import { createSignal, createEffect, For, Show } from "solid-js"; import type { CommentSortingProps } from "~/types/comment"; import CommentBlock from "./CommentBlock"; export default function CommentSorting(props: CommentSortingProps) { const [clickedOnce, setClickedOnce] = createSignal(false); const [showingBlock, setShowingBlock] = createSignal>( new Map(props.topLevelComments?.map((comment) => [comment.id, true])) ); // Update showing block when top level comments change createEffect(() => { setShowingBlock( new Map(props.topLevelComments?.map((comment) => [comment.id, true])) ); }); // Reset clickedOnce after timeout createEffect(() => { if (clickedOnce()) { setTimeout(() => setClickedOnce(false), 300); } }); const checkForDoubleClick = (id: number) => { if (clickedOnce()) { setShowingBlock((prev) => { const newMap = new Map(prev); newMap.set(id, !prev.get(id)); return newMap; }); } else { setClickedOnce(true); } }; // Comments are already sorted from server, no need for client-side sorting return ( {(topLevelComment) => (
checkForDoubleClick(topLevelComment.id)} class="bg-mantle mt-4 max-w-full rounded-lg py-2 pl-2 shadow-xl select-none sm:pl-4 md:pl-8 lg:pl-12" > } > comment.parent_comment_id === topLevelComment.id )} privilegeLevel={props.privilegeLevel} currentUserID={props.currentUserID} reactionMap={props.reactionMap} level={0} socket={props.socket} userCommentMap={props.userCommentMap} toggleModification={props.toggleModification} newComment={props.newComment} commentSubmitLoading={props.commentSubmitLoading} commentReaction={props.commentReaction} />
)}
); }