diff --git a/api/system.go b/api/system.go index bba9e7af..31fe135d 100644 --- a/api/system.go +++ b/api/system.go @@ -6,5 +6,8 @@ type SystemStatus struct { Host *User `json:"host"` Profile *profile.Profile `json:"profile"` // System settings + // Allow sign up. AllowSignUp bool `json:"allowSignUp"` + // Additional style. + AdditionalStyle string `json:"additionalStyle"` } diff --git a/api/system_setting.go b/api/system_setting.go index 4566be07..6327a0ff 100644 --- a/api/system_setting.go +++ b/api/system_setting.go @@ -10,15 +10,16 @@ type SystemSettingName string const ( // SystemSettingAllowSignUpName is the key type of allow signup setting. SystemSettingAllowSignUpName SystemSettingName = "allowSignUp" - SystemSettingPlaceholderName SystemSettingName = "placeholder" + // SystemSettingAdditionalStyleName is the key type of additional style. + SystemSettingAdditionalStyleName SystemSettingName = "additionalStyle" ) func (key SystemSettingName) String() string { switch key { case SystemSettingAllowSignUpName: return "allowSignUp" - case SystemSettingPlaceholderName: - return "placeholder" + case SystemSettingAdditionalStyleName: + return "additionalStyle" } return "" } @@ -58,6 +59,12 @@ func (upsert SystemSettingUpsert) Validate() error { if invalid { return fmt.Errorf("invalid system setting allow signup value") } + } else if upsert.Name == SystemSettingAdditionalStyleName { + value := "" + err := json.Unmarshal([]byte(upsert.Value), &value) + if err != nil { + return fmt.Errorf("failed to unmarshal system setting additional style value") + } } else { return fmt.Errorf("invalid system setting name") } diff --git a/api/user_setting.go b/api/user_setting.go index bf59b15a..6a45d5f6 100644 --- a/api/user_setting.go +++ b/api/user_setting.go @@ -12,9 +12,7 @@ const ( UserSettingLocaleKey UserSettingKey = "locale" // UserSettingMemoVisibilityKey is the key type for user preference memo default visibility. 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 is the key type for mobile editor style. UserSettingMobileEditorStyleKey UserSettingKey = "mobileEditorStyle" // UserSettingMemoDisplayTsOptionKey is the key type for memo display ts option. UserSettingMemoDisplayTsOptionKey UserSettingKey = "memoDisplayTsOption" @@ -27,8 +25,6 @@ func (key UserSettingKey) String() string { return "locale" case UserSettingMemoVisibilityKey: return "memoVisibility" - case UserSettingEditorFontStyleKey: - return "editorFontFamily" case UserSettingMobileEditorStyleKey: return "mobileEditorStyle" case UserSettingMemoDisplayTsOptionKey: @@ -93,23 +89,6 @@ func (upsert UserSettingUpsert) Validate() error { if invalid { return fmt.Errorf("invalid user setting memo visibility value") } - } else if upsert.Key == UserSettingEditorFontStyleKey { - editorFontStyleValue := "normal" - err := json.Unmarshal([]byte(upsert.Value), &editorFontStyleValue) - if err != nil { - return fmt.Errorf("failed to unmarshal user setting editor font style") - } - - invalid := true - for _, value := range UserSettingEditorFontStyleValue { - if editorFontStyleValue == value { - invalid = false - break - } - } - 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) diff --git a/server/system.go b/server/system.go index c463ac1d..dad8fffa 100644 --- a/server/system.go +++ b/server/system.go @@ -38,9 +38,10 @@ func (s *Server) registerSystemRoutes(g *echo.Group) { } systemStatus := api.SystemStatus{ - Host: hostUser, - Profile: s.Profile, - AllowSignUp: false, + Host: hostUser, + Profile: s.Profile, + AllowSignUp: false, + AdditionalStyle: "", } systemSettingList, err := s.Store.FindSystemSettingList(ctx, &api.SystemSettingFind{}) @@ -56,6 +57,8 @@ func (s *Server) registerSystemRoutes(g *echo.Group) { if systemSetting.Name == api.SystemSettingAllowSignUpName { systemStatus.AllowSignUp = value.(bool) + } else if systemSetting.Name == api.SystemSettingAdditionalStyleName { + systemStatus.AdditionalStyle = value.(string) } } diff --git a/web/src/App.tsx b/web/src/App.tsx index 2f1fa29a..7a59fa85 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -5,6 +5,7 @@ import { RouterProvider } from "react-router-dom"; import { globalService, locationService } from "./services"; import { useAppSelector } from "./store"; import router from "./router"; +import * as api from "./helpers/api"; import * as storage from "./helpers/storage"; function App() { @@ -20,6 +21,18 @@ function App() { globalService.initialState(); }, []); + useEffect(() => { + api.getSystemStatus().then(({ data }) => { + const { data: status } = data; + if (status.additionalStyle) { + const styleEl = document.createElement("style"); + styleEl.innerHTML = status.additionalStyle; + styleEl.setAttribute("type", "text/css"); + document.head.appendChild(styleEl); + } + }); + }, []); + useEffect(() => { i18n.changeLanguage(global.locale); storage.set({ diff --git a/web/src/components/MemoEditor.tsx b/web/src/components/MemoEditor.tsx index 8ea3794e..454a8756 100644 --- a/web/src/components/MemoEditor.tsx +++ b/web/src/components/MemoEditor.tsx @@ -55,7 +55,6 @@ const MemoEditor: React.FC = () => { const prevGlobalStateRef = useRef(editorState); const editorRef = useRef(null); const tagSeletorRef = useRef(null); - const editorFontStyle = user?.setting.editorFontStyle || "normal"; const mobileEditorStyle = user?.setting.mobileEditorStyle || "normal"; const memoVisibilityOptionSelectorItems = VISIBILITY_SELECTOR_ITEMS.map((item) => { return { @@ -395,14 +394,14 @@ const MemoEditor: React.FC = () => { const editorConfig = useMemo( () => ({ - className: `memo-editor ${editorFontStyle}`, + className: `memo-editor`, initialContent: getEditorContentCache(), placeholder: t("editor.placeholder"), fullscreen: state.fullscreen, onContentChange: handleContentChange, onPaste: handlePasteEvent, }), - [state.fullscreen, i18n.language, editorFontStyle] + [state.fullscreen, i18n.language] ); return ( diff --git a/web/src/components/Settings/PreferencesSection.tsx b/web/src/components/Settings/PreferencesSection.tsx index a21a78a2..10d7b6c7 100644 --- a/web/src/components/Settings/PreferencesSection.tsx +++ b/web/src/components/Settings/PreferencesSection.tsx @@ -20,17 +20,6 @@ const localeSelectorItems = [ }, ]; -const editorFontStyleSelectorItems = [ - { - text: "Normal", - value: "normal", - }, - { - text: "Mono", - value: "mono", - }, -]; - const mobileEditorStyleSelectorItems = [ { text: "Normal", @@ -68,10 +57,6 @@ const PreferencesSection = () => { await userService.upsertUserSetting("memoVisibility", value); }; - const handleEditorFontStyleChanged = async (value: string) => { - await userService.upsertUserSetting("editorFontStyle", value); - }; - const handleMobileEditorStyleChanged = async (value: string) => { await userService.upsertUserSetting("mobileEditorStyle", value); }; @@ -97,15 +82,6 @@ const PreferencesSection = () => { handleValueChanged={handleDefaultMemoVisibilityChanged} /> -