import { For, Show, createSignal } from "solid-js"; import { useNavigate, useLocation } from "@solidjs/router"; import type { CommentSortingSelectProps, SortingMode } from "~/types/comment"; import Check from "~/components/icons/Check"; import UpDownArrows from "~/components/icons/UpDownArrows"; const SORTING_OPTIONS: { val: SortingMode; label: string }[] = [ { val: "newest", label: "Newest" }, { val: "oldest", label: "Oldest" }, { val: "highest_rated", label: "Highest Rated" }, { val: "hot", label: "Hot" } ]; export default function CommentSortingSelect(props: CommentSortingSelectProps) { const [isOpen, setIsOpen] = createSignal(false); const navigate = useNavigate(); const location = useLocation(); const selectedLabel = () => { const option = SORTING_OPTIONS.find( (opt) => opt.val === props.selectedSorting.val ); return option?.label || "Newest"; }; const handleSelect = (mode: SortingMode) => { props.setSorting(mode); setIsOpen(false); const url = new URL(window.location.href); url.searchParams.set("sortBy", mode); navigate(`${location.pathname}?${url.searchParams.toString()}#comments`, { scroll: false, replace: true }); }; return (