Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions proto/api/v1/memo_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,9 @@ message ListMemosRequest {

// Optional. If true, show deleted memos in the response.
bool show_deleted = 6 [(google.api.field_behavior) = OPTIONAL];

// Optional. If true, include comment memos in the response.
bool show_comments = 7 [(google.api.field_behavior) = OPTIONAL];
}

message ListMemosResponse {
Expand Down
16 changes: 13 additions & 3 deletions proto/gen/api/v1/memo_service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions proto/gen/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,11 @@ paths:
description: Optional. If true, show deleted memos in the response.
schema:
type: boolean
- name: showComments
in: query
description: Optional. If true, include comment memos in the response.
schema:
type: boolean
responses:
"200":
description: OK
Expand Down
2 changes: 1 addition & 1 deletion scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash

# Exit when any command fails
set -e
Expand Down
7 changes: 3 additions & 4 deletions server/router/api/v1/memo_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ func (s *APIV1Service) CreateMemo(ctx context.Context, request *v1pb.CreateMemoR

func (s *APIV1Service) ListMemos(ctx context.Context, request *v1pb.ListMemosRequest) (*v1pb.ListMemosResponse, error) {
memoFind := &store.FindMemo{
// Exclude comments by default.
ExcludeComments: true,
ExcludeComments: !request.ShowComments,
}
if request.State == v1pb.State_ARCHIVED {
state := store.Archived
Expand Down Expand Up @@ -695,7 +694,7 @@ func (s *APIV1Service) RenameMemoTag(ctx context.Context, request *v1pb.RenameMe
memoFind := &store.FindMemo{
CreatorID: &user.ID,
Filters: []string{fmt.Sprintf("tag in [\"%s\"]", request.OldTag)},
ExcludeComments: true,
ExcludeComments: false,
}
if (request.Parent) != "memos/-" {
memoUID, err := ExtractMemoUIDFromName(request.Parent)
Expand Down Expand Up @@ -746,7 +745,7 @@ func (s *APIV1Service) DeleteMemoTag(ctx context.Context, request *v1pb.DeleteMe
CreatorID: &user.ID,
Filters: []string{fmt.Sprintf("tag in [\"%s\"]", request.Tag)},
ExcludeContent: true,
ExcludeComments: true,
ExcludeComments: false,
}
if request.Parent != "memos/-" {
memoUID, err := ExtractMemoUIDFromName(request.Parent)
Expand Down
8 changes: 3 additions & 5 deletions server/router/api/v1/user_service_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ func (s *APIV1Service) ListAllUserStats(ctx context.Context, _ *v1pb.ListAllUser

normalStatus := store.Normal
memoFind := &store.FindMemo{
// Exclude comments by default.
ExcludeComments: true,
ExcludeComments: false,
ExcludeContent: true,
RowStatus: &normalStatus,
}
Expand Down Expand Up @@ -83,9 +82,8 @@ func (s *APIV1Service) GetUserStats(ctx context.Context, request *v1pb.GetUserSt

normalStatus := store.Normal
memoFind := &store.FindMemo{
CreatorID: &userID,
// Exclude comments by default.
ExcludeComments: true,
CreatorID: &userID,
ExcludeComments: false,
ExcludeContent: true,
RowStatus: &normalStatus,
}
Expand Down
13 changes: 13 additions & 0 deletions web/src/components/MemoDisplaySettingMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Settings2Icon } from "lucide-react";
import { observer } from "mobx-react-lite";
import { Checkbox } from "@/components/ui/checkbox";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import { cn } from "@/lib/utils";
import { viewStore } from "@/store";
Expand Down Expand Up @@ -59,6 +60,18 @@ const MemoDisplaySettingMenu = observer(({ className }: Props) => {
</SelectContent>
</Select>
</div>
<div className="w-full flex flex-row justify-between items-center">
<span className="text-sm shrink-0 mr-3 text-foreground">{t("common.show-comments")}</span>
<Checkbox
id="show-comments"
checked={viewStore.state.showComments}
onCheckedChange={(value) =>
viewStore.state.setPartial({
showComments: Boolean(value),
})
}
/>
</div>
</div>
</PopoverContent>
</Popover>
Expand Down
4 changes: 3 additions & 1 deletion web/src/components/PagedMemoList/PagedMemoList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface Props {
listSort?: (list: Memo[]) => Memo[];
state?: State;
orderBy?: string;
showComments?: boolean;
filter?: string;
pageSize?: number;
}
Expand Down Expand Up @@ -49,6 +50,7 @@ const PagedMemoList = observer((props: Props) => {
const response = await memoStore.fetchMemos({
state: props.state || State.NORMAL,
orderBy: props.orderBy || "display_time desc",
showComments: props.showComments,
filter: props.filter,
pageSize: props.pageSize || DEFAULT_LIST_MEMOS_PAGE_SIZE,
pageToken,
Expand Down Expand Up @@ -99,7 +101,7 @@ const PagedMemoList = observer((props: Props) => {
// Initial load and reload when props change
useEffect(() => {
refreshList();
}, [props.state, props.orderBy, props.filter, props.pageSize]);
}, [props.state, props.orderBy, props.filter, props.pageSize, props.showComments]);

// Auto-fetch more content when list changes and page isn't full
useEffect(() => {
Expand Down
1 change: 1 addition & 0 deletions web/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"language": "Language",
"last-updated-at": "Last updated at",
"layout": "Layout",
"show-comments": "Show comments",
"learn-more": "Learn more",
"link": "Link",
"mark": "Mark",
Expand Down
2 changes: 2 additions & 0 deletions web/src/pages/Archived.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ const Archived = observer(() => {
}
state={State.ARCHIVED}
orderBy={viewStore.state.orderByTimeAsc ? "display_time asc" : "display_time desc"}
// It does not support show comments now
// showComments={viewStore.state.showComments}
filter={memoFitler}
/>
);
Expand Down
1 change: 1 addition & 0 deletions web/src/pages/Explore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const Explore = observer(() => {
)
}
orderBy={viewStore.state.orderByTimeAsc ? "display_time asc" : "display_time desc"}
showComments={viewStore.state.showComments}
/>
</div>
</section>
Expand Down
1 change: 1 addition & 0 deletions web/src/pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const Home = observer(() => {
)
}
orderBy={viewStore.state.orderByTimeAsc ? "display_time asc" : "display_time desc"}
showComments={viewStore.state.showComments}
filter={memoFilter}
/>
</div>
Expand Down
1 change: 1 addition & 0 deletions web/src/pages/UserProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ const UserProfile = observer(() => {
)
}
orderBy={viewStore.state.orderByTimeAsc ? "display_time asc" : "display_time desc"}
showComments={viewStore.state.showComments}
filter={memoFilter}
/>
</>
Expand Down
4 changes: 4 additions & 0 deletions web/src/store/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const LOCAL_STORAGE_KEY = "memos-view-setting";
class LocalState {
orderByTimeAsc: boolean = false;
layout: "LIST" | "MASONRY" = "LIST";
showComments: boolean = false;

constructor() {
makeAutoObservable(this);
Expand Down Expand Up @@ -41,6 +42,9 @@ const viewStore = (() => {
viewStore.state.setPartial({ layout: cache.layout });
}
}
if (Object.hasOwn(cache, "showComments")) {
viewStore.state.setPartial({ showComments: Boolean(cache.showComments) });
}
} catch {
// Do nothing
}
Expand Down
24 changes: 23 additions & 1 deletion web/src/types/proto/api/v1/memo_service.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.