mirror of
https://github.com/SamyRai/tercul-frontend.git
synced 2025-12-27 02:31:34 +00:00
Enable discussions on various content types and enhance user engagement
Refactors comment storage to support generic entities using entityType and entityId fields in storage.ts and schema.ts. 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/079d6656-1153-4bbe-8f09-2e865c68b583.jpg
This commit is contained in:
parent
bfbc4c336e
commit
3cb048ea9e
@ -319,8 +319,9 @@ As we continue to develop the Tercul platform, we're committed to addressing the
|
||||
this.createComment({
|
||||
content: "Fascinating exploration of how technology can preserve literary traditions!",
|
||||
userId: user1.id,
|
||||
workId: 0, // Placeholder for blog posts
|
||||
parentId: blogPost.id
|
||||
entityType: "blogPost",
|
||||
entityId: blogPost.id,
|
||||
parentId: null
|
||||
});
|
||||
}
|
||||
|
||||
@ -537,28 +538,19 @@ As we continue to develop the Tercul platform, we're committed to addressing the
|
||||
}
|
||||
|
||||
async getCommentsByEntityId(entityType: string, entityId: number): Promise<Comment[]> {
|
||||
// In our storage model, we have specific fields for workId and translationId,
|
||||
// but we want to support a more generic entity approach for blog posts, etc.
|
||||
// For now, we'll handle the mapping between entity types and specific fields
|
||||
|
||||
// If we're using the primary entity fields (workId or translationId)
|
||||
if (entityType === 'work') {
|
||||
return this.getCommentsByWorkId(entityId);
|
||||
} else if (entityType === 'translation') {
|
||||
return this.getCommentsByTranslationId(entityId);
|
||||
} else if (entityType === 'blogPost') {
|
||||
// For blog posts, filter comments by their entityType and entityId properties
|
||||
// This assumes we're storing comment entities with these properties
|
||||
} else {
|
||||
// For all other entity types, use the generic entityType and entityId fields
|
||||
return Array.from(this.comments.values()).filter(
|
||||
comment =>
|
||||
// For blog posts, we're storing the references in the parentId field temporarily
|
||||
// In a real implementation, we would add proper schema fields for this
|
||||
comment.workId === 0 && // Use a placeholder workId
|
||||
comment.parentId === entityId
|
||||
comment.entityType === entityType &&
|
||||
comment.entityId === entityId
|
||||
);
|
||||
}
|
||||
|
||||
// Default return empty array if entity type is not recognized
|
||||
return [];
|
||||
}
|
||||
|
||||
async createComment(insertComment: InsertComment): Promise<Comment> {
|
||||
|
||||
@ -91,11 +91,14 @@ export const bookmarks = pgTable("bookmarks", {
|
||||
export const comments = pgTable("comments", {
|
||||
id: serial("id").primaryKey(),
|
||||
userId: integer("user_id").references(() => users.id).notNull(),
|
||||
workId: integer("work_id").references(() => works.id).notNull(),
|
||||
workId: integer("work_id").references(() => works.id), // Optional for non-work comments
|
||||
translationId: integer("translation_id").references(() => translations.id),
|
||||
lineNumber: integer("line_number"),
|
||||
content: text("content").notNull(),
|
||||
parentId: integer("parent_id").references(() => comments.id),
|
||||
// Adding support for blog posts and other content types
|
||||
entityType: text("entity_type"), // 'work', 'translation', 'blogPost', etc.
|
||||
entityId: integer("entity_id"), // ID of the entity
|
||||
createdAt: timestamp("created_at").defaultNow().notNull(),
|
||||
});
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user