mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
chore: update user setting key convention (#1447)
* chore: update user settng key convention * chore: update
This commit is contained in:
@@ -15,9 +15,7 @@ const (
|
|||||||
// UserSettingAppearanceKey is the key type for user appearance.
|
// UserSettingAppearanceKey is the key type for user appearance.
|
||||||
UserSettingAppearanceKey UserSettingKey = "appearance"
|
UserSettingAppearanceKey UserSettingKey = "appearance"
|
||||||
// UserSettingMemoVisibilityKey is the key type for user preference memo default visibility.
|
// UserSettingMemoVisibilityKey is the key type for user preference memo default visibility.
|
||||||
UserSettingMemoVisibilityKey UserSettingKey = "memoVisibility"
|
UserSettingMemoVisibilityKey UserSettingKey = "memo-visibility"
|
||||||
// UserSettingResourceVisibilityKey is the key type for user preference resource default visibility.
|
|
||||||
UserSettingResourceVisibilityKey UserSettingKey = "resourceVisibility"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// String returns the string format of UserSettingKey type.
|
// String returns the string format of UserSettingKey type.
|
||||||
@@ -28,9 +26,7 @@ func (key UserSettingKey) String() string {
|
|||||||
case UserSettingAppearanceKey:
|
case UserSettingAppearanceKey:
|
||||||
return "appearance"
|
return "appearance"
|
||||||
case UserSettingMemoVisibilityKey:
|
case UserSettingMemoVisibilityKey:
|
||||||
return "memoVisibility"
|
return "memo-visibility"
|
||||||
case UserSettingResourceVisibilityKey:
|
|
||||||
return "resourceVisibility"
|
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
@@ -39,7 +35,6 @@ var (
|
|||||||
UserSettingLocaleValue = []string{"en", "zh", "vi", "fr", "nl", "sv", "de", "es", "uk", "ru", "it", "hant", "tr", "ko", "sl"}
|
UserSettingLocaleValue = []string{"en", "zh", "vi", "fr", "nl", "sv", "de", "es", "uk", "ru", "it", "hant", "tr", "ko", "sl"}
|
||||||
UserSettingAppearanceValue = []string{"system", "light", "dark"}
|
UserSettingAppearanceValue = []string{"system", "light", "dark"}
|
||||||
UserSettingMemoVisibilityValue = []Visibility{Private, Protected, Public}
|
UserSettingMemoVisibilityValue = []Visibility{Private, Protected, Public}
|
||||||
UserSettingResourceVisibilityValue = []Visibility{Private, Protected, Public}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type UserSetting struct {
|
type UserSetting struct {
|
||||||
@@ -83,15 +78,6 @@ func (upsert UserSettingUpsert) Validate() error {
|
|||||||
if !slices.Contains(UserSettingMemoVisibilityValue, memoVisibilityValue) {
|
if !slices.Contains(UserSettingMemoVisibilityValue, memoVisibilityValue) {
|
||||||
return fmt.Errorf("invalid user setting memo visibility value")
|
return fmt.Errorf("invalid user setting memo visibility value")
|
||||||
}
|
}
|
||||||
} else if upsert.Key == UserSettingResourceVisibilityKey {
|
|
||||||
resourceVisibilityValue := Private
|
|
||||||
err := json.Unmarshal([]byte(upsert.Value), &resourceVisibilityValue)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to unmarshal user setting resource visibility value")
|
|
||||||
}
|
|
||||||
if !slices.Contains(UserSettingResourceVisibilityValue, resourceVisibilityValue) {
|
|
||||||
return fmt.Errorf("invalid user setting resource visibility value")
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
return fmt.Errorf("invalid user setting key")
|
return fmt.Errorf("invalid user setting key")
|
||||||
}
|
}
|
||||||
|
@@ -12,7 +12,7 @@ import (
|
|||||||
var Version = "0.11.2"
|
var Version = "0.11.2"
|
||||||
|
|
||||||
// DevVersion is the service current development version.
|
// DevVersion is the service current development version.
|
||||||
var DevVersion = "0.11.2"
|
var DevVersion = "0.12.0"
|
||||||
|
|
||||||
func GetCurrentVersion(mode string) string {
|
func GetCurrentVersion(mode string) string {
|
||||||
if mode == "dev" || mode == "demo" {
|
if mode == "dev" || mode == "demo" {
|
||||||
|
15
store/db/migration/prod/0.12/00__user_setting.sql
Normal file
15
store/db/migration/prod/0.12/00__user_setting.sql
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
INSERT INTO
|
||||||
|
user_setting (user_id, key, value)
|
||||||
|
SELECT
|
||||||
|
user_id,
|
||||||
|
'memo-visibility',
|
||||||
|
value
|
||||||
|
FROM
|
||||||
|
user_setting
|
||||||
|
WHERE
|
||||||
|
key = 'memoVisibility';
|
||||||
|
|
||||||
|
DELETE FROM
|
||||||
|
user_setting
|
||||||
|
WHERE
|
||||||
|
key = 'memoVisibility';
|
@@ -33,11 +33,7 @@ const PreferencesSection = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleDefaultMemoVisibilityChanged = async (value: string) => {
|
const handleDefaultMemoVisibilityChanged = async (value: string) => {
|
||||||
await userStore.upsertUserSetting("memoVisibility", value);
|
await userStore.upsertUserSetting("memo-visibility", value);
|
||||||
};
|
|
||||||
|
|
||||||
const handleDefaultResourceVisibilityChanged = async (value: string) => {
|
|
||||||
await userStore.upsertUserSetting("resourceVisibility", value);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDoubleClickEnabledChanged = (event: React.ChangeEvent<HTMLInputElement>) => {
|
const handleDoubleClickEnabledChanged = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
@@ -78,25 +74,6 @@ const PreferencesSection = () => {
|
|||||||
))}
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
<div className="form-label selector">
|
|
||||||
<span className="normal-text">{t("setting.preference-section.default-resource-visibility")}</span>
|
|
||||||
<Select
|
|
||||||
className="!min-w-[10rem] w-auto text-sm"
|
|
||||||
value={setting.resourceVisibility}
|
|
||||||
onChange={(_, visibility) => {
|
|
||||||
if (visibility) {
|
|
||||||
handleDefaultResourceVisibilityChanged(visibility);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{visibilitySelectorItems.map((item) => (
|
|
||||||
<Option key={item.value} value={item.value} className="whitespace-nowrap">
|
|
||||||
{item.text}
|
|
||||||
</Option>
|
|
||||||
))}
|
|
||||||
</Select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="form-label selector">
|
<div className="form-label selector">
|
||||||
<span className="normal-text">{t("setting.preference-section.daily-review-time-offset")}</span>
|
<span className="normal-text">{t("setting.preference-section.daily-review-time-offset")}</span>
|
||||||
<span className="w-auto inline-flex">
|
<span className="w-auto inline-flex">
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
import { camelCase } from "lodash-es";
|
||||||
import store, { useAppSelector } from "..";
|
import store, { useAppSelector } from "..";
|
||||||
import * as api from "../../helpers/api";
|
import * as api from "../../helpers/api";
|
||||||
import * as storage from "../../helpers/storage";
|
import * as storage from "../../helpers/storage";
|
||||||
@@ -10,7 +11,6 @@ const defaultSetting: Setting = {
|
|||||||
locale: "en",
|
locale: "en",
|
||||||
appearance: getSystemColorScheme(),
|
appearance: getSystemColorScheme(),
|
||||||
memoVisibility: "PRIVATE",
|
memoVisibility: "PRIVATE",
|
||||||
resourceVisibility: "PRIVATE",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const defaultLocalSetting: LocalSetting = {
|
const defaultLocalSetting: LocalSetting = {
|
||||||
@@ -30,7 +30,7 @@ export const convertResponseModelUser = (user: User): User => {
|
|||||||
|
|
||||||
if (user.userSettingList) {
|
if (user.userSettingList) {
|
||||||
for (const userSetting of user.userSettingList) {
|
for (const userSetting of user.userSettingList) {
|
||||||
(setting as any)[userSetting.key] = JSON.parse(userSetting.value);
|
(setting as any)[camelCase(userSetting.key)] = JSON.parse(userSetting.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,7 +120,7 @@ export const useUserStore = () => {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
upsertUserSetting: async (key: keyof Setting, value: any) => {
|
upsertUserSetting: async (key: string, value: any) => {
|
||||||
await api.upsertUserSetting({
|
await api.upsertUserSetting({
|
||||||
key: key as any,
|
key: key as any,
|
||||||
value: JSON.stringify(value),
|
value: JSON.stringify(value),
|
||||||
|
10
web/src/types/modules/setting.d.ts
vendored
10
web/src/types/modules/setting.d.ts
vendored
@@ -4,7 +4,6 @@ interface Setting {
|
|||||||
locale: Locale;
|
locale: Locale;
|
||||||
appearance: Appearance;
|
appearance: Appearance;
|
||||||
memoVisibility: Visibility;
|
memoVisibility: Visibility;
|
||||||
resourceVisibility: Visibility;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface LocalSetting {
|
interface LocalSetting {
|
||||||
@@ -23,16 +22,11 @@ interface UserAppearanceSetting {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface UserMemoVisibilitySetting {
|
interface UserMemoVisibilitySetting {
|
||||||
key: "memoVisibility";
|
key: "memo-visibility";
|
||||||
value: Visibility;
|
value: Visibility;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface UserResourceVisibilitySetting {
|
type UserSetting = UserLocaleSetting | UserAppearanceSetting | UserMemoVisibilitySetting;
|
||||||
key: "resourceVisibility";
|
|
||||||
value: Visibility;
|
|
||||||
}
|
|
||||||
|
|
||||||
type UserSetting = UserLocaleSetting | UserAppearanceSetting | UserMemoVisibilitySetting | UserResourceVisibilitySetting;
|
|
||||||
|
|
||||||
interface UserSettingUpsert {
|
interface UserSettingUpsert {
|
||||||
key: keyof Setting;
|
key: keyof Setting;
|
||||||
|
Reference in New Issue
Block a user