From b938c8d7b65dba60c6c9fe1851e8b6cdb2d6de88 Mon Sep 17 00:00:00 2001 From: Steven Date: Sun, 8 Oct 2023 00:42:02 +0800 Subject: [PATCH] chore: only show comments in memo detail page --- api/v1/memo.go | 12 ++++++++++-- store/db/sqlite/memo.go | 28 ++++++++++++++++++++------- store/memo.go | 3 ++- web/src/components/Memo.tsx | 30 +++++++++++++++-------------- web/src/components/MemoList.tsx | 2 +- web/src/components/MemoResource.tsx | 28 ++++++++++++--------------- web/src/pages/Explore.tsx | 2 +- web/src/pages/MemoDetail.tsx | 8 ++++---- 8 files changed, 67 insertions(+), 46 deletions(-) diff --git a/api/v1/memo.go b/api/v1/memo.go index 73d56ea8..ddd43411 100644 --- a/api/v1/memo.go +++ b/api/v1/memo.go @@ -144,7 +144,10 @@ func (s *APIV1Service) registerMemoRoutes(g *echo.Group) { // @Router /api/v1/memo [GET] func (s *APIV1Service) GetMemoList(c echo.Context) error { ctx := c.Request().Context() - findMemoMessage := &store.FindMemo{} + hasParentFlag := false + findMemoMessage := &store.FindMemo{ + HasParent: &hasParentFlag, + } if userID, err := util.ConvertStringToInt32(c.QueryParam("creatorId")); err == nil { findMemoMessage.CreatorID = &userID } @@ -404,7 +407,10 @@ func (s *APIV1Service) CreateMemo(c echo.Context) error { // - creatorUsername is listed at ./web/src/helpers/api.ts:82, but it's not present here func (s *APIV1Service) GetAllMemos(c echo.Context) error { ctx := c.Request().Context() - findMemoMessage := &store.FindMemo{} + hasParentFlag := false + findMemoMessage := &store.FindMemo{ + HasParent: &hasParentFlag, + } _, ok := c.Get(userIDContextKey).(int32) if !ok { findMemoMessage.VisibilityList = []store.Visibility{store.Public} @@ -461,8 +467,10 @@ func (s *APIV1Service) GetAllMemos(c echo.Context) error { func (s *APIV1Service) GetMemoStats(c echo.Context) error { ctx := c.Request().Context() normalStatus := store.Normal + hasParentFlag := false findMemoMessage := &store.FindMemo{ RowStatus: &normalStatus, + HasParent: &hasParentFlag, } if creatorID, err := util.ConvertStringToInt32(c.QueryParam("creatorId")); err == nil { findMemoMessage.CreatorID = &creatorID diff --git a/store/db/sqlite/memo.go b/store/db/sqlite/memo.go index a864a22c..d0215391 100644 --- a/store/db/sqlite/memo.go +++ b/store/db/sqlite/memo.go @@ -65,9 +65,6 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo if v := find.CreatedTsAfter; v != nil { where, args = append(where, "memo.created_ts > ?"), append(args, *v) } - if v := find.Pinned; v != nil { - where = append(where, "memo_organizer.pinned = 1") - } if v := find.ContentSearch; len(v) != 0 { for _, s := range v { where, args = append(where, "memo.content LIKE ?"), append(args, "%"+s+"%") @@ -81,6 +78,17 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo } where = append(where, fmt.Sprintf("memo.visibility in (%s)", strings.Join(list, ","))) } + if v := find.Pinned; v != nil { + where = append(where, "memo_organizer.pinned = 1") + } + if v := find.HasParent; v != nil { + if *v { + where = append(where, "parent_id IS NOT NULL") + } else { + where = append(where, "parent_id IS NULL") + } + } + orders := []string{"pinned DESC"} if find.OrderByUpdatedTs { orders = append(orders, "updated_ts DESC") @@ -99,6 +107,15 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo memo.content AS content, memo.visibility AS visibility, CASE WHEN memo_organizer.pinned = 1 THEN 1 ELSE 0 END AS pinned, + ( + SELECT + related_memo_id + FROM + memo_relation + WHERE + memo_relation.memo_id = memo.id AND memo_relation.type = 'COMMENT' + LIMIT 1 + ) AS parent_id, GROUP_CONCAT(resource.id) AS resource_id_list, ( SELECT @@ -145,6 +162,7 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo &memo.Content, &memo.Visibility, &memo.Pinned, + &memo.ParentID, &memoResourceIDList, &memoRelationList, ); err != nil { @@ -184,10 +202,6 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo RelatedMemoID: relatedMemoID, Type: relationType, }) - // Set the first parent ID if relation type is comment. - if memo.ParentID == nil && memoID == memo.ID && relationType == store.MemoRelationComment { - memo.ParentID = &relatedMemoID - } } } list = append(list, &memo) diff --git a/store/memo.go b/store/memo.go index 338d6c4e..e5afa05b 100644 --- a/store/memo.go +++ b/store/memo.go @@ -60,9 +60,10 @@ type FindMemo struct { CreatedTsBefore *int64 // Domain specific fields - Pinned *bool ContentSearch []string VisibilityList []Visibility + Pinned *bool + HasParent *bool // Pagination Limit *int diff --git a/web/src/components/Memo.tsx b/web/src/components/Memo.tsx index d251dcd8..bad0ef10 100644 --- a/web/src/components/Memo.tsx +++ b/web/src/components/Memo.tsx @@ -245,18 +245,26 @@ const Memo: React.FC = (props: Props) => {
- - {memo.pinned ? : } - {memo.pinned ? t("common.unpin") : t("common.pin")} - + {!memo.parent && ( + + {memo.pinned ? ( + + ) : ( + + )} + {memo.pinned ? t("common.unpin") : t("common.pin")} + + )} {t("common.edit")} - - - {t("common.mark")} - + {!memo.parent && ( + + + {t("common.mark")} + + )} @@ -290,12 +298,6 @@ const Memo: React.FC = (props: Props) => {
{creator && ( <> - - - #{memo.id} - - - diff --git a/web/src/components/MemoList.tsx b/web/src/components/MemoList.tsx index e48ab522..345a5511 100644 --- a/web/src/components/MemoList.tsx +++ b/web/src/components/MemoList.tsx @@ -63,7 +63,7 @@ const MemoList: React.FC = () => { return shouldShow; }) : memos - ).filter((memo) => memo.creatorUsername === username && memo.rowStatus === "NORMAL"); + ).filter((memo) => memo.creatorUsername === username && memo.rowStatus === "NORMAL" && !memo.parent); const pinnedMemos = shownMemos.filter((m) => m.pinned); const unpinnedMemos = shownMemos.filter((m) => !m.pinned); diff --git a/web/src/components/MemoResource.tsx b/web/src/components/MemoResource.tsx index 52e8c918..c5ef9299 100644 --- a/web/src/components/MemoResource.tsx +++ b/web/src/components/MemoResource.tsx @@ -16,22 +16,18 @@ const MemoResource: React.FC = (props: Props) => { }; return ( - <> -
- {resource.type.startsWith("audio") ? ( - <> - - - ) : ( - <> - - - {resource.filename} - - - )} -
- +
+ {resource.type.startsWith("audio") ? ( + + ) : ( + <> + + + {resource.filename} + + + )} +
); }; diff --git a/web/src/pages/Explore.tsx b/web/src/pages/Explore.tsx index 706fec61..a2cfe66d 100644 --- a/web/src/pages/Explore.tsx +++ b/web/src/pages/Explore.tsx @@ -54,7 +54,7 @@ const Explore = () => { : memos; const sortedMemos = fetchedMemos - .filter((m) => m.rowStatus === "NORMAL" && m.visibility !== "PRIVATE") + .filter((m) => m.rowStatus === "NORMAL" && m.visibility !== "PRIVATE" && !m.parent) .sort((mi, mj) => mj.displayTs - mi.displayTs); useEffect(() => { diff --git a/web/src/pages/MemoDetail.tsx b/web/src/pages/MemoDetail.tsx index f580624b..19671ca9 100644 --- a/web/src/pages/MemoDetail.tsx +++ b/web/src/pages/MemoDetail.tsx @@ -114,6 +114,10 @@ const MemoDetail = () => {
{getDateTimeString(memo.displayTs)} + + + #{memo.id} +
{memo.parent && (
@@ -127,10 +131,6 @@ const MemoDetail = () => {
- - #{memo.id} - -