Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add search bar in archived and explore pages #2025

Merged
merged 2 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions web/src/pages/Archived.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { useEffect, useState } from "react";
import { useTranslate } from "@/utils/i18n";
import toast from "react-hot-toast";
import { useMemoStore } from "@/store/module";
import { useFilterStore, useMemoStore } from "@/store/module";
import useLoading from "@/hooks/useLoading";
import ArchivedMemo from "@/components/ArchivedMemo";
import MobileHeader from "@/components/MobileHeader";
import Empty from "@/components/Empty";
import SearchBar from "@/components/SearchBar";
import MemoFilter from "@/components/MemoFilter";
import "@/less/archived.less";

const Archived = () => {
Expand All @@ -14,12 +16,16 @@ const Archived = () => {
const loadingState = useLoading();
const [archivedMemos, setArchivedMemos] = useState<Memo[]>([]);
const memos = memoStore.state.memos;
const filterStore = useFilterStore();
const filter = filterStore.state;
const { text: textQuery } = filter;

useEffect(() => {
memoStore
.fetchArchivedMemos()
.then((result) => {
setArchivedMemos(result);
const filteredMemos = textQuery ? result.filter((memo) => memo.content.toLowerCase().includes(textQuery.toLowerCase())) : result;
setArchivedMemos(filteredMemos);
})
.catch((error) => {
console.error(error);
Expand All @@ -28,12 +34,16 @@ const Archived = () => {
.finally(() => {
loadingState.setFinish();
});
}, [memos]);
}, [memos, textQuery]);

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">
<MobileHeader showSearch={false} />
<div className="archived-memo-page">
<div className="mb-4 mt-2 w-full">
<SearchBar />
</div>
<MemoFilter />
{loadingState.isLoading ? (
<div className="tip-text-container">
<p className="tip-text">{t("memo.fetching-data")}</p>
Expand Down
9 changes: 9 additions & 0 deletions web/src/pages/Explore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import MemoFilter from "@/components/MemoFilter";
import Memo from "@/components/Memo";
import MobileHeader from "@/components/MobileHeader";
import Empty from "@/components/Empty";
import SearchBar from "@/components/SearchBar";

const Explore = () => {
const t = useTranslate();
Expand Down Expand Up @@ -45,6 +46,11 @@ const Explore = () => {
shouldShow = false;
}
}

if (textQuery && !memo.content.toLowerCase().includes(textQuery.toLowerCase())) {
shouldShow = false;
}

return shouldShow;
})
: memos;
Expand Down Expand Up @@ -92,6 +98,9 @@ const Explore = () => {
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">
<MobileHeader showSearch={false} />
<div className="mb-4 mt-2 w-full">
<SearchBar />
</div>
{!loadingState.isLoading && (
<main className="relative w-full h-auto flex flex-col justify-start items-start">
<MemoFilter />
Expand Down