mirror of
https://github.com/usememos/memos.git
synced 2025-03-19 12:10:08 +01:00
feat: add search box in resources dashboard
This commit is contained in:
parent
3e138405b3
commit
d317b03832
@ -62,7 +62,8 @@
|
|||||||
"new": "New",
|
"new": "New",
|
||||||
"mark": "Mark",
|
"mark": "Mark",
|
||||||
"profile": "Profile",
|
"profile": "Profile",
|
||||||
"inbox": "Inbox"
|
"inbox": "Inbox",
|
||||||
|
"search": "Search"
|
||||||
},
|
},
|
||||||
"router": {
|
"router": {
|
||||||
"go-to-home": "Go to Home",
|
"go-to-home": "Go to Home",
|
||||||
|
@ -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 { useEffect, useState } from "react";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
import { showCommonDialog } from "@/components/Dialog/CommonDialog";
|
import { showCommonDialog } from "@/components/Dialog/CommonDialog";
|
||||||
@ -12,11 +13,6 @@ import i18n from "@/i18n";
|
|||||||
import { Resource } from "@/types/proto/api/v2/resource_service";
|
import { Resource } from "@/types/proto/api/v2/resource_service";
|
||||||
import { useTranslate } from "@/utils/i18n";
|
import { useTranslate } from "@/utils/i18n";
|
||||||
|
|
||||||
const fetchAllResources = async () => {
|
|
||||||
const { resources } = await resourceServiceClient.listResources({});
|
|
||||||
return resources;
|
|
||||||
};
|
|
||||||
|
|
||||||
function groupResourcesByDate(resources: Resource[]) {
|
function groupResourcesByDate(resources: Resource[]) {
|
||||||
const grouped = new Map<number, Resource[]>();
|
const grouped = new Map<number, Resource[]>();
|
||||||
resources.forEach((item) => {
|
resources.forEach((item) => {
|
||||||
@ -32,15 +28,23 @@ function groupResourcesByDate(resources: Resource[]) {
|
|||||||
return grouped;
|
return grouped;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface State {
|
||||||
|
searchQuery: string;
|
||||||
|
}
|
||||||
|
|
||||||
const Resources = () => {
|
const Resources = () => {
|
||||||
const t = useTranslate();
|
const t = useTranslate();
|
||||||
const loadingState = useLoading();
|
const loadingState = useLoading();
|
||||||
|
const [state, setState] = useState<State>({
|
||||||
|
searchQuery: "",
|
||||||
|
});
|
||||||
const [resources, setResources] = useState<Resource[]>([]);
|
const [resources, setResources] = useState<Resource[]>([]);
|
||||||
const groupedResources = groupResourcesByDate(resources.filter((resoure) => resoure.memoId));
|
const filteredResources = resources.filter((resource) => includes(resource.filename, state.searchQuery));
|
||||||
const unusedResources = resources.filter((resoure) => !resoure.memoId);
|
const groupedResources = groupResourcesByDate(filteredResources.filter((resoure) => resoure.memoId));
|
||||||
|
const unusedResources = filteredResources.filter((resoure) => !resoure.memoId);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchAllResources().then((resources) => {
|
resourceServiceClient.listResources({}).then(({ resources }) => {
|
||||||
setResources(resources);
|
setResources(resources);
|
||||||
loadingState.setFinish();
|
loadingState.setFinish();
|
||||||
});
|
});
|
||||||
@ -69,6 +73,16 @@ const Resources = () => {
|
|||||||
<p className="px-2 py-1 flex flex-row justify-start items-center select-none opacity-80">
|
<p className="px-2 py-1 flex flex-row justify-start items-center select-none opacity-80">
|
||||||
<Icon.Paperclip className="w-5 h-auto mr-1" /> {t("common.resources")}
|
<Icon.Paperclip className="w-5 h-auto mr-1" /> {t("common.resources")}
|
||||||
</p>
|
</p>
|
||||||
|
<div>
|
||||||
|
<Input
|
||||||
|
className="max-w-[8rem]"
|
||||||
|
variant="plain"
|
||||||
|
placeholder={t("common.search")}
|
||||||
|
startDecorator={<Icon.Search className="w-4 h-auto" />}
|
||||||
|
value={state.searchQuery}
|
||||||
|
onChange={(e) => setState({ ...state, searchQuery: e.target.value })}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="w-full flex flex-col justify-start items-start mt-4 mb-6">
|
<div className="w-full flex flex-col justify-start items-start mt-4 mb-6">
|
||||||
{loadingState.isLoading ? (
|
{loadingState.isLoading ? (
|
||||||
@ -77,7 +91,7 @@ const Resources = () => {
|
|||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
{resources.length === 0 ? (
|
{filteredResources.length === 0 ? (
|
||||||
<div className="w-full mt-8 mb-8 flex flex-col justify-center items-center italic">
|
<div className="w-full mt-8 mb-8 flex flex-col justify-center items-center italic">
|
||||||
<Empty />
|
<Empty />
|
||||||
<p className="mt-4 text-gray-600 dark:text-gray-400">{t("message.no-data")}</p>
|
<p className="mt-4 text-gray-600 dark:text-gray-400">{t("message.no-data")}</p>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user