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
a0667abe
Unverified
Commit
a0667abe
authored
Nov 22, 2022
by
boojack
Committed by
GitHub
Nov 22, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: update data initial requests (#538)
parent
362306a9
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
111 additions
and
135 deletions
+111
-135
system.go
api/system.go
+3
-3
system.go
server/system.go
+1
-1
App.tsx
web/src/App.tsx
+17
-23
AboutSiteDialog.tsx
web/src/components/AboutSiteDialog.tsx
+9
-28
MemoFilter.tsx
web/src/components/MemoFilter.tsx
+1
-0
UpdateVersionBanner.tsx
web/src/components/UpdateVersionBanner.tsx
+11
-22
Auth.tsx
web/src/pages/Auth.tsx
+25
-43
index.tsx
web/src/router/index.tsx
+12
-1
globalService.ts
web/src/services/globalService.ts
+8
-6
userService.ts
web/src/services/userService.ts
+8
-6
global.ts
web/src/store/modules/global.ts
+15
-1
system.d.ts
web/src/types/modules/system.d.ts
+1
-1
No files found.
api/system.go
View file @
a0667abe
...
@@ -3,9 +3,9 @@ package api
...
@@ -3,9 +3,9 @@ package api
import
"github.com/usememos/memos/server/profile"
import
"github.com/usememos/memos/server/profile"
type
SystemStatus
struct
{
type
SystemStatus
struct
{
Host
*
User
`json:"host"`
Host
*
User
`json:"host"`
Profile
*
profile
.
Profile
`json:"profile"`
Profile
profile
.
Profile
`json:"profile"`
DBSize
int64
`json:"dbSize"`
DBSize
int64
`json:"dbSize"`
// System settings
// System settings
// Allow sign up.
// Allow sign up.
...
...
server/system.go
View file @
a0667abe
...
@@ -41,7 +41,7 @@ func (s *Server) registerSystemRoutes(g *echo.Group) {
...
@@ -41,7 +41,7 @@ func (s *Server) registerSystemRoutes(g *echo.Group) {
systemStatus
:=
api
.
SystemStatus
{
systemStatus
:=
api
.
SystemStatus
{
Host
:
hostUser
,
Host
:
hostUser
,
Profile
:
s
.
Profile
,
Profile
:
*
s
.
Profile
,
DBSize
:
0
,
DBSize
:
0
,
AllowSignUp
:
false
,
AllowSignUp
:
false
,
AdditionalStyle
:
""
,
AdditionalStyle
:
""
,
...
...
web/src/App.tsx
View file @
a0667abe
...
@@ -2,49 +2,43 @@ import { CssVarsProvider } from "@mui/joy/styles";
...
@@ -2,49 +2,43 @@ import { CssVarsProvider } from "@mui/joy/styles";
import
{
useEffect
}
from
"react"
;
import
{
useEffect
}
from
"react"
;
import
{
useTranslation
}
from
"react-i18next"
;
import
{
useTranslation
}
from
"react-i18next"
;
import
{
RouterProvider
}
from
"react-router-dom"
;
import
{
RouterProvider
}
from
"react-router-dom"
;
import
{
globalService
,
locationService
}
from
"./services"
;
import
{
locationService
}
from
"./services"
;
import
{
useAppSelector
}
from
"./store"
;
import
{
useAppSelector
}
from
"./store"
;
import
router
from
"./router"
;
import
router
from
"./router"
;
import
*
as
api
from
"./helpers/api"
;
import
*
as
storage
from
"./helpers/storage"
;
import
*
as
storage
from
"./helpers/storage"
;
function
App
()
{
function
App
()
{
const
{
i18n
}
=
useTranslation
();
const
{
i18n
}
=
useTranslation
();
const
global
=
useAppSelector
((
state
)
=>
state
.
global
);
const
{
locale
,
systemStatus
}
=
useAppSelector
((
state
)
=>
state
.
global
);
useEffect
(()
=>
{
useEffect
(()
=>
{
locationService
.
updateStateWithLocation
();
locationService
.
updateStateWithLocation
();
window
.
onpopstate
=
()
=>
{
window
.
onpopstate
=
()
=>
{
locationService
.
updateStateWithLocation
();
locationService
.
updateStateWithLocation
();
};
};
globalService
.
initialState
();
},
[]);
},
[]);
// Inject additional style and script codes.
// Inject additional style and script codes.
useEffect
(()
=>
{
useEffect
(()
=>
{
api
.
getSystemStatus
().
then
(({
data
})
=>
{
if
(
systemStatus
.
additionalStyle
)
{
const
{
data
:
status
}
=
data
;
const
styleEl
=
document
.
createElement
(
"style"
);
if
(
status
.
additionalStyle
)
{
styleEl
.
innerHTML
=
systemStatus
.
additionalStyle
;
const
styleEl
=
document
.
createElement
(
"style"
);
styleEl
.
setAttribute
(
"type"
,
"text/css"
);
styleEl
.
innerHTML
=
status
.
additionalStyle
;
document
.
head
.
appendChild
(
styleEl
);
styleEl
.
setAttribute
(
"type"
,
"text/css"
);
}
document
.
head
.
appendChild
(
styleEl
);
if
(
systemStatus
.
additionalScript
)
{
}
const
scriptEl
=
document
.
createElement
(
"script"
);
if
(
status
.
additionalScript
)
{
scriptEl
.
innerHTML
=
systemStatus
.
additionalScript
;
const
scriptEl
=
document
.
createElement
(
"script"
);
document
.
head
.
appendChild
(
scriptEl
);
scriptEl
.
innerHTML
=
status
.
additionalScript
;
}
document
.
head
.
appendChild
(
scriptEl
);
},
[
systemStatus
]);
}
});
},
[]);
useEffect
(()
=>
{
useEffect
(()
=>
{
i18n
.
changeLanguage
(
global
.
locale
);
i18n
.
changeLanguage
(
locale
);
storage
.
set
({
storage
.
set
({
locale
:
global
.
locale
,
locale
:
locale
,
});
});
},
[
global
.
locale
]);
},
[
locale
]);
return
(
return
(
<
CssVarsProvider
>
<
CssVarsProvider
>
...
...
web/src/components/AboutSiteDialog.tsx
View file @
a0667abe
import
{
useEffect
,
useState
}
from
"react"
;
import
{
useTranslation
}
from
"react-i18next"
;
import
{
useTranslation
}
from
"react-i18next"
;
import
*
as
api
from
"../helpers/api
"
;
import
{
useAppSelector
}
from
"../store
"
;
import
Icon
from
"./Icon"
;
import
Icon
from
"./Icon"
;
import
{
generateDialog
}
from
"./Dialog"
;
import
{
generateDialog
}
from
"./Dialog"
;
import
GitHubBadge
from
"./GitHubBadge"
;
import
GitHubBadge
from
"./GitHubBadge"
;
...
@@ -10,23 +9,7 @@ type Props = DialogProps;
...
@@ -10,23 +9,7 @@ type Props = DialogProps;
const
AboutSiteDialog
:
React
.
FC
<
Props
>
=
({
destroy
}:
Props
)
=>
{
const
AboutSiteDialog
:
React
.
FC
<
Props
>
=
({
destroy
}:
Props
)
=>
{
const
{
t
}
=
useTranslation
();
const
{
t
}
=
useTranslation
();
const
[
profile
,
setProfile
]
=
useState
<
Profile
>
();
const
profile
=
useAppSelector
((
state
)
=>
state
.
global
.
systemStatus
.
profile
);
useEffect
(()
=>
{
try
{
api
.
getSystemStatus
().
then
(({
data
})
=>
{
const
{
data
:
{
profile
},
}
=
data
;
setProfile
(
profile
);
});
}
catch
(
error
)
{
setProfile
({
mode
:
"dev"
,
version
:
"0.0.0"
,
});
}
},
[]);
const
handleCloseBtnClick
=
()
=>
{
const
handleCloseBtnClick
=
()
=>
{
destroy
();
destroy
();
...
@@ -49,15 +32,13 @@ const AboutSiteDialog: React.FC<Props> = ({ destroy }: Props) => {
...
@@ -49,15 +32,13 @@ const AboutSiteDialog: React.FC<Props> = ({ destroy }: Props) => {
<
br
/>
<
br
/>
<
div
className=
"addtion-info-container"
>
<
div
className=
"addtion-info-container"
>
<
GitHubBadge
/>
<
GitHubBadge
/>
{
profile
!==
undefined
&&
(
<>
<>
{
t
(
"common.version"
)
}
:
{
t
(
"common.version"
)
}
:
<
span
className=
"pre-text"
>
<
span
className=
"pre-text"
>
{
profile
.
version
}
-
{
profile
.
mode
}
{
profile
?.
version
}
-
{
profile
?.
mode
}
</
span
>
</
span
>
🎉
🎉
</>
</>
)
}
</
div
>
</
div
>
</
div
>
</
div
>
</>
</>
...
...
web/src/components/MemoFilter.tsx
View file @
a0667abe
...
@@ -8,6 +8,7 @@ import "../less/memo-filter.less";
...
@@ -8,6 +8,7 @@ import "../less/memo-filter.less";
const
MemoFilter
=
()
=>
{
const
MemoFilter
=
()
=>
{
const
{
t
}
=
useTranslation
();
const
{
t
}
=
useTranslation
();
useAppSelector
((
state
)
=>
state
.
shortcut
.
shortcuts
);
const
query
=
useAppSelector
((
state
)
=>
state
.
location
.
query
);
const
query
=
useAppSelector
((
state
)
=>
state
.
location
.
query
);
const
{
tag
:
tagQuery
,
duration
,
type
:
memoType
,
text
:
textQuery
,
shortcutId
,
visibility
}
=
query
;
const
{
tag
:
tagQuery
,
duration
,
type
:
memoType
,
text
:
textQuery
,
shortcutId
,
visibility
}
=
query
;
const
shortcut
=
shortcutId
?
shortcutService
.
getShortcutById
(
shortcutId
)
:
null
;
const
shortcut
=
shortcutId
?
shortcutService
.
getShortcutById
(
shortcutId
)
:
null
;
...
...
web/src/components/UpdateVersionBanner.tsx
View file @
a0667abe
import
{
useEffect
,
useState
}
from
"react"
;
import
{
useEffect
,
useState
}
from
"react"
;
import
{
useAppSelector
}
from
"../store"
;
import
*
as
api
from
"../helpers/api"
;
import
*
as
api
from
"../helpers/api"
;
import
*
as
storage
from
"../helpers/storage"
;
import
*
as
storage
from
"../helpers/storage"
;
import
Icon
from
"./Icon"
;
import
Icon
from
"./Icon"
;
...
@@ -10,35 +11,23 @@ interface State {
...
@@ -10,35 +11,23 @@ interface State {
}
}
const
UpdateVersionBanner
:
React
.
FC
=
()
=>
{
const
UpdateVersionBanner
:
React
.
FC
=
()
=>
{
const
profile
=
useAppSelector
((
state
)
=>
state
.
global
.
systemStatus
.
profile
);
const
[
state
,
setState
]
=
useState
<
State
>
({
const
[
state
,
setState
]
=
useState
<
State
>
({
latestVersion
:
""
,
latestVersion
:
""
,
show
:
false
,
show
:
false
,
});
});
useEffect
(()
=>
{
useEffect
(()
=>
{
Promise
.
all
([
api
.
getRepoLatestTag
(),
api
.
getSystemStatus
()])
api
.
getRepoLatestTag
().
then
((
latestTag
)
=>
{
.
then
(
const
{
skippedVersion
}
=
storage
.
get
([
"skippedVersion"
]);
([
const
latestVersion
=
latestTag
.
slice
(
1
)
||
"0.0.0"
;
latestTag
,
const
currentVersion
=
profile
.
version
;
{
const
skipped
=
skippedVersion
?
skippedVersion
===
latestVersion
:
false
;
data
:
{
setState
({
data
:
{
profile
},
latestVersion
,
},
show
:
!
skipped
&&
currentVersion
<
latestVersion
,
},
])
=>
{
const
{
skippedVersion
}
=
storage
.
get
([
"skippedVersion"
]);
const
latestVersion
=
latestTag
.
slice
(
1
)
||
"0.0.0"
;
const
currentVersion
=
profile
.
version
;
const
skipped
=
skippedVersion
?
skippedVersion
===
latestVersion
:
false
;
setState
({
latestVersion
,
show
:
!
skipped
&&
currentVersion
<
latestVersion
,
});
}
)
.
catch
(()
=>
{
// do nth
});
});
});
},
[]);
},
[]);
const
onSkip
=
()
=>
{
const
onSkip
=
()
=>
{
...
...
web/src/pages/Auth.tsx
View file @
a0667abe
import
{
use
Effect
,
use
State
}
from
"react"
;
import
{
useState
}
from
"react"
;
import
{
useTranslation
}
from
"react-i18next"
;
import
{
useTranslation
}
from
"react-i18next"
;
import
{
useNavigate
}
from
"react-router-dom"
;
import
{
useNavigate
}
from
"react-router-dom"
;
import
{
useAppSelector
}
from
"../store"
;
import
*
as
api
from
"../helpers/api"
;
import
*
as
api
from
"../helpers/api"
;
import
{
validate
,
ValidatorConfig
}
from
"../helpers/validator"
;
import
{
validate
,
ValidatorConfig
}
from
"../helpers/validator"
;
import
useLoading
from
"../hooks/useLoading"
;
import
useLoading
from
"../hooks/useLoading"
;
...
@@ -19,23 +20,11 @@ const validateConfig: ValidatorConfig = {
...
@@ -19,23 +20,11 @@ const validateConfig: ValidatorConfig = {
const
Auth
=
()
=>
{
const
Auth
=
()
=>
{
const
{
t
,
i18n
}
=
useTranslation
();
const
{
t
,
i18n
}
=
useTranslation
();
const
navigate
=
useNavigate
();
const
navigate
=
useNavigate
();
const
pageLoadingState
=
useLoading
(
true
);
const
systemStatus
=
useAppSelector
((
state
)
=>
state
.
global
.
systemStatus
);
const
[
systemStatus
,
setSystemStatus
]
=
useState
<
SystemStatus
>
();
const
[
email
,
setEmail
]
=
useState
(
""
);
const
[
password
,
setPassword
]
=
useState
(
""
);
const
actionBtnLoadingState
=
useLoading
(
false
);
const
actionBtnLoadingState
=
useLoading
(
false
);
const
mode
=
systemStatus
.
profile
.
mode
;
useEffect
(()
=>
{
const
[
email
,
setEmail
]
=
useState
(
mode
===
"dev"
?
"demo@usememos.com"
:
""
);
api
.
getSystemStatus
().
then
(({
data
})
=>
{
const
[
password
,
setPassword
]
=
useState
(
mode
===
"dev"
?
"secret"
:
""
);
const
{
data
:
status
}
=
data
;
setSystemStatus
(
status
);
if
(
status
.
profile
.
mode
===
"dev"
)
{
setEmail
(
"demo@usememos.com"
);
setPassword
(
"secret"
);
}
pageLoadingState
.
setFinish
();
});
},
[]);
const
handleEmailInputChanged
=
(
e
:
React
.
ChangeEvent
<
HTMLInputElement
>
)
=>
{
const
handleEmailInputChanged
=
(
e
:
React
.
ChangeEvent
<
HTMLInputElement
>
)
=>
{
const
text
=
e
.
target
.
value
as
string
;
const
text
=
e
.
target
.
value
as
string
;
...
@@ -138,39 +127,32 @@ const Auth = () => {
...
@@ -138,39 +127,32 @@ const Auth = () => {
</
div
>
</
div
>
</
div
>
</
div
>
<
div
className=
"action-btns-container"
>
<
div
className=
"action-btns-container"
>
{
!
pageLoadingState
.
isLoading
&&
(
{
systemStatus
?.
host
?
(
<>
<>
{
systemStatus
?.
host
?
(
{
actionBtnLoadingState
.
isLoading
&&
<
Icon
.
Loader
className=
"w-4 h-auto animate-spin"
/>
}
{
systemStatus
?.
allowSignUp
&&
(
<>
<>
{
actionBtnLoadingState
.
isLoading
&&
<
Icon
.
Loader
className=
"w-4 h-auto animate-spin"
/>
}
{
systemStatus
?.
allowSignUp
&&
(
<>
<
button
className=
{
`btn signup-btn ${actionBtnLoadingState.isLoading ? "requesting" : ""}`
}
onClick=
{
()
=>
handleSignUpBtnsClick
(
"USER"
)
}
>
{
t
(
"common.sign-up"
)
}
</
button
>
<
span
className=
"mr-2 font-mono text-gray-200"
>
/
</
span
>
</>
)
}
<
button
<
button
className=
{
`btn sign
in
-btn ${actionBtnLoadingState.isLoading ? "requesting" : ""}`
}
className=
{
`btn sign
up
-btn ${actionBtnLoadingState.isLoading ? "requesting" : ""}`
}
onClick=
{
handleSigninBtnsClick
}
onClick=
{
()
=>
handleSignUpBtnsClick
(
"USER"
)
}
>
>
{
t
(
"common.sign-in"
)
}
{
t
(
"common.sign-up"
)
}
</
button
>
</>
)
:
(
<>
<
button
className=
{
`btn signin-btn ${actionBtnLoadingState.isLoading ? "requesting" : ""}`
}
onClick=
{
()
=>
handleSignUpBtnsClick
(
"HOST"
)
}
>
{
t
(
"auth.signup-as-host"
)
}
</
button
>
</
button
>
<
span
className=
"mr-2 font-mono text-gray-200"
>
/
</
span
>
</>
</>
)
}
)
}
<
button
className=
{
`btn signin-btn ${actionBtnLoadingState.isLoading ? "requesting" : ""}`
}
onClick=
{
handleSigninBtnsClick
}
>
{
t
(
"common.sign-in"
)
}
</
button
>
</>
)
:
(
<>
<
button
className=
{
`btn signin-btn ${actionBtnLoadingState.isLoading ? "requesting" : ""}`
}
onClick=
{
()
=>
handleSignUpBtnsClick
(
"HOST"
)
}
>
{
t
(
"auth.signup-as-host"
)
}
</
button
>
</>
</>
)
}
)
}
</
div
>
</
div
>
...
...
web/src/router/index.tsx
View file @
a0667abe
import
{
createBrowserRouter
,
redirect
}
from
"react-router-dom"
;
import
{
createBrowserRouter
,
redirect
}
from
"react-router-dom"
;
import
{
isNullorUndefined
}
from
"../helpers/utils"
;
import
{
isNullorUndefined
}
from
"../helpers/utils"
;
import
{
userService
}
from
"../services"
;
import
{
globalService
,
userService
}
from
"../services"
;
import
Auth
from
"../pages/Auth"
;
import
Auth
from
"../pages/Auth"
;
import
Explore
from
"../pages/Explore"
;
import
Explore
from
"../pages/Explore"
;
import
Home
from
"../pages/Home"
;
import
Home
from
"../pages/Home"
;
...
@@ -10,12 +10,20 @@ const router = createBrowserRouter([
...
@@ -10,12 +10,20 @@ const router = createBrowserRouter([
{
{
path
:
"/auth"
,
path
:
"/auth"
,
element
:
<
Auth
/>,
element
:
<
Auth
/>,
loader
:
async
()
=>
{
try
{
await
globalService
.
initialState
();
}
catch
(
error
)
{
// do nth
}
},
},
},
{
{
path
:
"/"
,
path
:
"/"
,
element
:
<
Home
/>,
element
:
<
Home
/>,
loader
:
async
()
=>
{
loader
:
async
()
=>
{
try
{
try
{
await
globalService
.
initialState
();
await
userService
.
initialState
();
await
userService
.
initialState
();
}
catch
(
error
)
{
}
catch
(
error
)
{
// do nth
// do nth
...
@@ -34,6 +42,7 @@ const router = createBrowserRouter([
...
@@ -34,6 +42,7 @@ const router = createBrowserRouter([
element
:
<
Home
/>,
element
:
<
Home
/>,
loader
:
async
()
=>
{
loader
:
async
()
=>
{
try
{
try
{
await
globalService
.
initialState
();
await
userService
.
initialState
();
await
userService
.
initialState
();
}
catch
(
error
)
{
}
catch
(
error
)
{
// do nth
// do nth
...
@@ -50,6 +59,7 @@ const router = createBrowserRouter([
...
@@ -50,6 +59,7 @@ const router = createBrowserRouter([
element
:
<
Explore
/>,
element
:
<
Explore
/>,
loader
:
async
()
=>
{
loader
:
async
()
=>
{
try
{
try
{
await
globalService
.
initialState
();
await
userService
.
initialState
();
await
userService
.
initialState
();
}
catch
(
error
)
{
}
catch
(
error
)
{
// do nth
// do nth
...
@@ -66,6 +76,7 @@ const router = createBrowserRouter([
...
@@ -66,6 +76,7 @@ const router = createBrowserRouter([
element
:
<
MemoDetail
/>,
element
:
<
MemoDetail
/>,
loader
:
async
()
=>
{
loader
:
async
()
=>
{
try
{
try
{
await
globalService
.
initialState
();
await
userService
.
initialState
();
await
userService
.
initialState
();
}
catch
(
error
)
{
}
catch
(
error
)
{
// do nth
// do nth
...
...
web/src/services/globalService.ts
View file @
a0667abe
...
@@ -2,7 +2,6 @@ import store from "../store";
...
@@ -2,7 +2,6 @@ import store from "../store";
import
*
as
api
from
"../helpers/api"
;
import
*
as
api
from
"../helpers/api"
;
import
*
as
storage
from
"../helpers/storage"
;
import
*
as
storage
from
"../helpers/storage"
;
import
{
setGlobalState
,
setLocale
}
from
"../store/modules/global"
;
import
{
setGlobalState
,
setLocale
}
from
"../store/modules/global"
;
import
{
convertResponseModelUser
}
from
"./userService"
;
const
globalService
=
{
const
globalService
=
{
getState
:
()
=>
{
getState
:
()
=>
{
...
@@ -12,19 +11,22 @@ const globalService = {
...
@@ -12,19 +11,22 @@ const globalService = {
initialState
:
async
()
=>
{
initialState
:
async
()
=>
{
const
defaultGlobalState
=
{
const
defaultGlobalState
=
{
locale
:
"en"
as
Locale
,
locale
:
"en"
as
Locale
,
systemStatus
:
{
allowSignUp
:
false
,
additionalStyle
:
""
,
additionalScript
:
""
,
}
as
SystemStatus
,
};
};
const
{
locale
:
storageLocale
}
=
storage
.
get
([
"locale"
]);
const
{
locale
:
storageLocale
}
=
storage
.
get
([
"locale"
]);
if
(
storageLocale
)
{
if
(
storageLocale
)
{
defaultGlobalState
.
locale
=
storageLocale
;
defaultGlobalState
.
locale
=
storageLocale
;
}
}
try
{
try
{
const
{
data
}
=
(
await
api
.
get
MyselfUser
()).
data
;
const
{
data
}
=
(
await
api
.
get
SystemStatus
()).
data
;
if
(
data
)
{
if
(
data
)
{
const
user
=
convertResponseModelUser
(
data
);
defaultGlobalState
.
systemStatus
=
data
;
if
(
user
.
setting
.
locale
)
{
defaultGlobalState
.
locale
=
user
.
setting
.
locale
;
}
}
}
}
catch
(
error
)
{
}
catch
(
error
)
{
// do nth
// do nth
...
...
web/src/services/userService.ts
View file @
a0667abe
import
{
locationService
}
from
"."
;
import
{
globalService
,
locationService
}
from
"."
;
import
*
as
api
from
"../helpers/api"
;
import
*
as
api
from
"../helpers/api"
;
import
{
UNKNOWN_ID
}
from
"../helpers/consts"
;
import
{
UNKNOWN_ID
}
from
"../helpers/consts"
;
import
store
from
"../store"
;
import
store
from
"../store"
;
import
{
setLocale
}
from
"../store/modules/global"
;
import
{
setUser
,
patchUser
,
setHost
,
setOwner
}
from
"../store/modules/user"
;
import
{
setUser
,
patchUser
,
setHost
,
setOwner
}
from
"../store/modules/user"
;
const
defauleSetting
:
Setting
=
{
const
defauleSetting
:
Setting
=
{
...
@@ -35,11 +36,9 @@ const userService = {
...
@@ -35,11 +36,9 @@ const userService = {
},
},
initialState
:
async
()
=>
{
initialState
:
async
()
=>
{
const
{
const
{
systemStatus
}
=
globalService
.
getState
();
data
:
{
host
},
if
(
systemStatus
.
host
)
{
}
=
(
await
api
.
getSystemStatus
()).
data
;
store
.
dispatch
(
setHost
(
convertResponseModelUser
(
systemStatus
.
host
)));
if
(
host
)
{
store
.
dispatch
(
setHost
(
convertResponseModelUser
(
host
)));
}
}
const
ownerUserId
=
userService
.
getUserIdFromPath
();
const
ownerUserId
=
userService
.
getUserIdFromPath
();
...
@@ -53,6 +52,9 @@ const userService = {
...
@@ -53,6 +52,9 @@ const userService = {
const
{
data
:
user
}
=
(
await
api
.
getMyselfUser
()).
data
;
const
{
data
:
user
}
=
(
await
api
.
getMyselfUser
()).
data
;
if
(
user
)
{
if
(
user
)
{
store
.
dispatch
(
setUser
(
convertResponseModelUser
(
user
)));
store
.
dispatch
(
setUser
(
convertResponseModelUser
(
user
)));
if
(
user
.
setting
.
locale
)
{
store
.
dispatch
(
setLocale
(
user
.
setting
.
locale
));
}
}
}
},
},
...
...
web/src/store/modules/global.ts
View file @
a0667abe
...
@@ -2,11 +2,25 @@ import { createSlice, PayloadAction } from "@reduxjs/toolkit";
...
@@ -2,11 +2,25 @@ import { createSlice, PayloadAction } from "@reduxjs/toolkit";
interface
State
{
interface
State
{
locale
:
Locale
;
locale
:
Locale
;
systemStatus
:
SystemStatus
;
}
}
const
globalSlice
=
createSlice
({
const
globalSlice
=
createSlice
({
name
:
"global"
,
name
:
"global"
,
initialState
:
{}
as
State
,
initialState
:
{
locale
:
"en"
,
systemStatus
:
{
host
:
undefined
,
profile
:
{
mode
:
"dev"
,
version
:
""
,
},
dbSize
:
0
,
allowSignUp
:
false
,
additionalStyle
:
""
,
additionalScript
:
""
,
},
}
as
State
,
reducers
:
{
reducers
:
{
setGlobalState
:
(
_
,
action
:
PayloadAction
<
State
>
)
=>
{
setGlobalState
:
(
_
,
action
:
PayloadAction
<
State
>
)
=>
{
return
action
.
payload
;
return
action
.
payload
;
...
...
web/src/types/modules/system.d.ts
View file @
a0667abe
...
@@ -4,7 +4,7 @@ interface Profile {
...
@@ -4,7 +4,7 @@ interface Profile {
}
}
interface
SystemStatus
{
interface
SystemStatus
{
host
:
User
;
host
?
:
User
;
profile
:
Profile
;
profile
:
Profile
;
dbSize
:
number
;
dbSize
:
number
;
// System settings
// System settings
...
...
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