import { Button, Input } from "@mui/joy"; import { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import CollectionView from "@/components/CollectionView"; import CreateCollectionDrawer from "@/components/CreateCollectionDrawer"; import useCollectionStore from "@/stores/v1/collection"; import useShortcutStore from "@/stores/v1/shortcut"; import FilterView from "../components/FilterView"; import Icon from "../components/Icon"; import useLoading from "../hooks/useLoading"; interface State { showCreateCollectionDrawer: boolean; } const CollectionDashboard: React.FC = () => { const { t } = useTranslation(); const loadingState = useLoading(); const shortcutStore = useShortcutStore(); const collectionStore = useCollectionStore(); const [state, setState] = useState({ showCreateCollectionDrawer: false, }); const [search, setSearch] = useState(""); const filteredCollections = collectionStore.getCollectionList().filter((collection) => { return ( collection.name.toLowerCase().includes(search.toLowerCase()) || collection.title.toLowerCase().includes(search.toLowerCase()) || collection.description.toLowerCase().includes(search.toLowerCase()) ); }); useEffect(() => { Promise.all([shortcutStore.fetchShortcutList(), collectionStore.fetchCollectionList()]).finally(() => { loadingState.setFinish(); }); }, []); const setShowCreateCollectionDrawer = (show: boolean) => { setState({ ...state, showCreateCollectionDrawer: show, }); }; return ( <>
} value={search} onChange={(e) => setSearch(e.target.value)} />
{loadingState.isLoading ? (
{t("common.loading")}
) : filteredCollections.length === 0 ? (

No collections found.

) : (
{filteredCollections.map((collection) => { return ; })}
)}
{state.showCreateCollectionDrawer && ( setShowCreateCollectionDrawer(false)} onConfirm={() => setShowCreateCollectionDrawer(false)} /> )} ); }; export default CollectionDashboard;