import { createSignal, Show } from "solid-js"; import { useSearchParams } from "@solidjs/router"; import type { Comment, CommentReaction, UserPublicData, ReactionType, ModificationType, PrivilegeLevel, SortingMode } from "~/types/comment"; import CommentInputBlock from "./CommentInputBlock"; import CommentSortingSelect from "./CommentSortingSelect"; import CommentSorting from "./CommentSorting"; const COMMENT_SORTING_OPTIONS: { val: SortingMode }[] = [ { val: "newest" }, { val: "oldest" }, { val: "highest_rated" }, { val: "hot" } ]; interface CommentSectionProps { privilegeLevel: PrivilegeLevel; allComments: Comment[]; topLevelComments: Comment[]; postID: number; reactionMap: Map; currentUserID: string; userCommentMap: Map | undefined; newComment: (commentBody: string, parentCommentID?: number) => Promise; 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 default function CommentSection(props: CommentSectionProps) { const [searchParams] = useSearchParams(); const [selectedSorting, setSelectedSorting] = createSignal( (searchParams.sortBy as SortingMode) || COMMENT_SORTING_OPTIONS[0].val ); const hasComments = () => props.allComments && props.allComments.length > 0 && props.topLevelComments && props.topLevelComments.length > 0; return (
Comments
No Comments Yet
} >
{}} toggleModification={props.toggleModification} commentSubmitLoading={props.commentSubmitLoading} selectedSorting={{ val: selectedSorting() }} commentReaction={props.commentReaction} />
); }