chore: add last visited page

This commit is contained in:
Steven 2024-05-28 09:05:59 +08:00
parent 239f28c1e0
commit 0275a65781
6 changed files with 46 additions and 5 deletions

View file

@ -1,12 +1,16 @@
import clsx from "clsx";
import useCurrentUser from "@/hooks/useCurrentUser";
import TagsSection from "../HomeSidebar/TagsSection";
import SearchBar from "../SearchBar";
import UserStatisticsView from "../UserStatisticsView";
interface Props {
className?: string;
}
const TimelineSidebar = (props: Props) => {
const currentUser = useCurrentUser();
return (
<aside
className={clsx(
@ -15,6 +19,7 @@ const TimelineSidebar = (props: Props) => {
)}
>
<SearchBar />
<UserStatisticsView user={currentUser} />
<TagsSection />
</aside>
);

View file

@ -29,10 +29,6 @@ const UserStatisticsView = (props: Props) => {
const memos = Object.values(memoStore.getState().memoMapByName);
useEffect(() => {
if (memos.length === 0) {
return;
}
(async () => {
setIsRequesting(true);
const { properties } = await memoServiceClient.listMemoProperties({

View file

@ -1,6 +1,7 @@
import { Button } from "@mui/joy";
import clsx from "clsx";
import { useEffect, useState } from "react";
import { useLocalStorage } from "react-use";
import Empty from "@/components/Empty";
import { HomeSidebar, HomeSidebarDrawer } from "@/components/HomeSidebar";
import Icon from "@/components/Icon";
@ -13,6 +14,7 @@ import { getTimeStampByDate } from "@/helpers/datetime";
import useCurrentUser from "@/hooks/useCurrentUser";
import useFilterWithUrlParams from "@/hooks/useFilterWithUrlParams";
import useResponsiveWidth from "@/hooks/useResponsiveWidth";
import { Routes } from "@/router";
import { useMemoList, useMemoStore } from "@/store/v1";
import { RowStatus } from "@/types/proto/api/v1/common";
import { useTranslate } from "@/utils/i18n";
@ -23,6 +25,7 @@ const Home = () => {
const user = useCurrentUser();
const memoStore = useMemoStore();
const memoList = useMemoList();
const [, setLastVisited] = useLocalStorage<string>("lastVisited", Routes.HOME);
const [isRequesting, setIsRequesting] = useState(true);
const [nextPageToken, setNextPageToken] = useState<string>("");
const filter = useFilterWithUrlParams();
@ -31,6 +34,10 @@ const Home = () => {
.sort((a, b) => getTimeStampByDate(b.displayTime) - getTimeStampByDate(a.displayTime))
.sort((a, b) => Number(b.pinned) - Number(a.pinned));
useEffect(() => {
setLastVisited(Routes.HOME);
}, []);
useEffect(() => {
memoList.reset();
fetchMemos("");

View file

@ -0,0 +1,20 @@
import { useEffect } from "react";
import useLocalStorage from "react-use/lib/useLocalStorage";
import useNavigateTo from "@/hooks/useNavigateTo";
const RootRedirector: React.FC = () => {
const [lastVisited] = useLocalStorage<string>("lastVisited", "/home");
const navigateTo = useNavigateTo();
useEffect(() => {
if (lastVisited === "/home" || lastVisited === "/timeline") {
navigateTo(lastVisited);
} else {
navigateTo("/home");
}
}, []);
return <></>;
};
export default RootRedirector;

View file

@ -2,6 +2,7 @@ import { Button, IconButton } from "@mui/joy";
import clsx from "clsx";
import dayjs from "dayjs";
import { useEffect, useState } from "react";
import { useLocalStorage } from "react-use";
import ActivityCalendar from "@/components/ActivityCalendar";
import Empty from "@/components/Empty";
import Icon from "@/components/Icon";
@ -17,6 +18,7 @@ import useCurrentUser from "@/hooks/useCurrentUser";
import useFilterWithUrlParams from "@/hooks/useFilterWithUrlParams";
import useResponsiveWidth from "@/hooks/useResponsiveWidth";
import i18n from "@/i18n";
import { Routes } from "@/router";
import { useMemoList, useMemoStore } from "@/store/v1";
import { useTranslate } from "@/utils/i18n";
@ -26,6 +28,7 @@ const Timeline = () => {
const user = useCurrentUser();
const memoStore = useMemoStore();
const memoList = useMemoList();
const [, setLastVisited] = useLocalStorage<string>("lastVisited", Routes.TIMELINE);
const { tag: tagQuery, text: textQuery } = useFilterWithUrlParams();
const [activityStats, setActivityStats] = useState<Record<string, number>>({});
const [selectedDateString, setSelectedDateString] = useState<string>(new Date().toDateString());
@ -34,6 +37,10 @@ const Timeline = () => {
const sortedMemos = memoList.value.sort((a, b) => getTimeStampByDate(a.displayTime) - getTimeStampByDate(b.displayTime));
const monthString = dayjs(selectedDateString).format("YYYY-MM");
useEffect(() => {
setLastVisited(Routes.TIMELINE);
}, []);
useEffect(() => {
memoList.reset();
fetchMemos("");

View file

@ -12,6 +12,7 @@ import MemoDetail from "@/pages/MemoDetail";
import NotFound from "@/pages/NotFound";
import PermissionDenied from "@/pages/PermissionDenied";
import Resources from "@/pages/Resources";
import RootRedirector from "@/pages/RootRedirector";
import Setting from "@/pages/Setting";
import SignIn from "@/pages/SignIn";
import SignUp from "@/pages/SignUp";
@ -19,7 +20,8 @@ import Timeline from "@/pages/Timeline";
import UserProfile from "@/pages/UserProfile";
export enum Routes {
HOME = "/",
ROOT = "/",
HOME = "/home",
TIMELINE = "/timeline",
RESOURCES = "/resources",
INBOX = "/inbox",
@ -57,6 +59,10 @@ const router = createBrowserRouter([
path: "/",
element: <HomeLayout />,
children: [
{
path: Routes.ROOT,
element: <RootRedirector />,
},
{
path: Routes.HOME,
element: <Home />,