mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
feat: customize memo list sorting rules (#312)
* chore: update .gitignore * feat: 添加Memo列表按更新时间排序 * fix go-static-checks * update * update * update Memo.tsx/MemoList.tsx * handle conflict Co-authored-by: boojack <stevenlgtm@gmail.com>
This commit is contained in:
@ -16,6 +16,8 @@ const (
|
||||
UserSettingEditorFontStyleKey UserSettingKey = "editorFontStyle"
|
||||
// UserSettingEditorFontStyleKey is the key type for mobile editor style.
|
||||
UserSettingMobileEditorStyleKey UserSettingKey = "mobileEditorStyle"
|
||||
// UserSettingMemoSortOptionKey is the key type for sort time option.
|
||||
UserSettingMemoSortOptionKey UserSettingKey = "memoSortOption"
|
||||
)
|
||||
|
||||
// String returns the string format of UserSettingKey type.
|
||||
@ -29,6 +31,8 @@ func (key UserSettingKey) String() string {
|
||||
return "editorFontFamily"
|
||||
case UserSettingMobileEditorStyleKey:
|
||||
return "mobileEditorStyle"
|
||||
case UserSettingMemoSortOptionKey:
|
||||
return "memoSortOption"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
@ -38,6 +42,7 @@ var (
|
||||
UserSettingMemoVisibilityValue = []Visibility{Privite, Protected, Public}
|
||||
UserSettingEditorFontStyleValue = []string{"normal", "mono"}
|
||||
UserSettingMobileEditorStyleValue = []string{"normal", "float"}
|
||||
UserSettingSortTimeOptionKeyValue = []string{"created_ts", "updated_ts"}
|
||||
)
|
||||
|
||||
type UserSetting struct {
|
||||
@ -122,6 +127,23 @@ func (upsert UserSettingUpsert) Validate() error {
|
||||
if invalid {
|
||||
return fmt.Errorf("invalid user setting mobile editor style value")
|
||||
}
|
||||
} else if upsert.Key == UserSettingMemoSortOptionKey {
|
||||
memoSortOption := "created_ts"
|
||||
err := json.Unmarshal([]byte(upsert.Value), &memoSortOption)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to unmarshal user setting memo sort option")
|
||||
}
|
||||
|
||||
invalid := true
|
||||
for _, value := range UserSettingSortTimeOptionKeyValue {
|
||||
if memoSortOption == value {
|
||||
invalid = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if invalid {
|
||||
return fmt.Errorf("invalid user setting memo sort option value")
|
||||
}
|
||||
} else {
|
||||
return fmt.Errorf("invalid user setting key")
|
||||
}
|
||||
|
Reference in New Issue
Block a user