mirror of https://github.com/usememos/memos.git
fix(web): refresh sidebar tags when creating/updating memos
The sidebar tag list wasn't updating when users created new memos with tags or modified existing memo tags. This was because useFilteredMemoStats hook only refetched when filter/state/orderBy changed. Now the hook observes memoStore.state.stateId, which changes whenever memos are created, updated, or deleted. This triggers automatic refetch and the sidebar updates immediately with the latest tag counts. Fixes tag refresh issue in sidebar
This commit is contained in:
parent
cabd0d61c6
commit
edfbd6b073
|
|
@ -2,6 +2,7 @@ import dayjs from "dayjs";
|
|||
import { countBy } from "lodash-es";
|
||||
import { useEffect, useState } from "react";
|
||||
import { memoServiceClient } from "@/grpcweb";
|
||||
import { memoStore } from "@/store";
|
||||
import { State } from "@/types/proto/api/v1/common";
|
||||
import type { StatisticsData } from "@/types/statistics";
|
||||
|
||||
|
|
@ -51,6 +52,8 @@ export const useFilteredMemoStats = (filter?: string, state: State = State.NORMA
|
|||
tags: {},
|
||||
loading: true,
|
||||
});
|
||||
// React to memo store changes (create, update, delete)
|
||||
const memoStoreStateId = memoStore.state.stateId;
|
||||
|
||||
useEffect(() => {
|
||||
const fetchMemosAndComputeStats = async () => {
|
||||
|
|
@ -107,7 +110,7 @@ export const useFilteredMemoStats = (filter?: string, state: State = State.NORMA
|
|||
};
|
||||
|
||||
fetchMemosAndComputeStats();
|
||||
}, [filter, state, orderBy]);
|
||||
}, [filter, state, orderBy, memoStoreStateId]);
|
||||
|
||||
return data;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue