Skip to content

Commit 0dfcb1a

Browse files
committed
feat: total memo count
1 parent 3349311 commit 0dfcb1a

File tree

6 files changed

+318
-285
lines changed

6 files changed

+318
-285
lines changed

proto/api/v1/user_service.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ message UserStats {
214214
// The pinned memos of the user.
215215
repeated string pinned_memos = 5;
216216

217+
int32 total_memo_count = 6;
218+
217219
message MemoTypeStats {
218220
int32 link_count = 1;
219221
int32 code_count = 2;

proto/gen/api/v1/user_service.pb.go

Lines changed: 292 additions & 281 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/gen/apidocs.swagger.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3277,6 +3277,9 @@ definitions:
32773277
items:
32783278
type: string
32793279
description: The pinned memos of the user.
3280+
totalMemoCount:
3281+
type: integer
3282+
format: int32
32803283
v1Visibility:
32813284
type: string
32823285
enum:

server/router/api/v1/user_service_stats.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ func (s *APIV1Service) ListAllUserStats(ctx context.Context, _ *v1pb.ListAllUser
8787
if memo.Payload.Property.GetHasIncompleteTasks() {
8888
userStats.MemoTypeStats.UndoCount++
8989
}
90+
userStats.TotalMemoCount++
9091
}
9192
userStatsList := []*v1pb.UserStats{}
9293
for _, userStats := range userStatsMap {
@@ -142,6 +143,7 @@ func (s *APIV1Service) GetUserStats(ctx context.Context, request *v1pb.GetUserSt
142143
MemoDisplayTimestamps: []*timestamppb.Timestamp{},
143144
MemoTypeStats: &v1pb.UserStats_MemoTypeStats{},
144145
TagCount: map[string]int32{},
146+
TotalMemoCount: int32(len(memos)),
145147
}
146148
for _, memo := range memos {
147149
displayTs := memo.CreatedTs

web/src/components/HomeSidebar/HomeSidebar.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,20 @@ const HomeSidebar = observer((props: Props) => {
7979
key={navLink.id}
8080
className={({ isActive }) =>
8181
cn(
82-
"w-full px-2 rounded-xl border flex flex-row items-center text-sm text-zinc-600 dark:text-gray-400 hover:bg-white hover:border-gray-200 dark:hover:border-zinc-700 dark:hover:bg-zinc-800",
82+
"w-full px-2 rounded-xl border flex flex-row items-center justify-between text-sm text-zinc-600 dark:text-gray-400 hover:bg-white hover:border-gray-200 dark:hover:border-zinc-700 dark:hover:bg-zinc-800",
8383
isActive ? "bg-white drop-shadow-sm dark:bg-zinc-800 border-gray-200 dark:border-zinc-700" : "border-transparent",
8484
)
8585
}
8686
to={navLink.path}
8787
viewTransition
8888
>
89-
{navLink.icon}
90-
<span className="ml-2 truncate leading-8">{navLink.title}</span>
89+
<div className="flex flex-row items-center">
90+
{navLink.icon}
91+
<span className="ml-2 truncate leading-8">{navLink.title}</span>
92+
</div>
93+
{navLink.path === Routes.ROOT && currentUser && userStore.state.currentUserStats && (
94+
<span className="font-mono text-xs opacity-80">{userStore.state.currentUserStats.totalMemoCount}</span>
95+
)}
9196
</NavLink>
9297
))}
9398
</div>

web/src/store/v2/user.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ class LocalState {
2626
return tagCount;
2727
}
2828

29+
get currentUserStats() {
30+
if (!this.currentUser) {
31+
return undefined;
32+
}
33+
return this.userStatsByName[this.currentUser];
34+
}
35+
2936
constructor() {
3037
makeAutoObservable(this);
3138
}
@@ -171,7 +178,10 @@ const userStore = (() => {
171178
userStatsByName[user] = userStats;
172179
}
173180
state.setPartial({
174-
userStatsByName,
181+
userStatsByName: {
182+
...state.userStatsByName,
183+
...userStatsByName,
184+
},
175185
});
176186
};
177187

0 commit comments

Comments
 (0)