mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
chore: update memo list api (#350)
This commit is contained in:
@ -28,3 +28,10 @@ func ValidateEmail(email string) bool {
|
|||||||
func GenUUID() string {
|
func GenUUID() string {
|
||||||
return uuid.New().String()
|
return uuid.New().String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Min(x, y int) int {
|
||||||
|
if x < y {
|
||||||
|
return x
|
||||||
|
}
|
||||||
|
return y
|
||||||
|
}
|
||||||
|
@ -193,8 +193,18 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sort.Slice(list, func(i, j int) bool {
|
sort.Slice(list, func(i, j int) bool {
|
||||||
return list[i].DisplayTs > list[j].DisplayTs
|
return list[i].DisplayTs < list[j].DisplayTs
|
||||||
})
|
})
|
||||||
|
sort.Slice(list, func(i, j int) bool {
|
||||||
|
if !list[i].Pinned && list[j].Pinned {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
|
if memoFind.Limit != 0 {
|
||||||
|
list = list[memoFind.Offset:common.Min(len(list), memoFind.Offset+memoFind.Limit)]
|
||||||
|
}
|
||||||
|
|
||||||
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
|
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
|
||||||
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(list)); err != nil {
|
if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(list)); err != nil {
|
||||||
|
@ -329,14 +329,6 @@ func findMemoRawList(ctx context.Context, tx *sql.Tx, find *api.MemoFind) ([]*me
|
|||||||
where = append(where, fmt.Sprintf("visibility in (%s)", strings.Join(list, ",")))
|
where = append(where, fmt.Sprintf("visibility in (%s)", strings.Join(list, ",")))
|
||||||
}
|
}
|
||||||
|
|
||||||
pagination := ""
|
|
||||||
if find.Limit > 0 {
|
|
||||||
pagination = fmt.Sprintf("%s LIMIT %d", pagination, find.Limit)
|
|
||||||
if find.Offset > 0 {
|
|
||||||
pagination = fmt.Sprintf("%s OFFSET %d", pagination, find.Offset)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
query := `
|
query := `
|
||||||
SELECT
|
SELECT
|
||||||
id,
|
id,
|
||||||
@ -349,7 +341,7 @@ func findMemoRawList(ctx context.Context, tx *sql.Tx, find *api.MemoFind) ([]*me
|
|||||||
FROM memo
|
FROM memo
|
||||||
WHERE ` + strings.Join(where, " AND ") + `
|
WHERE ` + strings.Join(where, " AND ") + `
|
||||||
ORDER BY created_ts DESC
|
ORDER BY created_ts DESC
|
||||||
` + pagination
|
`
|
||||||
rows, err := tx.QueryContext(ctx, query, args...)
|
rows, err := tx.QueryContext(ctx, query, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, FormatError(err)
|
return nil, FormatError(err)
|
||||||
|
@ -78,6 +78,9 @@ export function getMemoList(memoFind?: MemoFind) {
|
|||||||
if (memoFind?.rowStatus) {
|
if (memoFind?.rowStatus) {
|
||||||
queryList.push(`rowStatus=${memoFind.rowStatus}`);
|
queryList.push(`rowStatus=${memoFind.rowStatus}`);
|
||||||
}
|
}
|
||||||
|
if (memoFind?.pinned) {
|
||||||
|
queryList.push(`pinned=${memoFind.pinned}`);
|
||||||
|
}
|
||||||
if (memoFind?.offset) {
|
if (memoFind?.offset) {
|
||||||
queryList.push(`offset=${memoFind.offset}`);
|
queryList.push(`offset=${memoFind.offset}`);
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { uniqBy } from "lodash";
|
||||||
import * as api from "../helpers/api";
|
import * as api from "../helpers/api";
|
||||||
import { createMemo, deleteMemo, patchMemo, setIsFetching, setMemos, setTags } from "../store/modules/memo";
|
import { createMemo, deleteMemo, patchMemo, setIsFetching, setMemos, setTags } from "../store/modules/memo";
|
||||||
import store from "../store";
|
import store from "../store";
|
||||||
@ -35,7 +36,7 @@ const memoService = {
|
|||||||
store.dispatch(setMemos([]));
|
store.dispatch(setMemos([]));
|
||||||
}
|
}
|
||||||
const memos = memoService.getState().memos;
|
const memos = memoService.getState().memos;
|
||||||
store.dispatch(setMemos(memos.concat(fetchedMemos)));
|
store.dispatch(setMemos(uniqBy(memos.concat(fetchedMemos), "id")));
|
||||||
store.dispatch(setIsFetching(false));
|
store.dispatch(setIsFetching(false));
|
||||||
|
|
||||||
return fetchedMemos;
|
return fetchedMemos;
|
||||||
|
@ -18,7 +18,7 @@ const memoSlice = createSlice({
|
|||||||
setMemos: (state, action: PayloadAction<Memo[]>) => {
|
setMemos: (state, action: PayloadAction<Memo[]>) => {
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
memos: action.payload.filter((m) => m.rowStatus === "NORMAL"),
|
memos: action.payload,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
createMemo: (state, action: PayloadAction<Memo>) => {
|
createMemo: (state, action: PayloadAction<Memo>) => {
|
||||||
|
1
web/src/types/modules/memo.d.ts
vendored
1
web/src/types/modules/memo.d.ts
vendored
@ -37,6 +37,7 @@ interface MemoPatch {
|
|||||||
interface MemoFind {
|
interface MemoFind {
|
||||||
creatorId?: UserId;
|
creatorId?: UserId;
|
||||||
rowStatus?: RowStatus;
|
rowStatus?: RowStatus;
|
||||||
|
pinned?: boolean;
|
||||||
visibility?: Visibility;
|
visibility?: Visibility;
|
||||||
offset?: number;
|
offset?: number;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
|
Reference in New Issue
Block a user