From d7c7de24c1f9f30d480f508da9371e0b0abdf6bc Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 28 Jun 2023 22:39:18 +0800 Subject: [PATCH] feat: add shortcut filter --- web/src/pages/Home.tsx | 40 ++++++++++++++++------------------------ 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/web/src/pages/Home.tsx b/web/src/pages/Home.tsx index 3b0534b..fbe4004 100644 --- a/web/src/pages/Home.tsx +++ b/web/src/pages/Home.tsx @@ -1,10 +1,9 @@ -import { Button } from "@mui/joy"; +import { Button, Option, Select } from "@mui/joy"; import { useEffect, useState } from "react"; import { shortcutService } from "../services"; import { useAppSelector } from "../stores"; import useLoading from "../hooks/useLoading"; import Icon from "../components/Icon"; -import Dropdown from "../components/common/Dropdown"; import ShortcutListView from "../components/ShortcutListView"; import CreateShortcutDialog from "../components/CreateShortcutDialog"; @@ -15,9 +14,12 @@ interface State { const Home: React.FC = () => { const loadingState = useLoading(); const { shortcutList } = useAppSelector((state) => state.shortcut); + const user = useAppSelector((state) => state.user).user as User; const [state, setState] = useState({ showCreateShortcutDialog: false, }); + const [selectedFilter, setSelectFilter] = useState<"ALL" | "PRIVATE">("ALL"); + const filteredShortcutList = selectedFilter === "ALL" ? shortcutList : shortcutList.filter((shortcut) => shortcut.creatorId === user.id); useEffect(() => { Promise.all([shortcutService.getMyAllShortcuts()]).finally(() => { @@ -36,27 +38,17 @@ const Home: React.FC = () => { <>
- Shortcuts +
+ Shortcuts + +
- - Add new... - - } - actions={ - <> - - - } - actionsClassName="!w-32" - /> +
{loadingState.isLoading ? ( @@ -64,7 +56,7 @@ const Home: React.FC = () => { loading
- ) : shortcutList.length === 0 ? ( + ) : filteredShortcutList.length === 0 ? (

No shortcuts found.

@@ -73,7 +65,7 @@ const Home: React.FC = () => {
) : ( - + )}