From 7a6eb53e0fc9bdcfa2a43f37f55c31002a5159b4 Mon Sep 17 00:00:00 2001 From: f97 Date: Tue, 20 Sep 2022 19:42:14 +0700 Subject: [PATCH] feat: float mobile editor (#234) * feat: float mobile editor * fix: fix pr comment * lint: fix golangci-lint --- api/user_setting.go | 28 +++++++++++++++++-- web/src/components/MemoEditor.tsx | 3 +- .../Settings/PreferencesSection.tsx | 24 ++++++++++++++++ web/src/less/memo-editor.less | 9 ++++++ web/src/locales/en.json | 3 +- web/src/locales/vi.json | 3 +- web/src/locales/zh.json | 3 +- web/src/services/userService.ts | 1 + web/src/types/modules/setting.d.ts | 1 + 9 files changed, 68 insertions(+), 7 deletions(-) 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")}