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