Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
8a332907
Unverified
Commit
8a332907
authored
Apr 03, 2023
by
boojack
Committed by
GitHub
Apr 03, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: update user setting key convention (#1447)
* chore: update user settng key convention * chore: update
parent
11cd9b21
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
27 additions
and
55 deletions
+27
-55
user_setting.go
api/user_setting.go
+5
-19
version.go
server/version/version.go
+1
-1
00__user_setting.sql
store/db/migration/prod/0.12/00__user_setting.sql
+15
-0
PreferencesSection.tsx
web/src/components/Settings/PreferencesSection.tsx
+1
-24
user.ts
web/src/store/module/user.ts
+3
-3
setting.d.ts
web/src/types/modules/setting.d.ts
+2
-8
No files found.
api/user_setting.go
View file @
8a332907
...
...
@@ -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,18 +26,15 @@ func (key UserSettingKey) String() string {
case
UserSettingAppearanceKey
:
return
"appearance"
case
UserSettingMemoVisibilityKey
:
return
"memoVisibility"
case
UserSettingResourceVisibilityKey
:
return
"resourceVisibility"
return
"memo-visibility"
}
return
""
}
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
}
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
}
)
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"
)
}
...
...
server/version/version.go
View file @
8a332907
...
...
@@ -12,7 +12,7 @@ import (
var
Version
=
"0.11.2"
// DevVersion is the service current development version.
var
DevVersion
=
"0.1
1.2
"
var
DevVersion
=
"0.1
2.0
"
func
GetCurrentVersion
(
mode
string
)
string
{
if
mode
==
"dev"
||
mode
==
"demo"
{
...
...
store/db/migration/prod/0.12/00__user_setting.sql
0 → 100644
View file @
8a332907
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'
;
\ No newline at end of file
web/src/components/Settings/PreferencesSection.tsx
View file @
8a332907
...
...
@@ -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"
>
...
...
web/src/store/module/user.ts
View file @
8a332907
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
Sett
ing
,
value
:
any
)
=>
{
upsertUserSetting
:
async
(
key
:
str
ing
,
value
:
any
)
=>
{
await
api
.
upsertUserSetting
({
key
:
key
as
any
,
value
:
JSON
.
stringify
(
value
),
...
...
web/src/types/modules/setting.d.ts
View file @
8a332907
...
...
@@ -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
:
"memo
V
isibility"
;
key
:
"memo
-v
isibility"
;
value
:
Visibility
;
}
interface
UserResourceVisibilitySetting
{
key
:
"resourceVisibility"
;
value
:
Visibility
;
}
type
UserSetting
=
UserLocaleSetting
|
UserAppearanceSetting
|
UserMemoVisibilitySetting
|
UserResourceVisibilitySetting
;
type
UserSetting
=
UserLocaleSetting
|
UserAppearanceSetting
|
UserMemoVisibilitySetting
;
interface
UserSettingUpsert
{
key
:
keyof
Setting
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment