Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
8c0bee38
Commit
8c0bee38
authored
Jun 01, 2024
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: tweak refresh button
parent
78f60645
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
39 deletions
+41
-39
UserStatisticsView.tsx
web/src/components/UserStatisticsView.tsx
+29
-39
index.ts
web/src/hooks/index.ts
+3
-0
useAsyncEffect.ts
web/src/hooks/useAsyncEffect.ts
+9
-0
No files found.
web/src/components/UserStatisticsView.tsx
View file @
8c0bee38
import
{
Divider
,
Tooltip
}
from
"@mui/joy"
;
import
{
Divider
,
Tooltip
}
from
"@mui/joy"
;
import
{
use
Effect
,
use
State
}
from
"react"
;
import
{
useState
}
from
"react"
;
import
toast
from
"react-hot-toast"
;
import
toast
from
"react-hot-toast"
;
import
{
memoServiceClient
}
from
"@/grpcweb"
;
import
{
memoServiceClient
}
from
"@/grpcweb"
;
import
useAsyncEffect
from
"@/hooks/useAsyncEffect"
;
import
{
useFilterStore
}
from
"@/store/module"
;
import
{
useFilterStore
}
from
"@/store/module"
;
import
{
useMemoStore
}
from
"@/store/v1"
;
import
{
useMemoStore
}
from
"@/store/v1"
;
import
{
User
}
from
"@/types/proto/api/v1/user_service"
;
import
{
User
}
from
"@/types/proto/api/v1/user_service"
;
import
{
useTranslate
}
from
"@/utils/i18n"
;
import
{
useTranslate
}
from
"@/utils/i18n"
;
import
{
showCommonDialog
}
from
"./Dialog/CommonDialog"
;
import
Icon
from
"./Icon"
;
import
Icon
from
"./Icon"
;
interface
Props
{
interface
Props
{
...
@@ -30,51 +30,41 @@ const UserStatisticsView = (props: Props) => {
...
@@ -30,51 +30,41 @@ const UserStatisticsView = (props: Props) => {
const
days
=
Math
.
ceil
((
Date
.
now
()
-
user
.
createTime
!
.
getTime
())
/
86400000
);
const
days
=
Math
.
ceil
((
Date
.
now
()
-
user
.
createTime
!
.
getTime
())
/
86400000
);
const
memos
=
Object
.
values
(
memoStore
.
getState
().
memoMapByName
);
const
memos
=
Object
.
values
(
memoStore
.
getState
().
memoMapByName
);
useEffect
(()
=>
{
useAsyncEffect
(
async
()
=>
{
(
async
()
=>
{
setIsRequesting
(
true
);
setIsRequesting
(
true
);
const
{
properties
}
=
await
memoServiceClient
.
listMemoProperties
({
const
{
properties
}
=
await
memoServiceClient
.
listMemoProperties
({
name
:
`memos/-`
,
name
:
`memos/-`
,
});
});
const
memoStats
:
UserMemoStats
=
{
links
:
0
,
todos
:
0
,
code
:
0
};
const
memoStats
:
UserMemoStats
=
{
links
:
0
,
todos
:
0
,
code
:
0
};
properties
.
forEach
((
property
)
=>
{
properties
.
forEach
((
property
)
=>
{
if
(
property
.
hasLink
)
{
if
(
property
.
hasLink
)
{
memoStats
.
links
+=
1
;
memoStats
.
links
+=
1
;
}
}
if
(
property
.
hasTaskList
)
{
if
(
property
.
hasTaskList
)
{
memoStats
.
todos
+=
1
;
memoStats
.
todos
+=
1
;
}
}
if
(
property
.
hasCode
)
{
if
(
property
.
hasCode
)
{
memoStats
.
code
+=
1
;
memoStats
.
code
+=
1
;
}
}
});
});
setMemoStats
(
memoStats
);
setMemoStats
(
memoStats
);
setMemoAmount
(
properties
.
length
);
setMemoAmount
(
properties
.
length
);
setIsRequesting
(
false
);
setIsRequesting
(
false
);
})();
},
[
memos
.
length
,
user
.
name
]);
},
[
memos
.
length
,
user
.
name
]);
const
handleRebuildMemoTags
=
()
=>
{
const
handleRebuildMemoTags
=
async
()
=>
{
showCommonDialog
({
await
memoServiceClient
.
rebuildMemoProperty
({
title
:
"Refresh"
,
name
:
"memos/-"
,
content
:
"It will refersh memo properties, are you sure?"
,
style
:
"warning"
,
dialogName
:
"refersh-memo-property-dialog"
,
onConfirm
:
async
()
=>
{
await
memoServiceClient
.
rebuildMemoProperty
({
name
:
"memos/-"
,
});
toast
.
success
(
"Refresh successfully"
);
window
.
location
.
reload
();
},
});
});
toast
.
success
(
"Refresh successfully"
);
window
.
location
.
reload
();
};
};
return
(
return
(
<
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"
>
<
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"
>
<
div
className=
"
group w-full
flex flex-row justify-between items-center"
>
<
div
className=
"
w-full mb-1
flex flex-row justify-between items-center"
>
<
p
className=
"text-sm font-medium leading-6 dark:text-gray-500"
>
{
t
(
"common.statistics"
)
}
</
p
>
<
p
className=
"text-sm font-medium leading-6 dark:text-gray-500"
>
{
t
(
"common.statistics"
)
}
</
p
>
<
div
className=
"
hidden group-hover:block
"
>
<
div
className=
""
>
<
Tooltip
title=
{
"Refresh"
}
placement=
"top"
>
<
Tooltip
title=
{
"Refresh"
}
placement=
"top"
>
<
Icon
.
RefreshCcw
<
Icon
.
RefreshCcw
className=
"text-gray-400 w-4 h-auto cursor-pointer opacity-60 hover:opacity-100"
className=
"text-gray-400 w-4 h-auto cursor-pointer opacity-60 hover:opacity-100"
...
...
web/src/hooks/index.ts
View file @
8c0bee38
export
*
from
"./useLoading"
;
export
*
from
"./useLoading"
;
export
*
from
"./useCurrentUser"
;
export
*
from
"./useCurrentUser"
;
export
*
from
"./useNavigateTo"
;
export
*
from
"./useNavigateTo"
;
export
*
from
"./useAsyncEffect"
;
export
*
from
"./useFilterWithUrlParams"
;
export
*
from
"./useResponsiveWidth"
;
web/src/hooks/useAsyncEffect.ts
0 → 100644
View file @
8c0bee38
import
{
DependencyList
,
useEffect
}
from
"react"
;
const
useAsyncEffect
=
(
effect
:
()
=>
void
|
Promise
<
void
>
,
deps
?:
DependencyList
):
void
=>
{
useEffect
(()
=>
{
effect
();
},
deps
);
};
export
default
useAsyncEffect
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment