fix: clean duplicated requests
This commit is contained in:
parent
1f7a90cec4
commit
7817947f66
5 changed files with 26 additions and 15 deletions
|
|
@ -29,7 +29,14 @@ const TagsSection = (props: Props) => {
|
||||||
.sort((a, b) => a[0].localeCompare(b[0]))
|
.sort((a, b) => a[0].localeCompare(b[0]))
|
||||||
.sort((a, b) => b[1] - a[1]);
|
.sort((a, b) => b[1] - a[1]);
|
||||||
|
|
||||||
useDebounce(() => fetchTags(), 300, [memoList.size(), location.pathname]);
|
useDebounce(
|
||||||
|
() => {
|
||||||
|
if (memoList.size() === 0) return;
|
||||||
|
fetchTags();
|
||||||
|
},
|
||||||
|
300,
|
||||||
|
[memoList.size(), location.pathname],
|
||||||
|
);
|
||||||
|
|
||||||
const fetchTags = async () => {
|
const fetchTags = async () => {
|
||||||
await tagStore.fetchTags({ user, location });
|
await tagStore.fetchTags({ user, location });
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,8 @@ const AddMemoRelationPopover = (props: Props) => {
|
||||||
|
|
||||||
useDebounce(
|
useDebounce(
|
||||||
async () => {
|
async () => {
|
||||||
|
if (!popoverOpen) return;
|
||||||
|
|
||||||
setIsFetching(true);
|
setIsFetching(true);
|
||||||
try {
|
try {
|
||||||
const filters = [`creator == "${user.name}"`, `row_status == "NORMAL"`];
|
const filters = [`creator == "${user.name}"`, `row_status == "NORMAL"`];
|
||||||
|
|
@ -57,7 +59,7 @@ const AddMemoRelationPopover = (props: Props) => {
|
||||||
setIsFetching(false);
|
setIsFetching(false);
|
||||||
},
|
},
|
||||||
300,
|
300,
|
||||||
[searchText],
|
[popoverOpen, searchText],
|
||||||
);
|
);
|
||||||
|
|
||||||
const getHighlightedContent = (content: string) => {
|
const getHighlightedContent = (content: string) => {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
import { Dropdown, IconButton, Menu, MenuButton } from "@mui/joy";
|
import { Dropdown, IconButton, Menu, MenuButton } from "@mui/joy";
|
||||||
import { HashIcon } from "lucide-react";
|
import { HashIcon } from "lucide-react";
|
||||||
import { useEffect, useRef, useState } from "react";
|
import { useRef, useState } from "react";
|
||||||
import useClickAway from "react-use/lib/useClickAway";
|
import useClickAway from "react-use/lib/useClickAway";
|
||||||
import OverflowTip from "@/components/kit/OverflowTip";
|
import OverflowTip from "@/components/kit/OverflowTip";
|
||||||
|
import useAsyncEffect from "@/hooks/useAsyncEffect";
|
||||||
import useCurrentUser from "@/hooks/useCurrentUser";
|
import useCurrentUser from "@/hooks/useCurrentUser";
|
||||||
import { useTagStore } from "@/store/v1";
|
import { useTagStore } from "@/store/v1";
|
||||||
import { useTranslate } from "@/utils/i18n";
|
import { useTranslate } from "@/utils/i18n";
|
||||||
|
|
@ -21,15 +22,15 @@ const TagSelector = (props: Props) => {
|
||||||
const tags = tagStore.sortedTags();
|
const tags = tagStore.sortedTags();
|
||||||
const user = useCurrentUser();
|
const user = useCurrentUser();
|
||||||
|
|
||||||
useEffect(() => {
|
useAsyncEffect(async () => {
|
||||||
(async () => {
|
if (!open) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await tagStore.fetchTags({ user });
|
await tagStore.fetchTags({ user });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// do nothing.
|
// do nothing.
|
||||||
}
|
}
|
||||||
})();
|
}, [open]);
|
||||||
}, []);
|
|
||||||
|
|
||||||
useClickAway(containerRef, () => {
|
useClickAway(containerRef, () => {
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
|
|
|
||||||
|
|
@ -312,7 +312,6 @@ const MemoEditor = (props: Props) => {
|
||||||
memoPatch.relations = state.relationList;
|
memoPatch.relations = state.relationList;
|
||||||
}
|
}
|
||||||
const memo = await memoStore.updateMemo(memoPatch, updateMask);
|
const memo = await memoStore.updateMemo(memoPatch, updateMask);
|
||||||
await memoStore.getOrFetchMemoByName(memo.name, { skipCache: true });
|
|
||||||
if (onConfirm) {
|
if (onConfirm) {
|
||||||
onConfirm(memo.name);
|
onConfirm(memo.name);
|
||||||
}
|
}
|
||||||
|
|
@ -338,7 +337,6 @@ const MemoEditor = (props: Props) => {
|
||||||
})
|
})
|
||||||
.then((memo) => memo);
|
.then((memo) => memo);
|
||||||
const memo = await request;
|
const memo = await request;
|
||||||
await memoStore.getOrFetchMemoByName(memo.name, { skipCache: true });
|
|
||||||
if (onConfirm) {
|
if (onConfirm) {
|
||||||
onConfirm(memo.name);
|
onConfirm(memo.name);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import { memoServiceClient } from "@/grpcweb";
|
||||||
import useAsyncEffect from "@/hooks/useAsyncEffect";
|
import useAsyncEffect from "@/hooks/useAsyncEffect";
|
||||||
import useCurrentUser from "@/hooks/useCurrentUser";
|
import useCurrentUser from "@/hooks/useCurrentUser";
|
||||||
import i18n from "@/i18n";
|
import i18n from "@/i18n";
|
||||||
import { useMemoFilterStore, useMemoStore } from "@/store/v1";
|
import { useMemoFilterStore, useMemoList, useMemoStore } from "@/store/v1";
|
||||||
import { useTranslate } from "@/utils/i18n";
|
import { useTranslate } from "@/utils/i18n";
|
||||||
import ActivityCalendar from "./ActivityCalendar";
|
import ActivityCalendar from "./ActivityCalendar";
|
||||||
import { Popover, PopoverContent, PopoverTrigger } from "./ui/Popover";
|
import { Popover, PopoverContent, PopoverTrigger } from "./ui/Popover";
|
||||||
|
|
@ -25,6 +25,7 @@ const UserStatisticsView = () => {
|
||||||
const t = useTranslate();
|
const t = useTranslate();
|
||||||
const currentUser = useCurrentUser();
|
const currentUser = useCurrentUser();
|
||||||
const memoStore = useMemoStore();
|
const memoStore = useMemoStore();
|
||||||
|
const memoList = useMemoList();
|
||||||
const memoFilterStore = useMemoFilterStore();
|
const memoFilterStore = useMemoFilterStore();
|
||||||
const [memoAmount, setMemoAmount] = useState(0);
|
const [memoAmount, setMemoAmount] = useState(0);
|
||||||
const [memoStats, setMemoStats] = useState<UserMemoStats>({ link: 0, taskList: 0, code: 0, incompleteTasks: 0 });
|
const [memoStats, setMemoStats] = useState<UserMemoStats>({ link: 0, taskList: 0, code: 0, incompleteTasks: 0 });
|
||||||
|
|
@ -34,6 +35,8 @@ const UserStatisticsView = () => {
|
||||||
const days = Math.ceil((Date.now() - currentUser.createTime!.getTime()) / 86400000);
|
const days = Math.ceil((Date.now() - currentUser.createTime!.getTime()) / 86400000);
|
||||||
|
|
||||||
useAsyncEffect(async () => {
|
useAsyncEffect(async () => {
|
||||||
|
if (memoList.size() === 0) return;
|
||||||
|
|
||||||
const { entities } = await memoServiceClient.listMemoProperties({
|
const { entities } = await memoServiceClient.listMemoProperties({
|
||||||
name: `memos/-`,
|
name: `memos/-`,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue