mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
chore: sort by pinned
This commit is contained in:
@@ -108,6 +108,7 @@ func (s *APIV1Service) ListMemos(ctx context.Context, request *v1pb.ListMemosReq
|
||||
return nil, status.Errorf(codes.InvalidArgument, "invalid parent: %v", err)
|
||||
}
|
||||
memoFind.CreatorID = &userID
|
||||
memoFind.OrderByPinned = true
|
||||
}
|
||||
if request.State == v1pb.State_ARCHIVED {
|
||||
state := store.Archived
|
||||
|
@@ -138,13 +138,15 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
|
||||
if find.OrderByTimeAsc {
|
||||
order = "ASC"
|
||||
}
|
||||
orders := []string{}
|
||||
if find.OrderByUpdatedTs {
|
||||
orders = append(orders, "`updated_ts` "+order)
|
||||
} else {
|
||||
orders = append(orders, "`created_ts` "+order)
|
||||
orderBy := []string{}
|
||||
if find.OrderByPinned {
|
||||
orderBy = append(orderBy, "`pinned` DESC")
|
||||
}
|
||||
if find.OrderByUpdatedTs {
|
||||
orderBy = append(orderBy, "`updated_ts` "+order)
|
||||
} else {
|
||||
orderBy = append(orderBy, "`created_ts` "+order)
|
||||
}
|
||||
orders = append(orders, "`id` "+order)
|
||||
fields := []string{
|
||||
"`memo`.`id` AS `id`",
|
||||
"`memo`.`uid` AS `uid`",
|
||||
@@ -165,7 +167,7 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
|
||||
"LEFT JOIN `memo_relation` ON `memo`.`id` = `memo_relation`.`memo_id` AND `memo_relation`.`type` = 'COMMENT'" + " " +
|
||||
"WHERE " + strings.Join(where, " AND ") + " " +
|
||||
"HAVING " + strings.Join(having, " AND ") + " " +
|
||||
"ORDER BY " + strings.Join(orders, ", ")
|
||||
"ORDER BY " + strings.Join(orderBy, ", ")
|
||||
if find.Limit != nil {
|
||||
query = fmt.Sprintf("%s LIMIT %d", query, *find.Limit)
|
||||
if find.Offset != nil {
|
||||
|
@@ -130,13 +130,15 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
|
||||
if find.OrderByTimeAsc {
|
||||
order = "ASC"
|
||||
}
|
||||
orders := []string{}
|
||||
if find.OrderByUpdatedTs {
|
||||
orders = append(orders, "updated_ts "+order)
|
||||
} else {
|
||||
orders = append(orders, "created_ts "+order)
|
||||
orderBy := []string{}
|
||||
if find.OrderByPinned {
|
||||
orderBy = append(orderBy, "pinned DESC")
|
||||
}
|
||||
if find.OrderByUpdatedTs {
|
||||
orderBy = append(orderBy, "updated_ts "+order)
|
||||
} else {
|
||||
orderBy = append(orderBy, "created_ts "+order)
|
||||
}
|
||||
orders = append(orders, "id "+order)
|
||||
fields := []string{
|
||||
`memo.id AS id`,
|
||||
`memo.uid AS uid`,
|
||||
@@ -157,7 +159,7 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
|
||||
FROM memo
|
||||
LEFT JOIN memo_relation ON memo.id = memo_relation.memo_id AND memo_relation.type = 'COMMENT'
|
||||
WHERE ` + strings.Join(where, " AND ") + `
|
||||
ORDER BY ` + strings.Join(orders, ", ")
|
||||
ORDER BY ` + strings.Join(orderBy, ", ")
|
||||
if find.Limit != nil {
|
||||
query = fmt.Sprintf("%s LIMIT %d", query, *find.Limit)
|
||||
if find.Offset != nil {
|
||||
|
@@ -131,12 +131,14 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
|
||||
order = "ASC"
|
||||
}
|
||||
orderBy := []string{}
|
||||
if find.OrderByPinned {
|
||||
orderBy = append(orderBy, "`pinned` DESC")
|
||||
}
|
||||
if find.OrderByUpdatedTs {
|
||||
orderBy = append(orderBy, "`updated_ts` "+order)
|
||||
} else {
|
||||
orderBy = append(orderBy, "`created_ts` "+order)
|
||||
}
|
||||
orderBy = append(orderBy, "`id` "+order)
|
||||
fields := []string{
|
||||
"`memo`.`id` AS `id`",
|
||||
"`memo`.`uid` AS `uid`",
|
||||
|
@@ -82,6 +82,7 @@ type FindMemo struct {
|
||||
|
||||
// Ordering
|
||||
OrderByUpdatedTs bool
|
||||
OrderByPinned bool
|
||||
OrderByTimeAsc bool
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { isEqual } from "lodash-es";
|
||||
import { CalendarIcon, CheckCircleIcon, CodeIcon, EyeIcon, HashIcon, LinkIcon, PinIcon, SearchIcon, XIcon } from "lucide-react";
|
||||
import { CalendarIcon, CheckCircleIcon, CodeIcon, EyeIcon, HashIcon, LinkIcon, BookmarkIcon, SearchIcon, XIcon } from "lucide-react";
|
||||
import { useEffect } from "react";
|
||||
import { useSearchParams } from "react-router-dom";
|
||||
import { FilterFactor, getMemoFilterKey, MemoFilter, stringifyFilters, useMemoFilterStore } from "@/store/v1";
|
||||
@@ -68,7 +68,7 @@ const FactorIcon = ({ factor, className }: { factor: FilterFactor; className?: s
|
||||
visibility: <EyeIcon className={className} />,
|
||||
contentSearch: <SearchIcon className={className} />,
|
||||
displayTime: <CalendarIcon className={className} />,
|
||||
pinned: <PinIcon className={className} />,
|
||||
pinned: <BookmarkIcon className={className} />,
|
||||
"property.hasLink": <LinkIcon className={className} />,
|
||||
"property.hasTaskList": <CheckCircleIcon className={className} />,
|
||||
"property.hasCode": <CodeIcon className={className} />,
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { Tooltip } from "@mui/joy";
|
||||
import dayjs from "dayjs";
|
||||
import { countBy } from "lodash-es";
|
||||
import { CheckCircleIcon, ChevronRightIcon, ChevronLeftIcon, Code2Icon, LinkIcon, ListTodoIcon, PinIcon } from "lucide-react";
|
||||
import { CheckCircleIcon, ChevronRightIcon, ChevronLeftIcon, Code2Icon, LinkIcon, ListTodoIcon, BookmarkIcon } from "lucide-react";
|
||||
import { observer } from "mobx-react-lite";
|
||||
import { useState } from "react";
|
||||
import DatePicker from "react-datepicker";
|
||||
@@ -107,7 +107,7 @@ const StatisticsView = observer(() => {
|
||||
onClick={() => memoFilterStore.addFilter({ factor: "pinned", value: "" })}
|
||||
>
|
||||
<div className="w-auto flex justify-start items-center mr-1">
|
||||
<PinIcon className="w-4 h-auto mr-1" />
|
||||
<BookmarkIcon className="w-4 h-auto mr-1" />
|
||||
<span className="block text-sm">Pinned</span>
|
||||
</div>
|
||||
<span className="text-sm truncate">{userStore.state.currentUserStats.pinnedMemos.length}</span>
|
||||
|
@@ -59,6 +59,7 @@ const Home = observer(() => {
|
||||
? dayjs(a.displayTime).unix() - dayjs(b.displayTime).unix()
|
||||
: dayjs(b.displayTime).unix() - dayjs(a.displayTime).unix(),
|
||||
)
|
||||
.sort((a, b) => Number(b.pinned) - Number(a.pinned))
|
||||
}
|
||||
owner={user.name}
|
||||
direction={viewStore.state.orderByTimeAsc ? Direction.ASC : Direction.DESC}
|
||||
|
@@ -110,6 +110,7 @@ const UserProfile = observer(() => {
|
||||
? dayjs(a.displayTime).unix() - dayjs(b.displayTime).unix()
|
||||
: dayjs(b.displayTime).unix() - dayjs(a.displayTime).unix(),
|
||||
)
|
||||
.sort((a, b) => Number(b.pinned) - Number(a.pinned))
|
||||
}
|
||||
owner={user.name}
|
||||
direction={viewStore.state.orderByTimeAsc ? Direction.ASC : Direction.DESC}
|
||||
|
Reference in New Issue
Block a user