Ensure blog posts and tags are correctly linked when the site initially loads

Refactors MemStorage to directly create BlogPost objects and explicitly manage tag relationships for proper initial data loading.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: cbacfb18-842a-4116-a907-18c0105ad8ec
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/39b5c689-6e8a-4d5a-9792-69cc81a56534/fd5143c4-e876-4e0a-b046-bf6a49323077.jpg
This commit is contained in:
mukimovd 2025-05-01 03:54:50 +00:00
parent 1e4ca9b72e
commit 7b8519f768

View File

@ -283,8 +283,10 @@ export class MemStorage implements IStorage {
description: "Died in St. Petersburg from wounds received in a duel with Georges d'Anthès" description: "Died in St. Petersburg from wounds received in a duel with Georges d'Anthès"
}); });
// Create sample blog post // Create sample blog post - work around async issues by creating the object directly
const blogPost = this.createBlogPost({ const blogPostId = this.blogPostId++;
const blogPost: BlogPost = {
id: blogPostId,
title: "Exploring Russian Poetry in the Digital Age", title: "Exploring Russian Poetry in the Digital Age",
slug: "exploring-russian-poetry-digital-age", slug: "exploring-russian-poetry-digital-age",
content: ` content: `
@ -308,16 +310,21 @@ As we continue to develop the Tercul platform, we're committed to addressing the
`, `,
authorId: user1.id, authorId: user1.id,
excerpt: "Exploring how digital platforms can help preserve and promote the rich tradition of Russian poetry in the modern age.", excerpt: "Exploring how digital platforms can help preserve and promote the rich tradition of Russian poetry in the modern age.",
publishedAt: new Date() publishedAt: new Date(),
}); createdAt: new Date()
};
// Add the blog post to storage manually to avoid async issues
this.blogPosts.set(blogPostId, blogPost);
console.log('Created blog post with ID:', blogPostId);
// Add tags to the blog post // Add tags to the blog post
console.log('Adding tags to blog post', blogPost.id); console.log('Adding tags to blog post', blogPostId);
this.addTagToBlogPost(blogPost.id, poetryTag.id); this.addTagToBlogPost(blogPostId, poetryTag.id);
this.addTagToBlogPost(blogPost.id, romanticismTag.id); this.addTagToBlogPost(blogPostId, romanticismTag.id);
// Add a comment to the blog post // Add a comment to the blog post
console.log('Creating comment for blog post', blogPost.id); console.log('Creating comment for blog post', blogPostId);
this.createComment({ this.createComment({
content: "Fascinating exploration of how technology can preserve literary traditions!", content: "Fascinating exploration of how technology can preserve literary traditions!",
userId: user1.id, userId: user1.id,
@ -325,7 +332,7 @@ As we continue to develop the Tercul platform, we're committed to addressing the
translationId: null, translationId: null,
lineNumber: null, lineNumber: null,
entityType: "blogPost", entityType: "blogPost",
entityId: blogPost.id, entityId: blogPostId,
parentId: null parentId: null
}); });
} }
@ -483,15 +490,29 @@ As we continue to develop the Tercul platform, we're committed to addressing the
} }
async getBlogPostTags(postId: number): Promise<Tag[]> { async getBlogPostTags(postId: number): Promise<Tag[]> {
console.log(`Getting tags for blog post ${postId}`);
console.log(`BlogPostTagsRelations map:`, Array.from(this.blogPostTagsRelations.entries()));
const tagIds = this.blogPostTagsRelations.get(postId) || new Set(); const tagIds = this.blogPostTagsRelations.get(postId) || new Set();
return Array.from(tagIds).map(id => this.tags.get(id)!).filter(Boolean); console.log(`Tag IDs for blog post ${postId}:`, Array.from(tagIds));
const tags = Array.from(tagIds).map(id => this.tags.get(id)!).filter(Boolean);
console.log(`Found ${tags.length} tags for blog post ${postId}:`, tags);
return tags;
} }
async addTagToBlogPost(postId: number, tagId: number): Promise<void> { async addTagToBlogPost(postId: number, tagId: number): Promise<void> {
console.log(`Adding tag ${tagId} to blog post ${postId}`);
if (!this.blogPostTagsRelations.has(postId)) { if (!this.blogPostTagsRelations.has(postId)) {
console.log(`Creating new tag set for blog post ${postId}`);
this.blogPostTagsRelations.set(postId, new Set()); this.blogPostTagsRelations.set(postId, new Set());
} }
this.blogPostTagsRelations.get(postId)!.add(tagId); this.blogPostTagsRelations.get(postId)!.add(tagId);
console.log(`After adding tag, blog post ${postId} has tags:`,
Array.from(this.blogPostTagsRelations.get(postId) || new Set()));
} }
// Bookmark methods // Bookmark methods