import { Button, Tab, TabList, Tabs } from "@mui/joy"; import { useEffect, useState } from "react"; import { shortcutService } from "../services"; import { useAppSelector } from "../stores"; import useViewStore, { Filter } from "../stores/v1/view"; import useUserStore from "../stores/v1/user"; import useLoading from "../hooks/useLoading"; import Icon from "../components/Icon"; import ShortcutListView from "../components/ShortcutListView"; import CreateShortcutDialog from "../components/CreateShortcutDialog"; import FilterView from "../components/FilterView"; interface State { showCreateShortcutDialog: boolean; } const getFilteredShortcutList = (shortcutList: Shortcut[], filter: Filter, currentUser: User) => { const { tag, mineOnly, visibility } = filter; const filteredShortcutList = shortcutList.filter((shortcut) => { if (tag) { if (!shortcut.tags.includes(tag)) { return false; } } if (mineOnly) { if (shortcut.creatorId !== currentUser.id) { return false; } } if (visibility) { if (shortcut.visibility !== visibility) { return false; } } return true; }); return filteredShortcutList; }; const Home: React.FC = () => { const loadingState = useLoading(); const currentUser = useUserStore().getCurrentUser(); const viewStore = useViewStore(); const { shortcutList } = useAppSelector((state) => state.shortcut); const [state, setState] = useState({ showCreateShortcutDialog: false, }); const filter = viewStore.filter; const filteredShortcutList = getFilteredShortcutList(shortcutList, filter, currentUser); useEffect(() => { Promise.all([shortcutService.getMyAllShortcuts()]).finally(() => { loadingState.setFinish(); }); }, []); const setShowCreateShortcutDialog = (show: boolean) => { setState({ ...state, showCreateShortcutDialog: show, }); }; return ( <>
Shortcuts
viewStore.setFilter({ mineOnly: value !== "ALL" })} > All Mine
{loadingState.isLoading ? (
loading
) : filteredShortcutList.length === 0 ? (

No shortcuts found.

) : ( )}
{state.showCreateShortcutDialog && ( setShowCreateShortcutDialog(false)} onConfirm={() => setShowCreateShortcutDialog(false)} /> )} ); }; export default Home;