diff --git a/web/src/locales/en.json b/web/src/locales/en.json index 3646e5bf..8d1c8d63 100644 --- a/web/src/locales/en.json +++ b/web/src/locales/en.json @@ -62,7 +62,8 @@ "new": "New", "mark": "Mark", "profile": "Profile", - "inbox": "Inbox" + "inbox": "Inbox", + "search": "Search" }, "router": { "go-to-home": "Go to Home", diff --git a/web/src/pages/Resources.tsx b/web/src/pages/Resources.tsx index 3cd00a1e..836daa3e 100644 --- a/web/src/pages/Resources.tsx +++ b/web/src/pages/Resources.tsx @@ -1,4 +1,5 @@ -import { Divider, IconButton, Tooltip } from "@mui/joy"; +import { Divider, IconButton, Input, Tooltip } from "@mui/joy"; +import { includes } from "lodash-es"; import { useEffect, useState } from "react"; import { Link } from "react-router-dom"; import { showCommonDialog } from "@/components/Dialog/CommonDialog"; @@ -12,11 +13,6 @@ import i18n from "@/i18n"; import { Resource } from "@/types/proto/api/v2/resource_service"; import { useTranslate } from "@/utils/i18n"; -const fetchAllResources = async () => { - const { resources } = await resourceServiceClient.listResources({}); - return resources; -}; - function groupResourcesByDate(resources: Resource[]) { const grouped = new Map(); resources.forEach((item) => { @@ -32,15 +28,23 @@ function groupResourcesByDate(resources: Resource[]) { return grouped; } +interface State { + searchQuery: string; +} + const Resources = () => { const t = useTranslate(); const loadingState = useLoading(); + const [state, setState] = useState({ + searchQuery: "", + }); const [resources, setResources] = useState([]); - const groupedResources = groupResourcesByDate(resources.filter((resoure) => resoure.memoId)); - const unusedResources = resources.filter((resoure) => !resoure.memoId); + const filteredResources = resources.filter((resource) => includes(resource.filename, state.searchQuery)); + const groupedResources = groupResourcesByDate(filteredResources.filter((resoure) => resoure.memoId)); + const unusedResources = filteredResources.filter((resoure) => !resoure.memoId); useEffect(() => { - fetchAllResources().then((resources) => { + resourceServiceClient.listResources({}).then(({ resources }) => { setResources(resources); loadingState.setFinish(); }); @@ -69,6 +73,16 @@ const Resources = () => {

{t("common.resources")}

+
+ } + value={state.searchQuery} + onChange={(e) => setState({ ...state, searchQuery: e.target.value })} + /> +
{loadingState.isLoading ? ( @@ -77,7 +91,7 @@ const Resources = () => {
) : ( <> - {resources.length === 0 ? ( + {filteredResources.length === 0 ? (

{t("message.no-data")}