Skip to content

Commit 8c0bee3

Browse files
committed
chore: tweak refresh button
1 parent 78f6064 commit 8c0bee3

File tree

3 files changed

+41
-39
lines changed

3 files changed

+41
-39
lines changed

web/src/components/UserStatisticsView.tsx

Lines changed: 29 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { Divider, Tooltip } from "@mui/joy";
2-
import { useEffect, useState } from "react";
2+
import { useState } from "react";
33
import toast from "react-hot-toast";
44
import { memoServiceClient } from "@/grpcweb";
5+
import useAsyncEffect from "@/hooks/useAsyncEffect";
56
import { useFilterStore } from "@/store/module";
67
import { useMemoStore } from "@/store/v1";
78
import { User } from "@/types/proto/api/v1/user_service";
89
import { useTranslate } from "@/utils/i18n";
9-
import { showCommonDialog } from "./Dialog/CommonDialog";
1010
import Icon from "./Icon";
1111

1212
interface Props {
@@ -30,51 +30,41 @@ const UserStatisticsView = (props: Props) => {
3030
const days = Math.ceil((Date.now() - user.createTime!.getTime()) / 86400000);
3131
const memos = Object.values(memoStore.getState().memoMapByName);
3232

33-
useEffect(() => {
34-
(async () => {
35-
setIsRequesting(true);
36-
const { properties } = await memoServiceClient.listMemoProperties({
37-
name: `memos/-`,
38-
});
39-
const memoStats: UserMemoStats = { links: 0, todos: 0, code: 0 };
40-
properties.forEach((property) => {
41-
if (property.hasLink) {
42-
memoStats.links += 1;
43-
}
44-
if (property.hasTaskList) {
45-
memoStats.todos += 1;
46-
}
47-
if (property.hasCode) {
48-
memoStats.code += 1;
49-
}
50-
});
51-
setMemoStats(memoStats);
52-
setMemoAmount(properties.length);
53-
setIsRequesting(false);
54-
})();
33+
useAsyncEffect(async () => {
34+
setIsRequesting(true);
35+
const { properties } = await memoServiceClient.listMemoProperties({
36+
name: `memos/-`,
37+
});
38+
const memoStats: UserMemoStats = { links: 0, todos: 0, code: 0 };
39+
properties.forEach((property) => {
40+
if (property.hasLink) {
41+
memoStats.links += 1;
42+
}
43+
if (property.hasTaskList) {
44+
memoStats.todos += 1;
45+
}
46+
if (property.hasCode) {
47+
memoStats.code += 1;
48+
}
49+
});
50+
setMemoStats(memoStats);
51+
setMemoAmount(properties.length);
52+
setIsRequesting(false);
5553
}, [memos.length, user.name]);
5654

57-
const handleRebuildMemoTags = () => {
58-
showCommonDialog({
59-
title: "Refresh",
60-
content: "It will refersh memo properties, are you sure?",
61-
style: "warning",
62-
dialogName: "refersh-memo-property-dialog",
63-
onConfirm: async () => {
64-
await memoServiceClient.rebuildMemoProperty({
65-
name: "memos/-",
66-
});
67-
toast.success("Refresh successfully");
68-
window.location.reload();
69-
},
55+
const handleRebuildMemoTags = async () => {
56+
await memoServiceClient.rebuildMemoProperty({
57+
name: "memos/-",
7058
});
59+
toast.success("Refresh successfully");
60+
window.location.reload();
7161
};
7262

7363
return (
7464
<div className="w-full border mt-2 py-2 px-3 rounded-lg space-y-0.5 text-gray-500 dark:text-gray-400 bg-zinc-50 dark:bg-zinc-900 dark:border-zinc-800">
75-
<div className="group w-full flex flex-row justify-between items-center">
65+
<div className="w-full mb-1 flex flex-row justify-between items-center">
7666
<p className="text-sm font-medium leading-6 dark:text-gray-500">{t("common.statistics")}</p>
77-
<div className="hidden group-hover:block">
67+
<div className="">
7868
<Tooltip title={"Refresh"} placement="top">
7969
<Icon.RefreshCcw
8070
className="text-gray-400 w-4 h-auto cursor-pointer opacity-60 hover:opacity-100"

web/src/hooks/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
export * from "./useLoading";
22
export * from "./useCurrentUser";
33
export * from "./useNavigateTo";
4+
export * from "./useAsyncEffect";
5+
export * from "./useFilterWithUrlParams";
6+
export * from "./useResponsiveWidth";

web/src/hooks/useAsyncEffect.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { DependencyList, useEffect } from "react";
2+
3+
const useAsyncEffect = (effect: () => void | Promise<void>, deps?: DependencyList): void => {
4+
useEffect(() => {
5+
effect();
6+
}, deps);
7+
};
8+
9+
export default useAsyncEffect;

0 commit comments

Comments
 (0)