Commit cc43d06d authored by Steven's avatar Steven

chore: update memo stats response

parent 9ffd8270
...@@ -143,11 +143,11 @@ func (s *APIV2Service) ListMemos(ctx context.Context, request *apiv2pb.ListMemos ...@@ -143,11 +143,11 @@ func (s *APIV2Service) ListMemos(ctx context.Context, request *apiv2pb.ListMemos
memoFind.VisibilityList = []store.Visibility{store.Public, store.Protected} memoFind.VisibilityList = []store.Visibility{store.Public, store.Protected}
} }
memoDisplayWithUpdatedTs, err := s.getMemoDisplayWithUpdatedTsSettingValue(ctx) displayWithUpdatedTs, err := s.getMemoDisplayWithUpdatedTsSettingValue(ctx)
if err != nil { if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get memo display with updated ts setting value") return nil, status.Errorf(codes.Internal, "failed to get memo display with updated ts setting value")
} }
if memoDisplayWithUpdatedTs { if displayWithUpdatedTs {
memoFind.OrderByUpdatedTs = true memoFind.OrderByUpdatedTs = true
} }
...@@ -436,12 +436,20 @@ func (s *APIV2Service) GetUserMemosStats(ctx context.Context, request *apiv2pb.G ...@@ -436,12 +436,20 @@ func (s *APIV2Service) GetUserMemosStats(ctx context.Context, request *apiv2pb.G
} }
normalRowStatus := store.Normal normalRowStatus := store.Normal
memos, err := s.Store.ListMemos(ctx, &store.FindMemo{ memoFind := &store.FindMemo{
CreatorID: &user.ID, CreatorID: &user.ID,
RowStatus: &normalRowStatus, RowStatus: &normalRowStatus,
ExcludeComments: true, ExcludeComments: true,
ExcludeContent: true, ExcludeContent: true,
}) }
displayWithUpdatedTs, err := s.getMemoDisplayWithUpdatedTsSettingValue(ctx)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get memo display with updated ts setting value")
}
if displayWithUpdatedTs {
memoFind.OrderByUpdatedTs = true
}
memos, err := s.Store.ListMemos(ctx, memoFind)
if err != nil { if err != nil {
return nil, status.Errorf(codes.Internal, "failed to list memos") return nil, status.Errorf(codes.Internal, "failed to list memos")
} }
...@@ -451,13 +459,17 @@ func (s *APIV2Service) GetUserMemosStats(ctx context.Context, request *apiv2pb.G ...@@ -451,13 +459,17 @@ func (s *APIV2Service) GetUserMemosStats(ctx context.Context, request *apiv2pb.G
return nil, status.Errorf(codes.Internal, "invalid timezone location") return nil, status.Errorf(codes.Internal, "invalid timezone location")
} }
creationStats := make(map[string]int32) stats := make(map[string]int32)
for _, memo := range memos { for _, memo := range memos {
creationStats[time.Unix(memo.CreatedTs, 0).In(location).Format("2006-01-02")]++ displayTs := memo.CreatedTs
if displayWithUpdatedTs {
displayTs = memo.UpdatedTs
}
stats[time.Unix(displayTs, 0).In(location).Format("2006-01-02")]++
} }
response := &apiv2pb.GetUserMemosStatsResponse{ response := &apiv2pb.GetUserMemosStatsResponse{
MemoCreationStats: creationStats, Stats: stats,
} }
return response, nil return response, nil
} }
......
...@@ -244,7 +244,7 @@ message GetUserMemosStatsRequest { ...@@ -244,7 +244,7 @@ message GetUserMemosStatsRequest {
} }
message GetUserMemosStatsResponse { message GetUserMemosStatsResponse {
// memo_creation_stats is the stats of memo creation. // stats is the stats of memo creating/updating activities.
// key is the year-month-day string. e.g. "2020-01-01". value is the count of memos created. // key is the year-month-day string. e.g. "2020-01-01".
map<string, int32> memo_creation_stats = 1; map<string, int32> stats = 1;
} }
...@@ -126,7 +126,7 @@ ...@@ -126,7 +126,7 @@
- [GetMemoResponse](#memos-api-v2-GetMemoResponse) - [GetMemoResponse](#memos-api-v2-GetMemoResponse)
- [GetUserMemosStatsRequest](#memos-api-v2-GetUserMemosStatsRequest) - [GetUserMemosStatsRequest](#memos-api-v2-GetUserMemosStatsRequest)
- [GetUserMemosStatsResponse](#memos-api-v2-GetUserMemosStatsResponse) - [GetUserMemosStatsResponse](#memos-api-v2-GetUserMemosStatsResponse)
- [GetUserMemosStatsResponse.MemoCreationStatsEntry](#memos-api-v2-GetUserMemosStatsResponse-MemoCreationStatsEntry) - [GetUserMemosStatsResponse.StatsEntry](#memos-api-v2-GetUserMemosStatsResponse-StatsEntry)
- [ListMemoCommentsRequest](#memos-api-v2-ListMemoCommentsRequest) - [ListMemoCommentsRequest](#memos-api-v2-ListMemoCommentsRequest)
- [ListMemoCommentsResponse](#memos-api-v2-ListMemoCommentsResponse) - [ListMemoCommentsResponse](#memos-api-v2-ListMemoCommentsResponse)
- [ListMemoRelationsRequest](#memos-api-v2-ListMemoRelationsRequest) - [ListMemoRelationsRequest](#memos-api-v2-ListMemoRelationsRequest)
...@@ -1794,16 +1794,16 @@ ...@@ -1794,16 +1794,16 @@
| Field | Type | Label | Description | | Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- | | ----- | ---- | ----- | ----------- |
| memo_creation_stats | [GetUserMemosStatsResponse.MemoCreationStatsEntry](#memos-api-v2-GetUserMemosStatsResponse-MemoCreationStatsEntry) | repeated | memo_creation_stats is the stats of memo creation. key is the year-month-day string. e.g. &#34;2020-01-01&#34;. value is the count of memos created. | | stats | [GetUserMemosStatsResponse.StatsEntry](#memos-api-v2-GetUserMemosStatsResponse-StatsEntry) | repeated | stats is the stats of memo creating/updating activities. key is the year-month-day string. e.g. &#34;2020-01-01&#34;. |
<a name="memos-api-v2-GetUserMemosStatsResponse-MemoCreationStatsEntry"></a> <a name="memos-api-v2-GetUserMemosStatsResponse-StatsEntry"></a>
### GetUserMemosStatsResponse.MemoCreationStatsEntry ### GetUserMemosStatsResponse.StatsEntry
......
This diff is collapsed.
...@@ -26,12 +26,12 @@ const PersonalStatistics = (props: Props) => { ...@@ -26,12 +26,12 @@ const PersonalStatistics = (props: Props) => {
(async () => { (async () => {
setIsRequesting(true); setIsRequesting(true);
const { memoCreationStats } = await memoServiceClient.getUserMemosStats({ const { stats } = await memoServiceClient.getUserMemosStats({
name: user.name, name: user.name,
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone, timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
}); });
setIsRequesting(false); setIsRequesting(false);
setMemoAmount(Object.values(memoCreationStats).reduce((acc, cur) => acc + cur, 0)); setMemoAmount(Object.values(stats).reduce((acc, cur) => acc + cur, 0));
})(); })();
}, [memos.length, user.name]); }, [memos.length, user.name]);
......
...@@ -14,7 +14,7 @@ const UserBanner = () => { ...@@ -14,7 +14,7 @@ const UserBanner = () => {
const title = user ? user.nickname || user.username : systemStatus.customizedProfile.name || "memos"; const title = user ? user.nickname || user.username : systemStatus.customizedProfile.name || "memos";
const avatarUrl = user ? user.avatarUrl : systemStatus.customizedProfile.logoUrl; const avatarUrl = user ? user.avatarUrl : systemStatus.customizedProfile.logoUrl;
const handleSignOutBtnClick = async () => { const handleSignOut = async () => {
await api.signout(); await api.signout();
window.location.href = "/auth"; window.location.href = "/auth";
}; };
...@@ -37,9 +37,10 @@ const UserBanner = () => { ...@@ -37,9 +37,10 @@ const UserBanner = () => {
{user != undefined && ( {user != undefined && (
<button <button
className="w-full px-3 truncate text-left leading-10 cursor-pointer rounded flex flex-row justify-start items-center dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-zinc-800" className="w-full px-3 truncate text-left leading-10 cursor-pointer rounded flex flex-row justify-start items-center dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-zinc-800"
onClick={handleSignOutBtnClick} onClick={handleSignOut}
> >
<Icon.LogOut className="w-5 h-auto mr-1 opacity-60" /> {t("common.sign-out")} <Icon.LogOut className="w-5 h-auto mr-1 opacity-60 shrink-0" />
<span className="truncate">{t("common.sign-out")}</span>
</button> </button>
)} )}
</> </>
......
...@@ -36,12 +36,12 @@ const DatePicker: React.FC<DatePickerProps> = (props: DatePickerProps) => { ...@@ -36,12 +36,12 @@ const DatePicker: React.FC<DatePickerProps> = (props: DatePickerProps) => {
useEffect(() => { useEffect(() => {
(async () => { (async () => {
const { memoCreationStats } = await memoServiceClient.getUserMemosStats({ const { stats } = await memoServiceClient.getUserMemosStats({
name: user.name, name: user.name,
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone, timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
}); });
const m = new Map(); const m = new Map();
Object.entries(memoCreationStats).forEach(([k]) => { Object.entries(stats).forEach(([k]) => {
const utcOffsetMilliseconds = new Date().getTimezoneOffset() * 60 * 1000; const utcOffsetMilliseconds = new Date().getTimezoneOffset() * 60 * 1000;
const date = getDateStampByDate(new Date(getTimeStampByDate(k) + utcOffsetMilliseconds)); const date = getDateStampByDate(new Date(getTimeStampByDate(k) + utcOffsetMilliseconds));
m.set(date, true); m.set(date, true);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment