diff --git a/api/user_setting.go b/api/user_setting.go index 9aeb153e..20cf3bf6 100644 --- a/api/user_setting.go +++ b/api/user_setting.go @@ -14,6 +14,8 @@ const ( UserSettingMemoVisibilityKey UserSettingKey = "memoVisibility" // UserSettingEditorFontStyleKey is the key type for editor font style. UserSettingEditorFontStyleKey UserSettingKey = "editorFontStyle" + // UserSettingEditorFontStyleKey is the key type for mobile editor style. + UserSettingMobileEditorStyleKey UserSettingKey = "mobileEditorStyle" ) // String returns the string format of UserSettingKey type. @@ -25,14 +27,17 @@ func (key UserSettingKey) String() string { return "memoVisibility" case UserSettingEditorFontStyleKey: return "editorFontFamily" + case UserSettingMobileEditorStyleKey: + return "mobileEditorStyle" } return "" } var ( - UserSettingLocaleValue = []string{"en", "zh", "vi"} - UserSettingMemoVisibilityValue = []Visibility{Privite, Protected, Public} - UserSettingEditorFontStyleValue = []string{"normal", "mono"} + UserSettingLocaleValue = []string{"en", "zh", "vi"} + UserSettingMemoVisibilityValue = []Visibility{Privite, Protected, Public} + UserSettingEditorFontStyleValue = []string{"normal", "mono"} + UserSettingMobileEditorStyleValue = []string{"normal", "float"} ) type UserSetting struct { @@ -100,6 +105,23 @@ func (upsert UserSettingUpsert) Validate() error { if invalid { return fmt.Errorf("invalid user setting editor font style value") } + } else if upsert.Key == UserSettingMobileEditorStyleKey { + mobileEditorStyleValue := "normal" + err := json.Unmarshal([]byte(upsert.Value), &mobileEditorStyleValue) + if err != nil { + return fmt.Errorf("failed to unmarshal user setting mobile editor style") + } + + invalid := true + for _, value := range UserSettingMobileEditorStyleValue { + if mobileEditorStyleValue == value { + invalid = false + break + } + } + if invalid { + return fmt.Errorf("invalid user setting mobile editor style value") + } } else { return fmt.Errorf("invalid user setting key") } diff --git a/web/src/components/MemoEditor.tsx b/web/src/components/MemoEditor.tsx index a953a041..ae8be5cf 100644 --- a/web/src/components/MemoEditor.tsx +++ b/web/src/components/MemoEditor.tsx @@ -31,6 +31,7 @@ const MemoEditor = () => { const prevGlobalStateRef = useRef(editorState); const tagSeletorRef = useRef(null); const editorFontStyle = user?.setting.editorFontStyle || "normal"; + const mobileEditorStyle = user?.setting.mobileEditorStyle || "normal"; useEffect(() => { if (editorState.markMemoId && editorState.markMemoId !== UNKNOWN_ID) { @@ -280,7 +281,7 @@ const MemoEditor = () => { ); return ( -
+
{t("editor.editing")}