import { useCallback } from "react"; import { observer } from "mobx-react"; import { useRouter } from "next/router"; // icons import { ChevronDown } from "lucide-react"; // types import { IIssueDisplayFilterOptions, IIssueDisplayProperties, IIssueFilterOptions, TIssueLayouts } from "@plane/types"; // ui import { CustomMenu } from "@plane/ui"; // components import { DisplayFiltersSelection, FilterSelection, FiltersDropdown } from "@/components/issues"; // constants import { EIssueFilterType, EIssuesStoreType, ISSUE_DISPLAY_FILTERS_BY_LAYOUT, ISSUE_LAYOUTS } from "@/constants/issue"; // helpers import { calculateTotalFilters } from "@/helpers/filter.helper"; // hooks import { useIssues, useLabel } from "@/hooks/store"; const ProfileIssuesMobileHeader = observer(() => { // router const router = useRouter(); const { workspaceSlug, userId } = router.query; // store hook const { issuesFilter: { issueFilters, updateFilters }, } = useIssues(EIssuesStoreType.PROFILE); const { workspaceLabels } = useLabel(); // derived values const states = undefined; // const members = undefined; // const activeLayout = issueFilters?.displayFilters?.layout; // const states = undefined; const members = undefined; const activeLayout = issueFilters?.displayFilters?.layout; const handleLayoutChange = useCallback( (layout: TIssueLayouts) => { if (!workspaceSlug || !userId) return; updateFilters( workspaceSlug.toString(), undefined, EIssueFilterType.DISPLAY_FILTERS, { layout: layout }, userId.toString() ); }, [workspaceSlug, updateFilters, userId] ); const handleFiltersUpdate = useCallback( (key: keyof IIssueFilterOptions, value: string | string[]) => { if (!workspaceSlug || !userId) return; const newValues = issueFilters?.filters?.[key] ?? []; if (Array.isArray(value)) { value.forEach((val) => { if (!newValues.includes(val)) newValues.push(val); }); } else { if (issueFilters?.filters?.[key]?.includes(value)) newValues.splice(newValues.indexOf(value), 1); else newValues.push(value); } updateFilters( workspaceSlug.toString(), undefined, EIssueFilterType.FILTERS, { [key]: newValues }, userId.toString() ); }, [workspaceSlug, issueFilters, updateFilters, userId] ); const handleDisplayFilters = useCallback( (updatedDisplayFilter: Partial) => { if (!workspaceSlug || !userId) return; updateFilters( workspaceSlug.toString(), undefined, EIssueFilterType.DISPLAY_FILTERS, updatedDisplayFilter, userId.toString() ); }, [workspaceSlug, updateFilters, userId] ); const handleDisplayProperties = useCallback( (property: Partial) => { if (!workspaceSlug || !userId) return; updateFilters( workspaceSlug.toString(), undefined, EIssueFilterType.DISPLAY_PROPERTIES, property, userId.toString() ); }, [workspaceSlug, updateFilters, userId] ); const isFiltersApplied = calculateTotalFilters(issueFilters?.filters ?? {}) !== 0; return (
Layout} customButtonClassName="flex flex-grow justify-center text-custom-text-200 text-sm" closeOnSelect > {ISSUE_LAYOUTS.map((layout, index) => { if (layout.key === "spreadsheet" || layout.key === "gantt_chart" || layout.key === "calendar") return; return ( { handleLayoutChange(ISSUE_LAYOUTS[index].key); }} className="flex items-center gap-2" >
{layout.title}
); })}
Filters } isFiltersApplied={isFiltersApplied} >
Display } >
); }); export default ProfileIssuesMobileHeader;