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 UserSettingKey = "appearance"
|
||||
// UserSettingMemoVisibilityKey is the key type for user preference memo default visibility.
|
||||
UserSettingMemoVisibilityKey UserSettingKey = "memoVisibility"
|
||||
// UserSettingResourceVisibilityKey is the key type for user preference resource default visibility.
|
||||
UserSettingResourceVisibilityKey UserSettingKey = "resourceVisibility"
|
||||
UserSettingMemoVisibilityKey UserSettingKey = "memo-visibility"
|
||||
)
|
||||
|
||||
// String returns the string format of UserSettingKey type.
|
||||
@@ -28,9 +26,7 @@ func (key UserSettingKey) String() string {
|
||||
case UserSettingAppearanceKey:
|
||||
return "appearance"
|
||||
case UserSettingMemoVisibilityKey:
|
||||
return "memoVisibility"
|
||||
case UserSettingResourceVisibilityKey:
|
||||
return "resourceVisibility"
|
||||
return "memo-visibility"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
@@ -39,7 +35,6 @@ var (
|
||||
UserSettingLocaleValue = []string{"en", "zh", "vi", "fr", "nl", "sv", "de", "es", "uk", "ru", "it", "hant", "tr", "ko", "sl"}
|
||||
UserSettingAppearanceValue = []string{"system", "light", "dark"}
|
||||
UserSettingMemoVisibilityValue = []Visibility{Private, Protected, Public}
|
||||
UserSettingResourceVisibilityValue = []Visibility{Private, Protected, Public}
|
||||
)
|
||||
|
||||
type UserSetting struct {
|
||||
@@ -83,15 +78,6 @@ func (upsert UserSettingUpsert) Validate() error {
|
||||
if !slices.Contains(UserSettingMemoVisibilityValue, memoVisibilityValue) {
|
||||
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 {
|
||||
return fmt.Errorf("invalid user setting key")
|
||||
}
|
||||
|
@@ -12,7 +12,7 @@ import (
|
||||
var Version = "0.11.2"
|
||||
|
||||
// DevVersion is the service current development version.
|
||||
var DevVersion = "0.11.2"
|
||||
var DevVersion = "0.12.0"
|
||||
|
||||
func GetCurrentVersion(mode string) string {
|
||||
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) => {
|
||||
await userStore.upsertUserSetting("memoVisibility", value);
|
||||
};
|
||||
|
||||
const handleDefaultResourceVisibilityChanged = async (value: string) => {
|
||||
await userStore.upsertUserSetting("resourceVisibility", value);
|
||||
await userStore.upsertUserSetting("memo-visibility", value);
|
||||
};
|
||||
|
||||
const handleDoubleClickEnabledChanged = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
@@ -78,25 +74,6 @@ const PreferencesSection = () => {
|
||||
))}
|
||||
</Select>
|
||||
</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">
|
||||
<span className="normal-text">{t("setting.preference-section.daily-review-time-offset")}</span>
|
||||
<span className="w-auto inline-flex">
|
||||
|
@@ -1,3 +1,4 @@
|
||||
import { camelCase } from "lodash-es";
|
||||
import store, { useAppSelector } from "..";
|
||||
import * as api from "../../helpers/api";
|
||||
import * as storage from "../../helpers/storage";
|
||||
@@ -10,7 +11,6 @@ const defaultSetting: Setting = {
|
||||
locale: "en",
|
||||
appearance: getSystemColorScheme(),
|
||||
memoVisibility: "PRIVATE",
|
||||
resourceVisibility: "PRIVATE",
|
||||
};
|
||||
|
||||
const defaultLocalSetting: LocalSetting = {
|
||||
@@ -30,7 +30,7 @@ export const convertResponseModelUser = (user: User): User => {
|
||||
|
||||
if (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;
|
||||
}
|
||||
},
|
||||
upsertUserSetting: async (key: keyof Setting, value: any) => {
|
||||
upsertUserSetting: async (key: string, value: any) => {
|
||||
await api.upsertUserSetting({
|
||||
key: key as any,
|
||||
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;
|
||||
appearance: Appearance;
|
||||
memoVisibility: Visibility;
|
||||
resourceVisibility: Visibility;
|
||||
}
|
||||
|
||||
interface LocalSetting {
|
||||
@@ -23,16 +22,11 @@ interface UserAppearanceSetting {
|
||||
}
|
||||
|
||||
interface UserMemoVisibilitySetting {
|
||||
key: "memoVisibility";
|
||||
key: "memo-visibility";
|
||||
value: Visibility;
|
||||
}
|
||||
|
||||
interface UserResourceVisibilitySetting {
|
||||
key: "resourceVisibility";
|
||||
value: Visibility;
|
||||
}
|
||||
|
||||
type UserSetting = UserLocaleSetting | UserAppearanceSetting | UserMemoVisibilitySetting | UserResourceVisibilitySetting;
|
||||
type UserSetting = UserLocaleSetting | UserAppearanceSetting | UserMemoVisibilitySetting;
|
||||
|
||||
interface UserSettingUpsert {
|
||||
key: keyof Setting;
|
||||
|
Reference in New Issue
Block a user