mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
chore: use filter in url params
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
import { Button } from "@mui/joy";
|
import { Button } from "@mui/joy";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
import { useLocation } from "react-router-dom";
|
||||||
import Empty from "@/components/Empty";
|
import Empty from "@/components/Empty";
|
||||||
import Icon from "@/components/Icon";
|
import Icon from "@/components/Icon";
|
||||||
import MemoFilter from "@/components/MemoFilter";
|
import MemoFilter from "@/components/MemoFilter";
|
||||||
@ -14,6 +15,7 @@ import { useTranslate } from "@/utils/i18n";
|
|||||||
|
|
||||||
const Explore = () => {
|
const Explore = () => {
|
||||||
const t = useTranslate();
|
const t = useTranslate();
|
||||||
|
const location = useLocation();
|
||||||
const user = useCurrentUser();
|
const user = useCurrentUser();
|
||||||
const filterStore = useFilterStore();
|
const filterStore = useFilterStore();
|
||||||
const memoStore = useMemoStore();
|
const memoStore = useMemoStore();
|
||||||
@ -24,6 +26,32 @@ const Explore = () => {
|
|||||||
const sortedMemos = memoList.value.sort((a, b) => getTimeStampByDate(b.displayTime) - getTimeStampByDate(a.displayTime));
|
const sortedMemos = memoList.value.sort((a, b) => getTimeStampByDate(b.displayTime) - getTimeStampByDate(a.displayTime));
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const urlParams = new URLSearchParams(location.search);
|
||||||
|
const tag = urlParams.get("tag");
|
||||||
|
const text = urlParams.get("text");
|
||||||
|
if (tag) {
|
||||||
|
filterStore.setTagFilter(tag);
|
||||||
|
}
|
||||||
|
if (text) {
|
||||||
|
filterStore.setTextFilter(text);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const urlParams = new URLSearchParams(location.search);
|
||||||
|
if (tagQuery) {
|
||||||
|
urlParams.set("tag", tagQuery);
|
||||||
|
} else {
|
||||||
|
urlParams.delete("tag");
|
||||||
|
}
|
||||||
|
if (textQuery) {
|
||||||
|
urlParams.set("text", textQuery);
|
||||||
|
} else {
|
||||||
|
urlParams.delete("text");
|
||||||
|
}
|
||||||
|
const params = urlParams.toString();
|
||||||
|
window.history.replaceState({}, "", `${location.pathname}${params?.length > 0 ? `?${params}` : ""}`);
|
||||||
|
|
||||||
memoList.reset();
|
memoList.reset();
|
||||||
fetchMemos();
|
fetchMemos();
|
||||||
}, [tagQuery, textQuery]);
|
}, [tagQuery, textQuery]);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { Button } from "@mui/joy";
|
import { Button } from "@mui/joy";
|
||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
import { useLocation } from "react-router-dom";
|
||||||
import Empty from "@/components/Empty";
|
import Empty from "@/components/Empty";
|
||||||
import HomeSidebar from "@/components/HomeSidebar";
|
import HomeSidebar from "@/components/HomeSidebar";
|
||||||
import HomeSidebarDrawer from "@/components/HomeSidebarDrawer";
|
import HomeSidebarDrawer from "@/components/HomeSidebarDrawer";
|
||||||
@ -20,6 +21,7 @@ import { useTranslate } from "@/utils/i18n";
|
|||||||
|
|
||||||
const Home = () => {
|
const Home = () => {
|
||||||
const t = useTranslate();
|
const t = useTranslate();
|
||||||
|
const location = useLocation();
|
||||||
const { md } = useResponsiveWidth();
|
const { md } = useResponsiveWidth();
|
||||||
const user = useCurrentUser();
|
const user = useCurrentUser();
|
||||||
const filterStore = useFilterStore();
|
const filterStore = useFilterStore();
|
||||||
@ -34,6 +36,32 @@ const Home = () => {
|
|||||||
.sort((a, b) => Number(b.pinned) - Number(a.pinned));
|
.sort((a, b) => Number(b.pinned) - Number(a.pinned));
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const urlParams = new URLSearchParams(location.search);
|
||||||
|
const tag = urlParams.get("tag");
|
||||||
|
const text = urlParams.get("text");
|
||||||
|
if (tag) {
|
||||||
|
filterStore.setTagFilter(tag);
|
||||||
|
}
|
||||||
|
if (text) {
|
||||||
|
filterStore.setTextFilter(text);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const urlParams = new URLSearchParams(location.search);
|
||||||
|
if (tagQuery) {
|
||||||
|
urlParams.set("tag", tagQuery);
|
||||||
|
} else {
|
||||||
|
urlParams.delete("tag");
|
||||||
|
}
|
||||||
|
if (textQuery) {
|
||||||
|
urlParams.set("text", textQuery);
|
||||||
|
} else {
|
||||||
|
urlParams.delete("text");
|
||||||
|
}
|
||||||
|
const params = urlParams.toString();
|
||||||
|
window.history.replaceState({}, "", `${location.pathname}${params?.length > 0 ? `?${params}` : ""}`);
|
||||||
|
|
||||||
memoList.reset();
|
memoList.reset();
|
||||||
fetchMemos();
|
fetchMemos();
|
||||||
}, [tagQuery, textQuery]);
|
}, [tagQuery, textQuery]);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { Button } from "@mui/joy";
|
import { Button } from "@mui/joy";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { toast } from "react-hot-toast";
|
import { toast } from "react-hot-toast";
|
||||||
import { useParams } from "react-router-dom";
|
import { useLocation, useParams } from "react-router-dom";
|
||||||
import Empty from "@/components/Empty";
|
import Empty from "@/components/Empty";
|
||||||
import Icon from "@/components/Icon";
|
import Icon from "@/components/Icon";
|
||||||
import MemoFilter from "@/components/MemoFilter";
|
import MemoFilter from "@/components/MemoFilter";
|
||||||
@ -18,6 +18,7 @@ import { useTranslate } from "@/utils/i18n";
|
|||||||
|
|
||||||
const UserProfile = () => {
|
const UserProfile = () => {
|
||||||
const t = useTranslate();
|
const t = useTranslate();
|
||||||
|
const location = useLocation();
|
||||||
const params = useParams();
|
const params = useParams();
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
const loadingState = useLoading();
|
const loadingState = useLoading();
|
||||||
@ -32,6 +33,18 @@ const UserProfile = () => {
|
|||||||
.sort((a, b) => getTimeStampByDate(b.displayTime) - getTimeStampByDate(a.displayTime))
|
.sort((a, b) => getTimeStampByDate(b.displayTime) - getTimeStampByDate(a.displayTime))
|
||||||
.sort((a, b) => Number(b.pinned) - Number(a.pinned));
|
.sort((a, b) => Number(b.pinned) - Number(a.pinned));
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const urlParams = new URLSearchParams(location.search);
|
||||||
|
const tag = urlParams.get("tag");
|
||||||
|
const text = urlParams.get("text");
|
||||||
|
if (tag) {
|
||||||
|
filterStore.setTagFilter(tag);
|
||||||
|
}
|
||||||
|
if (text) {
|
||||||
|
filterStore.setTextFilter(text);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const username = params.username;
|
const username = params.username;
|
||||||
if (!username) {
|
if (!username) {
|
||||||
@ -55,6 +68,20 @@ const UserProfile = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const urlParams = new URLSearchParams(location.search);
|
||||||
|
if (tagQuery) {
|
||||||
|
urlParams.set("tag", tagQuery);
|
||||||
|
} else {
|
||||||
|
urlParams.delete("tag");
|
||||||
|
}
|
||||||
|
if (textQuery) {
|
||||||
|
urlParams.set("text", textQuery);
|
||||||
|
} else {
|
||||||
|
urlParams.delete("text");
|
||||||
|
}
|
||||||
|
const params = urlParams.toString();
|
||||||
|
window.history.replaceState({}, "", `${location.pathname}${params?.length > 0 ? `?${params}` : ""}`);
|
||||||
|
|
||||||
memoList.reset();
|
memoList.reset();
|
||||||
fetchMemos();
|
fetchMemos();
|
||||||
}, [user, tagQuery, textQuery]);
|
}, [user, tagQuery, textQuery]);
|
||||||
|
Reference in New Issue
Block a user