mirror of
https://github.com/usememos/memos.git
synced 2025-01-06 23:36:31 +03:00
fix: get memo list order (#370)
This commit is contained in:
parent
0ccfd0c743
commit
64f0662a61
@ -196,22 +196,34 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
|
|||||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to fetch memo list").SetInternal(err)
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to fetch memo list").SetInternal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Slice(list, func(i, j int) bool {
|
var pinnedMemoList []*api.Memo
|
||||||
return list[i].DisplayTs < list[j].DisplayTs
|
var unpinnedMemoList []*api.Memo
|
||||||
})
|
|
||||||
sort.Slice(list, func(i, j int) bool {
|
for _, memo := range list {
|
||||||
if !list[i].Pinned && list[j].Pinned {
|
if memo.Pinned {
|
||||||
return false
|
pinnedMemoList = append(pinnedMemoList, memo)
|
||||||
|
} else {
|
||||||
|
unpinnedMemoList = append(unpinnedMemoList, memo)
|
||||||
}
|
}
|
||||||
return true
|
}
|
||||||
|
|
||||||
|
sort.Slice(pinnedMemoList, func(i, j int) bool {
|
||||||
|
return pinnedMemoList[i].DisplayTs > pinnedMemoList[j].DisplayTs
|
||||||
|
})
|
||||||
|
sort.Slice(unpinnedMemoList, func(i, j int) bool {
|
||||||
|
return unpinnedMemoList[i].DisplayTs > unpinnedMemoList[j].DisplayTs
|
||||||
})
|
})
|
||||||
|
|
||||||
|
var memoList []*api.Memo
|
||||||
|
memoList = append(memoList, pinnedMemoList...)
|
||||||
|
memoList = append(memoList, unpinnedMemoList...)
|
||||||
|
|
||||||
if memoFind.Limit != 0 {
|
if memoFind.Limit != 0 {
|
||||||
list = list[memoFind.Offset:common.Min(len(list), memoFind.Offset+memoFind.Limit)]
|
memoList = memoList[memoFind.Offset:common.Min(len(memoList), 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(memoList)); err != nil {
|
||||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to encode memo list response").SetInternal(err)
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to encode memo list response").SetInternal(err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user