Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

feat: dynamic fetch user stats

Johnnyb897b243e501
diff --git a/server/router/api/v1/acl_config.go b/server/router/api/v1/acl_config.go
index 6c3b06306..8f32ebb37 100644
--- a/server/router/api/v1/acl_config.go
+++ b/server/router/api/v1/acl_config.go
@@ -14,6 +14,7 @@ var authenticationAllowlistMethods = map[string]bool{
"/memos.api.v1.UserService/GetUser": true,
"/memos.api.v1.UserService/GetUserByUsername": true,
"/memos.api.v1.UserService/GetUserAvatarBinary": true,
+ "/memos.api.v1.UserService/GetUserStats": true,
"/memos.api.v1.UserService/ListAllUserStats": true,
"/memos.api.v1.UserService/SearchUsers": true,
"/memos.api.v1.MemoService/GetMemo": true,
diff --git a/web/src/components/HomeSidebar/HomeSidebar.tsx b/web/src/components/HomeSidebar/HomeSidebar.tsx
index 6de6127ba..cc224fb7d 100644
--- a/web/src/components/HomeSidebar/HomeSidebar.tsx
+++ b/web/src/components/HomeSidebar/HomeSidebar.tsx
@@ -1,10 +1,12 @@
+import { last } from "lodash-es";
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 SearchBar from "@/components/SearchBar";
import useCurrentUser from "@/hooks/useCurrentUser";
import { Routes } from "@/router";
import { useMemoList, useUserStatsStore } from "@/store/v1";
+import { userStore } from "@/store/v2";
import { cn } from "@/utils";
import { useTranslate } from "@/utils/i18n";
import MemoFilters from "../MemoFilters";
@@ -25,6 +27,7 @@ interface Props {
const HomeSidebar = (props: Props) => {
const t = useTranslate();
+ const location = useLocation();
const currentUser = useCurrentUser();
const memoList = useMemoList();
const userStatsStore = useUserStatsStore();
@@ -46,10 +49,19 @@ const HomeSidebar = (props: Props) => {
useDebounce(
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,
- [memoList.size(), userStatsStore.stateId, currentUser],
+ [memoList.size(), userStatsStore.stateId, currentUser, location.pathname],
);
return (
diff --git a/web/src/components/Navigation.tsx b/web/src/components/Navigation.tsx
index 07b7d31b7..ee1ed2c72 100644
--- a/web/src/components/Navigation.tsx
+++ b/web/src/components/Navigation.tsx
@@ -85,7 +85,7 @@ const Navigation = observer((props: Props) => {
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} />
{navLinks.map((navLink) => (
<NavLink