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
0dd23376
Commit
0dd23376
authored
Sep 21, 2022
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: update router
parent
d316c048
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
37 additions
and
39 deletions
+37
-39
Explore.tsx
web/src/pages/Explore.tsx
+2
-10
Home.tsx
web/src/pages/Home.tsx
+2
-13
MemoDetail.tsx
web/src/pages/MemoDetail.tsx
+2
-10
index.tsx
web/src/router/index.tsx
+28
-5
index.ts
web/src/store/index.ts
+3
-1
No files found.
web/src/pages/Explore.tsx
View file @
0dd23376
import
dayjs
from
"dayjs"
;
import
dayjs
from
"dayjs"
;
import
{
useEffect
,
useState
}
from
"react"
;
import
{
useEffect
,
useState
}
from
"react"
;
import
{
useTranslation
}
from
"react-i18next"
;
import
{
useTranslation
}
from
"react-i18next"
;
import
{
Link
,
useNavigate
}
from
"react-router-dom"
;
import
{
Link
}
from
"react-router-dom"
;
import
{
memoService
,
userService
}
from
"../services"
;
import
{
memoService
}
from
"../services"
;
import
{
isNullorUndefined
}
from
"../helpers/utils"
;
import
{
useAppSelector
}
from
"../store"
;
import
{
useAppSelector
}
from
"../store"
;
import
useLoading
from
"../hooks/useLoading"
;
import
useLoading
from
"../hooks/useLoading"
;
import
MemoContent
from
"../components/MemoContent"
;
import
MemoContent
from
"../components/MemoContent"
;
...
@@ -16,7 +15,6 @@ interface State {
...
@@ -16,7 +15,6 @@ interface State {
const
Explore
=
()
=>
{
const
Explore
=
()
=>
{
const
{
t
,
i18n
}
=
useTranslation
();
const
{
t
,
i18n
}
=
useTranslation
();
const
navigate
=
useNavigate
();
const
user
=
useAppSelector
((
state
)
=>
state
.
user
.
user
);
const
user
=
useAppSelector
((
state
)
=>
state
.
user
.
user
);
const
location
=
useAppSelector
((
state
)
=>
state
.
location
);
const
location
=
useAppSelector
((
state
)
=>
state
.
location
);
const
[
state
,
setState
]
=
useState
<
State
>
({
const
[
state
,
setState
]
=
useState
<
State
>
({
...
@@ -25,12 +23,6 @@ const Explore = () => {
...
@@ -25,12 +23,6 @@ const Explore = () => {
const
loadingState
=
useLoading
();
const
loadingState
=
useLoading
();
useEffect
(()
=>
{
useEffect
(()
=>
{
const
{
host
}
=
userService
.
getState
();
if
(
isNullorUndefined
(
host
))
{
navigate
(
"/auth"
);
return
;
}
memoService
.
fetchAllMemos
().
then
((
memos
)
=>
{
memoService
.
fetchAllMemos
().
then
((
memos
)
=>
{
setState
({
setState
({
memos
,
memos
,
...
...
web/src/pages/Home.tsx
View file @
0dd23376
import
{
useEffect
}
from
"react"
;
import
{
useEffect
}
from
"react"
;
import
{
useTranslation
}
from
"react-i18next"
;
import
{
useTranslation
}
from
"react-i18next"
;
import
{
useLocation
,
useNavigate
}
from
"react-router-dom"
;
import
{
useLocation
}
from
"react-router-dom"
;
import
{
globalService
,
userService
}
from
"../services"
;
import
{
globalService
,
userService
}
from
"../services"
;
import
{
useAppSelector
}
from
"../store"
;
import
{
useAppSelector
}
from
"../store"
;
import
{
isNullorUndefined
}
from
"../helpers/utils"
;
import
toastHelper
from
"../components/Toast"
;
import
toastHelper
from
"../components/Toast"
;
import
Sidebar
from
"../components/Sidebar"
;
import
Sidebar
from
"../components/Sidebar"
;
import
MemosHeader
from
"../components/MemosHeader"
;
import
MemosHeader
from
"../components/MemosHeader"
;
...
@@ -15,25 +14,15 @@ import "../less/home.less";
...
@@ -15,25 +14,15 @@ import "../less/home.less";
function
Home
()
{
function
Home
()
{
const
{
t
}
=
useTranslation
();
const
{
t
}
=
useTranslation
();
const
location
=
useLocation
();
const
location
=
useLocation
();
const
navigate
=
useNavigate
();
const
user
=
useAppSelector
((
state
)
=>
state
.
user
.
user
);
const
user
=
useAppSelector
((
state
)
=>
state
.
user
.
user
);
useEffect
(()
=>
{
useEffect
(()
=>
{
const
{
host
,
owner
,
user
}
=
userService
.
getState
();
const
{
owner
}
=
userService
.
getState
();
if
(
isNullorUndefined
(
host
))
{
navigate
(
"/auth"
);
return
;
}
if
(
userService
.
isVisitorMode
())
{
if
(
userService
.
isVisitorMode
())
{
if
(
!
owner
)
{
if
(
!
owner
)
{
toastHelper
.
error
(
t
(
"message.user-not-found"
));
toastHelper
.
error
(
t
(
"message.user-not-found"
));
}
}
}
else
{
if
(
isNullorUndefined
(
user
))
{
navigate
(
"/explore"
);
}
}
}
},
[
location
]);
},
[
location
]);
...
...
web/src/pages/MemoDetail.tsx
View file @
0dd23376
import
dayjs
from
"dayjs"
;
import
dayjs
from
"dayjs"
;
import
{
useEffect
,
useState
}
from
"react"
;
import
{
useEffect
,
useState
}
from
"react"
;
import
{
useTranslation
}
from
"react-i18next"
;
import
{
useTranslation
}
from
"react-i18next"
;
import
{
Link
,
use
Navigate
,
use
Params
}
from
"react-router-dom"
;
import
{
Link
,
useParams
}
from
"react-router-dom"
;
import
{
memoService
,
userService
}
from
"../services"
;
import
{
memoService
}
from
"../services"
;
import
{
UNKNOWN_ID
}
from
"../helpers/consts"
;
import
{
UNKNOWN_ID
}
from
"../helpers/consts"
;
import
{
isNullorUndefined
}
from
"../helpers/utils"
;
import
{
useAppSelector
}
from
"../store"
;
import
{
useAppSelector
}
from
"../store"
;
import
useLoading
from
"../hooks/useLoading"
;
import
useLoading
from
"../hooks/useLoading"
;
import
toastHelper
from
"../components/Toast"
;
import
toastHelper
from
"../components/Toast"
;
...
@@ -18,7 +17,6 @@ interface State {
...
@@ -18,7 +17,6 @@ interface State {
const
MemoDetail
=
()
=>
{
const
MemoDetail
=
()
=>
{
const
{
t
,
i18n
}
=
useTranslation
();
const
{
t
,
i18n
}
=
useTranslation
();
const
navigate
=
useNavigate
();
const
params
=
useParams
();
const
params
=
useParams
();
const
user
=
useAppSelector
((
state
)
=>
state
.
user
.
user
);
const
user
=
useAppSelector
((
state
)
=>
state
.
user
.
user
);
const
location
=
useAppSelector
((
state
)
=>
state
.
location
);
const
location
=
useAppSelector
((
state
)
=>
state
.
location
);
...
@@ -30,12 +28,6 @@ const MemoDetail = () => {
...
@@ -30,12 +28,6 @@ const MemoDetail = () => {
const
loadingState
=
useLoading
();
const
loadingState
=
useLoading
();
useEffect
(()
=>
{
useEffect
(()
=>
{
const
{
host
}
=
userService
.
getState
();
if
(
isNullorUndefined
(
host
))
{
navigate
(
"/auth"
);
return
;
}
const
memoId
=
Number
(
params
.
memoId
);
const
memoId
=
Number
(
params
.
memoId
);
if
(
memoId
&&
!
isNaN
(
memoId
))
{
if
(
memoId
&&
!
isNaN
(
memoId
))
{
memoService
memoService
...
...
web/src/router/index.tsx
View file @
0dd23376
import
{
createBrowserRouter
}
from
"react-router-dom"
;
import
{
createBrowserRouter
,
redirect
}
from
"react-router-dom"
;
import
{
isNullorUndefined
}
from
"../helpers/utils"
;
import
{
userService
}
from
"../services"
;
import
{
userService
}
from
"../services"
;
import
Auth
from
"../pages/Auth"
;
import
Auth
from
"../pages/Auth"
;
import
Explore
from
"../pages/Explore"
;
import
Explore
from
"../pages/Explore"
;
...
@@ -6,6 +7,10 @@ import Home from "../pages/Home";
...
@@ -6,6 +7,10 @@ import Home from "../pages/Home";
import
MemoDetail
from
"../pages/MemoDetail"
;
import
MemoDetail
from
"../pages/MemoDetail"
;
const
router
=
createBrowserRouter
([
const
router
=
createBrowserRouter
([
{
path
:
"/auth"
,
element
:
<
Auth
/>,
},
{
{
path
:
"/"
,
path
:
"/"
,
element
:
<
Home
/>,
element
:
<
Home
/>,
...
@@ -15,12 +20,15 @@ const router = createBrowserRouter([
...
@@ -15,12 +20,15 @@ const router = createBrowserRouter([
}
catch
(
error
)
{
}
catch
(
error
)
{
// do nth
// do nth
}
}
const
{
host
,
user
}
=
userService
.
getState
();
if
(
isNullorUndefined
(
host
))
{
return
redirect
(
"/auth"
);
}
else
if
(
isNullorUndefined
(
user
))
{
return
redirect
(
"/explore"
);
}
},
},
},
},
{
path
:
"/auth"
,
element
:
<
Auth
/>,
},
{
{
path
:
"/u/:userId"
,
path
:
"/u/:userId"
,
element
:
<
Home
/>,
element
:
<
Home
/>,
...
@@ -30,6 +38,11 @@ const router = createBrowserRouter([
...
@@ -30,6 +38,11 @@ const router = createBrowserRouter([
}
catch
(
error
)
{
}
catch
(
error
)
{
// do nth
// do nth
}
}
const
{
host
}
=
userService
.
getState
();
if
(
isNullorUndefined
(
host
))
{
return
redirect
(
"/auth"
);
}
},
},
},
},
{
{
...
@@ -41,6 +54,11 @@ const router = createBrowserRouter([
...
@@ -41,6 +54,11 @@ const router = createBrowserRouter([
}
catch
(
error
)
{
}
catch
(
error
)
{
// do nth
// do nth
}
}
const
{
host
}
=
userService
.
getState
();
if
(
isNullorUndefined
(
host
))
{
return
redirect
(
"/auth"
);
}
},
},
},
},
{
{
...
@@ -52,6 +70,11 @@ const router = createBrowserRouter([
...
@@ -52,6 +70,11 @@ const router = createBrowserRouter([
}
catch
(
error
)
{
}
catch
(
error
)
{
// do nth
// do nth
}
}
const
{
host
}
=
userService
.
getState
();
if
(
isNullorUndefined
(
host
))
{
return
redirect
(
"/auth"
);
}
},
},
},
},
]);
]);
...
...
web/src/store/index.ts
View file @
0dd23376
import
{
configureStore
}
from
"@reduxjs/toolkit"
;
import
{
configureStore
}
from
"@reduxjs/toolkit"
;
import
{
TypedUseSelectorHook
,
useSelector
}
from
"react-redux"
;
import
{
TypedUseSelectorHook
,
use
Dispatch
,
use
Selector
}
from
"react-redux"
;
import
globalReducer
from
"./modules/global"
;
import
globalReducer
from
"./modules/global"
;
import
userReducer
from
"./modules/user"
;
import
userReducer
from
"./modules/user"
;
import
memoReducer
from
"./modules/memo"
;
import
memoReducer
from
"./modules/memo"
;
...
@@ -19,7 +19,9 @@ const store = configureStore({
...
@@ -19,7 +19,9 @@ const store = configureStore({
});
});
type
AppState
=
ReturnType
<
typeof
store
.
getState
>
;
type
AppState
=
ReturnType
<
typeof
store
.
getState
>
;
type
AppDispatch
=
typeof
store
.
dispatch
;
export
const
useAppSelector
:
TypedUseSelectorHook
<
AppState
>
=
useSelector
;
export
const
useAppSelector
:
TypedUseSelectorHook
<
AppState
>
=
useSelector
;
export
const
useAppDispatch
:
()
=>
AppDispatch
=
useDispatch
;
export
default
store
;
export
default
store
;
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