Skip to content

Commit 34ab883

Browse files
committed
chore: sort by pinned
1 parent d794e6d commit 34ab883

File tree

9 files changed

+25
-15
lines changed

9 files changed

+25
-15
lines changed

server/router/api/v1/memo_service.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ func (s *APIV1Service) ListMemos(ctx context.Context, request *v1pb.ListMemosReq
108108
return nil, status.Errorf(codes.InvalidArgument, "invalid parent: %v", err)
109109
}
110110
memoFind.CreatorID = &userID
111+
memoFind.OrderByPinned = true
111112
}
112113
if request.State == v1pb.State_ARCHIVED {
113114
state := store.Archived

store/db/mysql/memo.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,15 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
138138
if find.OrderByTimeAsc {
139139
order = "ASC"
140140
}
141-
orders := []string{}
141+
orderBy := []string{}
142+
if find.OrderByPinned {
143+
orderBy = append(orderBy, "`pinned` DESC")
144+
}
142145
if find.OrderByUpdatedTs {
143-
orders = append(orders, "`updated_ts` "+order)
146+
orderBy = append(orderBy, "`updated_ts` "+order)
144147
} else {
145-
orders = append(orders, "`created_ts` "+order)
148+
orderBy = append(orderBy, "`created_ts` "+order)
146149
}
147-
orders = append(orders, "`id` "+order)
148150
fields := []string{
149151
"`memo`.`id` AS `id`",
150152
"`memo`.`uid` AS `uid`",
@@ -165,7 +167,7 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
165167
"LEFT JOIN `memo_relation` ON `memo`.`id` = `memo_relation`.`memo_id` AND `memo_relation`.`type` = 'COMMENT'" + " " +
166168
"WHERE " + strings.Join(where, " AND ") + " " +
167169
"HAVING " + strings.Join(having, " AND ") + " " +
168-
"ORDER BY " + strings.Join(orders, ", ")
170+
"ORDER BY " + strings.Join(orderBy, ", ")
169171
if find.Limit != nil {
170172
query = fmt.Sprintf("%s LIMIT %d", query, *find.Limit)
171173
if find.Offset != nil {

store/db/postgres/memo.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,15 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
130130
if find.OrderByTimeAsc {
131131
order = "ASC"
132132
}
133-
orders := []string{}
133+
orderBy := []string{}
134+
if find.OrderByPinned {
135+
orderBy = append(orderBy, "pinned DESC")
136+
}
134137
if find.OrderByUpdatedTs {
135-
orders = append(orders, "updated_ts "+order)
138+
orderBy = append(orderBy, "updated_ts "+order)
136139
} else {
137-
orders = append(orders, "created_ts "+order)
140+
orderBy = append(orderBy, "created_ts "+order)
138141
}
139-
orders = append(orders, "id "+order)
140142
fields := []string{
141143
`memo.id AS id`,
142144
`memo.uid AS uid`,
@@ -157,7 +159,7 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
157159
FROM memo
158160
LEFT JOIN memo_relation ON memo.id = memo_relation.memo_id AND memo_relation.type = 'COMMENT'
159161
WHERE ` + strings.Join(where, " AND ") + `
160-
ORDER BY ` + strings.Join(orders, ", ")
162+
ORDER BY ` + strings.Join(orderBy, ", ")
161163
if find.Limit != nil {
162164
query = fmt.Sprintf("%s LIMIT %d", query, *find.Limit)
163165
if find.Offset != nil {

store/db/sqlite/memo.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,14 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
131131
order = "ASC"
132132
}
133133
orderBy := []string{}
134+
if find.OrderByPinned {
135+
orderBy = append(orderBy, "`pinned` DESC")
136+
}
134137
if find.OrderByUpdatedTs {
135138
orderBy = append(orderBy, "`updated_ts` "+order)
136139
} else {
137140
orderBy = append(orderBy, "`created_ts` "+order)
138141
}
139-
orderBy = append(orderBy, "`id` "+order)
140142
fields := []string{
141143
"`memo`.`id` AS `id`",
142144
"`memo`.`uid` AS `uid`",

store/memo.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ type FindMemo struct {
8282

8383
// Ordering
8484
OrderByUpdatedTs bool
85+
OrderByPinned bool
8586
OrderByTimeAsc bool
8687
}
8788

web/src/components/MemoFilters.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { isEqual } from "lodash-es";
2-
import { CalendarIcon, CheckCircleIcon, CodeIcon, EyeIcon, HashIcon, LinkIcon, PinIcon, SearchIcon, XIcon } from "lucide-react";
2+
import { CalendarIcon, CheckCircleIcon, CodeIcon, EyeIcon, HashIcon, LinkIcon, BookmarkIcon, SearchIcon, XIcon } from "lucide-react";
33
import { useEffect } from "react";
44
import { useSearchParams } from "react-router-dom";
55
import { FilterFactor, getMemoFilterKey, MemoFilter, stringifyFilters, useMemoFilterStore } from "@/store/v1";
@@ -68,7 +68,7 @@ const FactorIcon = ({ factor, className }: { factor: FilterFactor; className?: s
6868
visibility: <EyeIcon className={className} />,
6969
contentSearch: <SearchIcon className={className} />,
7070
displayTime: <CalendarIcon className={className} />,
71-
pinned: <PinIcon className={className} />,
71+
pinned: <BookmarkIcon className={className} />,
7272
"property.hasLink": <LinkIcon className={className} />,
7373
"property.hasTaskList": <CheckCircleIcon className={className} />,
7474
"property.hasCode": <CodeIcon className={className} />,

web/src/components/StatisticsView.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Tooltip } from "@mui/joy";
22
import dayjs from "dayjs";
33
import { countBy } from "lodash-es";
4-
import { CheckCircleIcon, ChevronRightIcon, ChevronLeftIcon, Code2Icon, LinkIcon, ListTodoIcon, PinIcon } from "lucide-react";
4+
import { CheckCircleIcon, ChevronRightIcon, ChevronLeftIcon, Code2Icon, LinkIcon, ListTodoIcon, BookmarkIcon } from "lucide-react";
55
import { observer } from "mobx-react-lite";
66
import { useState } from "react";
77
import DatePicker from "react-datepicker";
@@ -107,7 +107,7 @@ const StatisticsView = observer(() => {
107107
onClick={() => memoFilterStore.addFilter({ factor: "pinned", value: "" })}
108108
>
109109
<div className="w-auto flex justify-start items-center mr-1">
110-
<PinIcon className="w-4 h-auto mr-1" />
110+
<BookmarkIcon className="w-4 h-auto mr-1" />
111111
<span className="block text-sm">Pinned</span>
112112
</div>
113113
<span className="text-sm truncate">{userStore.state.currentUserStats.pinnedMemos.length}</span>

web/src/pages/Home.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ const Home = observer(() => {
5959
? dayjs(a.displayTime).unix() - dayjs(b.displayTime).unix()
6060
: dayjs(b.displayTime).unix() - dayjs(a.displayTime).unix(),
6161
)
62+
.sort((a, b) => Number(b.pinned) - Number(a.pinned))
6263
}
6364
owner={user.name}
6465
direction={viewStore.state.orderByTimeAsc ? Direction.ASC : Direction.DESC}

web/src/pages/UserProfile.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ const UserProfile = observer(() => {
110110
? dayjs(a.displayTime).unix() - dayjs(b.displayTime).unix()
111111
: dayjs(b.displayTime).unix() - dayjs(a.displayTime).unix(),
112112
)
113+
.sort((a, b) => Number(b.pinned) - Number(a.pinned))
113114
}
114115
owner={user.name}
115116
direction={viewStore.state.orderByTimeAsc ? Direction.ASC : Direction.DESC}

0 commit comments

Comments
 (0)