migration of comments

This commit is contained in:
Michael Freno
2025-12-17 22:47:19 -05:00
parent a092c57d36
commit 1bc57c61eb
37 changed files with 3022 additions and 442 deletions

234
src/types/comment.ts Normal file
View File

@@ -0,0 +1,234 @@
/**
* Comment System Type Definitions
*
* Types for the blog comment system including:
* - Comment and CommentReaction models
* - WebSocket message types
* - User data structures
* - Component prop interfaces
*/
// ============================================================================
// Core Data Models
// ============================================================================
export interface Comment {
id: number;
body: string;
post_id: number;
parent_comment_id: number | null;
commenter_id: string;
edited: boolean;
date: string;
}
export interface CommentReaction {
id: number;
comment_id: number;
user_id: string;
type: ReactionType;
date: string;
}
export type ReactionType =
| "tears"
| "blank"
| "tongue"
| "cry"
| "heartEye"
| "angry"
| "moneyEye"
| "sick"
| "upsideDown"
| "worried";
export interface UserPublicData {
email?: string;
display_name?: string;
image?: string;
}
// ============================================================================
// WebSocket Message Types
// ============================================================================
export interface WebSocketBroadcast {
action:
| "commentCreationBroadcast"
| "commentUpdateBroadcast"
| "commentDeletionBroadcast"
| "commentReactionBroadcast";
commentID: number;
commentBody?: string;
commenterID: string;
commentParent?: number | null;
reactionType?: ReactionType;
deletionType?: "user" | "admin" | "database";
}
export interface BackupResponse {
commentID: number;
commentBody?: string;
commenterID: string;
commentParent?: number | null;
}
// ============================================================================
// Privilege and Sorting Types
// ============================================================================
export type PrivilegeLevel = "admin" | "user" | "anonymous";
export type PostType = "blog" | "project";
export type SortingMode = "newest" | "oldest" | "highest_rated" | "hot";
export type DeletionType = "user" | "admin" | "database";
export type ModificationType = "delete" | "edit";
// ============================================================================
// Component Props Interfaces
// ============================================================================
export interface CommentSectionWrapperProps {
privilegeLevel: PrivilegeLevel;
allComments: Comment[];
topLevelComments: Comment[];
id: number;
type: PostType;
reactionMap: Map<number, CommentReaction[]>;
currentUserID: string;
userCommentMap: Map<UserPublicData, number[]>;
}
export interface CommentSectionProps {
privilegeLevel: PrivilegeLevel;
type: PostType;
postID: number;
allComments: Comment[];
topLevelComments: Comment[];
reactionMap: Map<number, CommentReaction[]>;
currentUserID: string;
userCommentMap: Map<UserPublicData, number[]> | undefined;
newComment: (commentBody: string, parentCommentID?: number) => Promise<void>;
commentSubmitLoading: boolean;
toggleModification: (
commentID: number,
commenterID: string,
commentBody: string,
modificationType: ModificationType,
commenterImage?: string,
commenterEmail?: string,
commenterDisplayName?: string
) => void;
commentReaction: (reactionType: ReactionType, commentID: number) => void;
}
export interface CommentBlockProps {
comment: Comment;
category: PostType;
projectID: number;
recursionCount: number;
allComments: Comment[] | undefined;
child_comments: Comment[] | undefined;
privilegeLevel: PrivilegeLevel;
currentUserID: string;
reactionMap: Map<number, CommentReaction[]>;
level: number;
socket: WebSocket | undefined;
userCommentMap: Map<UserPublicData, number[]> | undefined;
newComment: (commentBody: string, parentCommentID?: number) => Promise<void>;
commentSubmitLoading: boolean;
toggleModification: (
commentID: number,
commenterID: string,
commentBody: string,
modificationType: ModificationType,
commenterImage?: string,
commenterEmail?: string,
commenterDisplayName?: string
) => void;
commentReaction: (reactionType: ReactionType, commentID: number) => void;
}
export interface CommentInputBlockProps {
isReply: boolean;
parent_id?: number;
privilegeLevel: PrivilegeLevel;
type: PostType;
post_id: number;
socket: WebSocket | undefined;
currentUserID: string;
newComment: (commentBody: string, parentCommentID?: number) => Promise<void>;
commentSubmitLoading: boolean;
}
export interface CommentSortingProps {
topLevelComments: Comment[];
privilegeLevel: PrivilegeLevel;
type: PostType;
postID: number;
allComments: Comment[];
reactionMap: Map<number, CommentReaction[]>;
currentUserID: string;
socket: WebSocket | undefined;
userCommentMap: Map<UserPublicData, number[]> | undefined;
newComment: (commentBody: string, parentCommentID?: number) => Promise<void>;
editComment: (body: string, comment_id: number) => Promise<void>;
toggleModification: (
commentID: number,
commenterID: string,
commentBody: string,
modificationType: ModificationType,
commenterImage?: string,
commenterEmail?: string,
commenterDisplayName?: string
) => void;
commentSubmitLoading: boolean;
selectedSorting: {
val: SortingMode;
};
commentReaction: (reactionType: ReactionType, commentID: number) => void;
}
export interface CommentSortingSelectProps {
selectedSorting: {
val: SortingMode;
};
setSorting: (mode: SortingMode) => void;
}
export interface ReactionBarProps {
currentUserID: string;
commentID: number;
reactions: CommentReaction[];
privilegeLevel: PrivilegeLevel;
showingReactionOptions: boolean;
commentReaction: (reactionType: ReactionType, commentID: number) => void;
}
export interface CommentDeletionPromptProps {
privilegeLevel: PrivilegeLevel;
commentID: number;
commenterID: string;
deleteComment: (
commentID: number,
commenterID: string,
deletionType: DeletionType
) => void;
commentDeletionLoading: boolean;
commenterImage?: string;
commenterEmail?: string;
commenterDisplayName?: string;
}
export interface EditCommentModalProps {
commentID: number;
commentBody: string;
editComment: (body: string, comment_id: number) => Promise<void>;
editCommentLoading: boolean;
commenterImage?: string;
commenterEmail?: string;
commenterDisplayName?: string;
}