mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
feat: dynamic fetch user stats
This commit is contained in:
@@ -14,6 +14,7 @@ var authenticationAllowlistMethods = map[string]bool{
|
|||||||
"/memos.api.v1.UserService/GetUser": true,
|
"/memos.api.v1.UserService/GetUser": true,
|
||||||
"/memos.api.v1.UserService/GetUserByUsername": true,
|
"/memos.api.v1.UserService/GetUserByUsername": true,
|
||||||
"/memos.api.v1.UserService/GetUserAvatarBinary": true,
|
"/memos.api.v1.UserService/GetUserAvatarBinary": true,
|
||||||
|
"/memos.api.v1.UserService/GetUserStats": true,
|
||||||
"/memos.api.v1.UserService/ListAllUserStats": true,
|
"/memos.api.v1.UserService/ListAllUserStats": true,
|
||||||
"/memos.api.v1.UserService/SearchUsers": true,
|
"/memos.api.v1.UserService/SearchUsers": true,
|
||||||
"/memos.api.v1.MemoService/GetMemo": true,
|
"/memos.api.v1.MemoService/GetMemo": true,
|
||||||
|
@@ -1,10 +1,12 @@
|
|||||||
|
import { last } from "lodash-es";
|
||||||
import { Globe2Icon, HomeIcon } from "lucide-react";
|
import { Globe2Icon, HomeIcon } from "lucide-react";
|
||||||
import { NavLink } from "react-router-dom";
|
import { matchPath, NavLink, useLocation } from "react-router-dom";
|
||||||
import useDebounce from "react-use/lib/useDebounce";
|
import useDebounce from "react-use/lib/useDebounce";
|
||||||
import SearchBar from "@/components/SearchBar";
|
import SearchBar from "@/components/SearchBar";
|
||||||
import useCurrentUser from "@/hooks/useCurrentUser";
|
import useCurrentUser from "@/hooks/useCurrentUser";
|
||||||
import { Routes } from "@/router";
|
import { Routes } from "@/router";
|
||||||
import { useMemoList, useUserStatsStore } from "@/store/v1";
|
import { useMemoList, useUserStatsStore } from "@/store/v1";
|
||||||
|
import { userStore } from "@/store/v2";
|
||||||
import { cn } from "@/utils";
|
import { cn } from "@/utils";
|
||||||
import { useTranslate } from "@/utils/i18n";
|
import { useTranslate } from "@/utils/i18n";
|
||||||
import MemoFilters from "../MemoFilters";
|
import MemoFilters from "../MemoFilters";
|
||||||
@@ -25,6 +27,7 @@ interface Props {
|
|||||||
|
|
||||||
const HomeSidebar = (props: Props) => {
|
const HomeSidebar = (props: Props) => {
|
||||||
const t = useTranslate();
|
const t = useTranslate();
|
||||||
|
const location = useLocation();
|
||||||
const currentUser = useCurrentUser();
|
const currentUser = useCurrentUser();
|
||||||
const memoList = useMemoList();
|
const memoList = useMemoList();
|
||||||
const userStatsStore = useUserStatsStore();
|
const userStatsStore = useUserStatsStore();
|
||||||
@@ -46,10 +49,19 @@ const HomeSidebar = (props: Props) => {
|
|||||||
|
|
||||||
useDebounce(
|
useDebounce(
|
||||||
async () => {
|
async () => {
|
||||||
await userStatsStore.listUserStats(currentUser.name);
|
let parent: string | undefined = undefined;
|
||||||
|
if (location.pathname === Routes.ROOT && currentUser) {
|
||||||
|
parent = currentUser.name;
|
||||||
|
}
|
||||||
|
if (matchPath("/u/:username", location.pathname) !== null) {
|
||||||
|
const username = last(location.pathname.split("/"));
|
||||||
|
const user = await userStore.fetchUserByUsername(username || "");
|
||||||
|
parent = user.name;
|
||||||
|
}
|
||||||
|
await userStatsStore.listUserStats(parent);
|
||||||
},
|
},
|
||||||
300,
|
300,
|
||||||
[memoList.size(), userStatsStore.stateId, currentUser],
|
[memoList.size(), userStatsStore.stateId, currentUser, location.pathname],
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@@ -85,7 +85,7 @@ const Navigation = observer((props: Props) => {
|
|||||||
className,
|
className,
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<div className="w-full px-1 py-2 flex flex-col justify-start items-start space-y-2 overflow-auto hide-scrollbar shrink">
|
<div className="w-full px-1 py-1 flex flex-col justify-start items-start space-y-2 overflow-auto hide-scrollbar shrink">
|
||||||
<BrandBanner className="mb-2" collapsed={collapsed} />
|
<BrandBanner className="mb-2" collapsed={collapsed} />
|
||||||
{navLinks.map((navLink) => (
|
{navLinks.map((navLink) => (
|
||||||
<NavLink
|
<NavLink
|
||||||
|
Reference in New Issue
Block a user