11import { Divider , Tooltip } from "@mui/joy" ;
2- import { useEffect , useState } from "react" ;
2+ import { useState } from "react" ;
33import toast from "react-hot-toast" ;
44import { memoServiceClient } from "@/grpcweb" ;
5+ import useAsyncEffect from "@/hooks/useAsyncEffect" ;
56import { useFilterStore } from "@/store/module" ;
67import { useMemoStore } from "@/store/v1" ;
78import { User } from "@/types/proto/api/v1/user_service" ;
89import { useTranslate } from "@/utils/i18n" ;
9- import { showCommonDialog } from "./Dialog/CommonDialog" ;
1010import Icon from "./Icon" ;
1111
1212interface 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"
0 commit comments