From 7b8519f7686dab1ad67d2d4d8c43bb089c05a0a8 Mon Sep 17 00:00:00 2001 From: mukimovd <41473651-mukimovd@users.noreply.replit.com> Date: Thu, 1 May 2025 03:54:50 +0000 Subject: [PATCH] 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 --- server/storage.ts | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/server/storage.ts b/server/storage.ts index f52b7eb..df953af 100644 --- a/server/storage.ts +++ b/server/storage.ts @@ -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" }); - // Create sample blog post - const blogPost = this.createBlogPost({ + // Create sample blog post - work around async issues by creating the object directly + const blogPostId = this.blogPostId++; + const blogPost: BlogPost = { + id: blogPostId, title: "Exploring Russian Poetry in the Digital Age", slug: "exploring-russian-poetry-digital-age", content: ` @@ -308,16 +310,21 @@ As we continue to develop the Tercul platform, we're committed to addressing the `, authorId: user1.id, 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 - console.log('Adding tags to blog post', blogPost.id); - this.addTagToBlogPost(blogPost.id, poetryTag.id); - this.addTagToBlogPost(blogPost.id, romanticismTag.id); + console.log('Adding tags to blog post', blogPostId); + this.addTagToBlogPost(blogPostId, poetryTag.id); + this.addTagToBlogPost(blogPostId, romanticismTag.id); // 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({ content: "Fascinating exploration of how technology can preserve literary traditions!", userId: user1.id, @@ -325,7 +332,7 @@ As we continue to develop the Tercul platform, we're committed to addressing the translationId: null, lineNumber: null, entityType: "blogPost", - entityId: blogPost.id, + entityId: blogPostId, 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 { + 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(); - 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 { + console.log(`Adding tag ${tagId} to blog post ${postId}`); + if (!this.blogPostTagsRelations.has(postId)) { + console.log(`Creating new tag set for blog post ${postId}`); this.blogPostTagsRelations.set(postId, new Set()); } + 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