mirror of
https://github.com/usememos/memos.git
synced 2025-01-05 04:58:02 +03:00
feat: add search bar in archived and explore pages (#2025)
* feat: add search bar in archived and explore pages * Update web/src/pages/Archived.tsx --------- Co-authored-by: boojack <stevenlgtm@gmail.com>
This commit is contained in:
parent
dc5f82ac9c
commit
9da0ca5cb3
@ -1,11 +1,13 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useTranslate } from "@/utils/i18n";
|
import { useTranslate } from "@/utils/i18n";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
import { useMemoStore } from "@/store/module";
|
import { useFilterStore, useMemoStore } from "@/store/module";
|
||||||
import useLoading from "@/hooks/useLoading";
|
import useLoading from "@/hooks/useLoading";
|
||||||
import ArchivedMemo from "@/components/ArchivedMemo";
|
import ArchivedMemo from "@/components/ArchivedMemo";
|
||||||
import MobileHeader from "@/components/MobileHeader";
|
import MobileHeader from "@/components/MobileHeader";
|
||||||
import Empty from "@/components/Empty";
|
import Empty from "@/components/Empty";
|
||||||
|
import SearchBar from "@/components/SearchBar";
|
||||||
|
import MemoFilter from "@/components/MemoFilter";
|
||||||
import "@/less/archived.less";
|
import "@/less/archived.less";
|
||||||
|
|
||||||
const Archived = () => {
|
const Archived = () => {
|
||||||
@ -14,12 +16,16 @@ const Archived = () => {
|
|||||||
const loadingState = useLoading();
|
const loadingState = useLoading();
|
||||||
const [archivedMemos, setArchivedMemos] = useState<Memo[]>([]);
|
const [archivedMemos, setArchivedMemos] = useState<Memo[]>([]);
|
||||||
const memos = memoStore.state.memos;
|
const memos = memoStore.state.memos;
|
||||||
|
const filterStore = useFilterStore();
|
||||||
|
const filter = filterStore.state;
|
||||||
|
const { text: textQuery } = filter;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
memoStore
|
memoStore
|
||||||
.fetchArchivedMemos()
|
.fetchArchivedMemos()
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
setArchivedMemos(result);
|
const filteredMemos = textQuery ? result.filter((memo) => memo.content.toLowerCase().includes(textQuery.toLowerCase())) : result;
|
||||||
|
setArchivedMemos(filteredMemos);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@ -28,12 +34,16 @@ const Archived = () => {
|
|||||||
.finally(() => {
|
.finally(() => {
|
||||||
loadingState.setFinish();
|
loadingState.setFinish();
|
||||||
});
|
});
|
||||||
}, [memos]);
|
}, [memos, textQuery]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className="w-full min-h-full flex flex-col md:flex-row justify-start items-start px-4 sm:px-2 sm:pt-4 pb-8 bg-zinc-100 dark:bg-zinc-800">
|
<section className="w-full min-h-full flex flex-col md:flex-row justify-start items-start px-4 sm:px-2 sm:pt-4 pb-8 bg-zinc-100 dark:bg-zinc-800">
|
||||||
<MobileHeader showSearch={false} />
|
<MobileHeader showSearch={false} />
|
||||||
<div className="archived-memo-page">
|
<div className="archived-memo-page">
|
||||||
|
<div className="mb-4 mt-2 w-full">
|
||||||
|
<SearchBar />
|
||||||
|
</div>
|
||||||
|
<MemoFilter />
|
||||||
{loadingState.isLoading ? (
|
{loadingState.isLoading ? (
|
||||||
<div className="tip-text-container">
|
<div className="tip-text-container">
|
||||||
<p className="tip-text">{t("memo.fetching-data")}</p>
|
<p className="tip-text">{t("memo.fetching-data")}</p>
|
||||||
|
@ -10,6 +10,7 @@ import MemoFilter from "@/components/MemoFilter";
|
|||||||
import Memo from "@/components/Memo";
|
import Memo from "@/components/Memo";
|
||||||
import MobileHeader from "@/components/MobileHeader";
|
import MobileHeader from "@/components/MobileHeader";
|
||||||
import Empty from "@/components/Empty";
|
import Empty from "@/components/Empty";
|
||||||
|
import SearchBar from "@/components/SearchBar";
|
||||||
|
|
||||||
const Explore = () => {
|
const Explore = () => {
|
||||||
const t = useTranslate();
|
const t = useTranslate();
|
||||||
@ -45,6 +46,11 @@ const Explore = () => {
|
|||||||
shouldShow = false;
|
shouldShow = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (textQuery && !memo.content.toLowerCase().includes(textQuery.toLowerCase())) {
|
||||||
|
shouldShow = false;
|
||||||
|
}
|
||||||
|
|
||||||
return shouldShow;
|
return shouldShow;
|
||||||
})
|
})
|
||||||
: memos;
|
: memos;
|
||||||
@ -92,6 +98,9 @@ const Explore = () => {
|
|||||||
return (
|
return (
|
||||||
<section className="w-full max-w-3xl min-h-full flex flex-col justify-start items-center px-4 sm:px-2 sm:pt-4 pb-8 bg-zinc-100 dark:bg-zinc-800">
|
<section className="w-full max-w-3xl min-h-full flex flex-col justify-start items-center px-4 sm:px-2 sm:pt-4 pb-8 bg-zinc-100 dark:bg-zinc-800">
|
||||||
<MobileHeader showSearch={false} />
|
<MobileHeader showSearch={false} />
|
||||||
|
<div className="mb-4 mt-2 w-full">
|
||||||
|
<SearchBar />
|
||||||
|
</div>
|
||||||
{!loadingState.isLoading && (
|
{!loadingState.isLoading && (
|
||||||
<main className="relative w-full h-auto flex flex-col justify-start items-start">
|
<main className="relative w-full h-auto flex flex-col justify-start items-start">
|
||||||
<MemoFilter />
|
<MemoFilter />
|
||||||
|
Loading…
Reference in New Issue
Block a user