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])) ); createEffect(() => { setShowingBlock( new Map(props.topLevelComments?.map((comment) => [comment.id, true])) ); }); 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); } }; 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 )} isAuthenticated={props.isAuthenticated} isAdmin={props.isAdmin} 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} />
)}
); }