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
d1599759
Commit
d1599759
authored
Jun 05, 2024
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: update statistics view
parent
aec5927d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
36 deletions
+34
-36
HomeSidebar.tsx
web/src/components/HomeSidebar/HomeSidebar.tsx
+1
-4
TimelineSidebar.tsx
web/src/components/TimelineSidebar/TimelineSidebar.tsx
+1
-4
UserStatisticsView.tsx
web/src/components/UserStatisticsView.tsx
+20
-21
memo.ts
web/src/store/v1/memo.ts
+12
-7
No files found.
web/src/components/HomeSidebar/HomeSidebar.tsx
View file @
d1599759
import
clsx
from
"clsx"
;
import
SearchBar
from
"@/components/SearchBar"
;
import
UserStatisticsView
from
"@/components/UserStatisticsView"
;
import
useCurrentUser
from
"@/hooks/useCurrentUser"
;
import
TagsSection
from
"./TagsSection"
;
interface
Props
{
...
...
@@ -9,8 +8,6 @@ interface Props {
}
const
HomeSidebar
=
(
props
:
Props
)
=>
{
const
currentUser
=
useCurrentUser
();
return
(
<
aside
className=
{
clsx
(
...
...
@@ -19,7 +16,7 @@ const HomeSidebar = (props: Props) => {
)
}
>
<
SearchBar
/>
<
UserStatisticsView
user=
{
currentUser
}
/>
<
UserStatisticsView
/>
<
TagsSection
/>
</
aside
>
);
...
...
web/src/components/TimelineSidebar/TimelineSidebar.tsx
View file @
d1599759
import
clsx
from
"clsx"
;
import
useCurrentUser
from
"@/hooks/useCurrentUser"
;
import
TagsSection
from
"../HomeSidebar/TagsSection"
;
import
SearchBar
from
"../SearchBar"
;
import
UserStatisticsView
from
"../UserStatisticsView"
;
...
...
@@ -9,8 +8,6 @@ interface Props {
}
const
TimelineSidebar
=
(
props
:
Props
)
=>
{
const
currentUser
=
useCurrentUser
();
return
(
<
aside
className=
{
clsx
(
...
...
@@ -19,7 +16,7 @@ const TimelineSidebar = (props: Props) => {
)
}
>
<
SearchBar
/>
<
UserStatisticsView
user=
{
currentUser
}
/>
<
UserStatisticsView
/>
<
TagsSection
/>
</
aside
>
);
...
...
web/src/components/UserStatisticsView.tsx
View file @
d1599759
...
...
@@ -4,16 +4,12 @@ import { useState } from "react";
import
toast
from
"react-hot-toast"
;
import
{
memoServiceClient
}
from
"@/grpcweb"
;
import
useAsyncEffect
from
"@/hooks/useAsyncEffect"
;
import
useCurrentUser
from
"@/hooks/useCurrentUser"
;
import
{
useFilterStore
}
from
"@/store/module"
;
import
{
useMemoStore
}
from
"@/store/v1"
;
import
{
User
}
from
"@/types/proto/api/v1/user_service"
;
import
{
useTranslate
}
from
"@/utils/i18n"
;
import
Icon
from
"./Icon"
;
interface
Props
{
user
:
User
;
}
interface
UserMemoStats
{
link
:
number
;
taskList
:
number
;
...
...
@@ -21,16 +17,15 @@ interface UserMemoStats {
incompleteTasks
:
number
;
}
const
UserStatisticsView
=
(
props
:
Props
)
=>
{
const
{
user
}
=
props
;
const
UserStatisticsView
=
()
=>
{
const
t
=
useTranslate
();
const
currentUser
=
useCurrentUser
();
const
memoStore
=
useMemoStore
();
const
filterStore
=
useFilterStore
();
const
[
memoAmount
,
setMemoAmount
]
=
useState
(
0
);
const
[
isRequesting
,
setIsRequesting
]
=
useState
(
false
);
const
[
memoStats
,
setMemoStats
]
=
useState
<
UserMemoStats
>
({
link
:
0
,
taskList
:
0
,
code
:
0
,
incompleteTasks
:
0
});
const
days
=
Math
.
ceil
((
Date
.
now
()
-
user
.
createTime
!
.
getTime
())
/
86400000
);
const
memos
=
Object
.
values
(
memoStore
.
getState
().
memoMapByName
);
const
days
=
Math
.
ceil
((
Date
.
now
()
-
currentUser
.
createTime
!
.
getTime
())
/
86400000
);
const
filter
=
filterStore
.
state
;
useAsyncEffect
(
async
()
=>
{
...
...
@@ -56,7 +51,7 @@ const UserStatisticsView = (props: Props) => {
setMemoStats
(
memoStats
);
setMemoAmount
(
properties
.
length
);
setIsRequesting
(
false
);
},
[
memo
s
.
length
,
user
.
name
]);
},
[
memo
Store
.
stateId
]);
const
handleRebuildMemoTags
=
async
()
=>
{
await
memoServiceClient
.
rebuildMemoProperty
({
...
...
@@ -117,20 +112,24 @@ const UserStatisticsView = (props: Props) => {
onClick=
{
()
=>
filterStore
.
setMemoPropertyFilter
({
hasTaskList
:
!
filter
.
memoPropertyFilter
?.
hasTaskList
})
}
>
<
div
className=
"w-auto flex justify-start items-center mr-1"
>
<
Icon
.
CheckCircle
className=
"w-4 h-auto mr-1"
/>
{
memoStats
.
incompleteTasks
>
0
?
(
<
Icon
.
ListTodo
className=
"w-4 h-auto mr-1"
/>
)
:
(
<
Icon
.
CheckCircle
className=
"w-4 h-auto mr-1"
/>
)
}
<
span
className=
"block text-sm"
>
{
t
(
"memo.to-do"
)
}
</
span
>
</
div
>
{
memoStats
.
incompleteTasks
>
0
&&
(
<>
<
Tooltip
title=
{
"Done"
}
placement=
"top"
arrow
>
<
span
className=
"t
ext-sm t
runcate"
>
{
memoStats
.
taskList
-
memoStats
.
incompleteTasks
}
</
span
>
</
Tooltip
>
<
span
className=
"text-sm font-mono opacity-50"
>
/
</
span
>
</
>
)
}
<
Tooltip
title=
{
"Total"
}
placement=
"top"
arrow
>
{
memoStats
.
incompleteTasks
>
0
?
(
<
Tooltip
title=
{
"Done / Total"
}
placement=
"top"
arrow
>
<
div
className=
"text-sm flex flex-row items-start justify-center"
>
<
span
className=
"truncate"
>
{
memoStats
.
taskList
-
memoStats
.
incompleteTasks
}
</
span
>
<
span
className=
"font-mono opacity-50"
>
/
</
span
>
<
span
className=
"truncate"
>
{
memoStats
.
taskList
}
</
span
>
</
div
>
</
Tooltip
>
)
:
(
<
span
className=
"text-sm truncate"
>
{
memoStats
.
taskList
}
</
span
>
</
Tooltip
>
)
}
</
div
>
<
div
className=
{
clsx
(
...
...
web/src/store/v1/memo.ts
View file @
d1599759
import
{
uniqueId
}
from
"lodash-es"
;
import
{
create
}
from
"zustand"
;
import
{
combine
}
from
"zustand/middleware"
;
import
{
memoServiceClient
}
from
"@/grpcweb"
;
import
{
CreateMemoRequest
,
ListMemosRequest
,
Memo
}
from
"@/types/proto/api/v1/memo_service"
;
interface
State
{
// stateId is used to identify the store instance state.
// It should be update when any state change.
stateId
:
string
;
memoMapByName
:
Record
<
string
,
Memo
>
;
}
const
getDefaultState
=
():
State
=>
({
stateId
:
uniqueId
(),
memoMapByName
:
{},
});
...
...
@@ -21,7 +26,7 @@ export const useMemoStore = create(
for
(
const
memo
of
memos
)
{
memoMap
[
memo
.
name
]
=
memo
;
}
set
({
memoMapByName
:
memoMap
});
set
({
stateId
:
uniqueId
(),
memoMapByName
:
memoMap
});
return
{
memos
,
nextPageToken
};
},
getOrFetchMemoByName
:
async
(
name
:
string
,
options
?:
{
skipCache
?:
boolean
;
skipStore
?:
boolean
})
=>
{
...
...
@@ -36,7 +41,7 @@ export const useMemoStore = create(
});
if
(
!
options
?.
skipStore
)
{
memoMap
[
name
]
=
memo
;
set
({
memoMapByName
:
memoMap
});
set
({
stateId
:
uniqueId
(),
memoMapByName
:
memoMap
});
}
return
memo
;
},
...
...
@@ -51,7 +56,7 @@ export const useMemoStore = create(
for
(
const
memo
of
memos
)
{
memoMap
[
memo
.
name
]
=
memo
;
}
set
({
memoMapByName
:
memoMap
});
set
({
stateId
:
uniqueId
(),
memoMapByName
:
memoMap
});
return
memos
;
},
getMemoByUid
:
(
uid
:
string
)
=>
{
...
...
@@ -62,7 +67,7 @@ export const useMemoStore = create(
const
memo
=
await
memoServiceClient
.
createMemo
(
request
);
const
memoMap
=
get
().
memoMapByName
;
memoMap
[
memo
.
name
]
=
memo
;
set
({
memoMapByName
:
memoMap
});
set
({
stateId
:
uniqueId
(),
memoMapByName
:
memoMap
});
return
memo
;
},
updateMemo
:
async
(
update
:
Partial
<
Memo
>
,
updateMask
:
string
[])
=>
{
...
...
@@ -73,7 +78,7 @@ export const useMemoStore = create(
const
memoMap
=
get
().
memoMapByName
;
memoMap
[
memo
.
name
]
=
memo
;
set
({
memoMapByName
:
memoMap
});
set
({
stateId
:
uniqueId
(),
memoMapByName
:
memoMap
});
return
memo
;
},
deleteMemo
:
async
(
name
:
string
)
=>
{
...
...
@@ -83,7 +88,7 @@ export const useMemoStore = create(
const
memoMap
=
get
().
memoMapByName
;
delete
memoMap
[
name
];
set
({
memoMapByName
:
memoMap
});
set
({
stateId
:
uniqueId
(),
memoMapByName
:
memoMap
});
},
})),
);
...
...
@@ -93,7 +98,7 @@ export const useMemoList = () => {
const
memos
=
Object
.
values
(
memoStore
.
getState
().
memoMapByName
);
const
reset
=
()
=>
{
memoStore
.
setState
({
memoMapByName
:
{}
});
memoStore
.
setState
({
stateId
:
uniqueId
(),
memoMapByName
:
{}
});
};
const
size
=
()
=>
{
...
...
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