Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
products_lesson_front
Project
Project
Details
Activity
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
Pavel Mishakov
products_lesson_front
Commits
f6961248
Commit
f6961248
authored
Apr 04, 2023
by
Pavel Mishakov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
93 done FRONT
parent
a124cb34
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
8 deletions
+26
-8
IUser.ts
src/interfaces/IUser.ts
+1
-0
IUserGetDto.ts
src/interfaces/IUserGetDto.ts
+5
-4
products.slice.ts
src/store/products/products.slice.ts
+1
-1
store.ts
src/store/store.ts
+19
-3
No files found.
src/interfaces/IUser.ts
View file @
f6961248
...
...
@@ -4,4 +4,5 @@ export default interface IUser {
password
:
string
active
:
boolean
token
:
string
role
:
string
}
\ No newline at end of file
src/interfaces/IUserGetDto.ts
View file @
f6961248
import
IU
S
er
from
"./IUser"
;
import
IU
s
er
from
"./IUser"
;
export
default
interface
IUserGetDto
{
_id
:
IUSer
[
'_id'
]
username
:
IUSer
[
'username'
]
token
:
IUSer
[
'token'
]
_id
:
IUser
[
'_id'
]
username
:
IUser
[
'username'
]
token
:
IUser
[
'token'
]
role
:
IUser
[
'role'
]
}
\ No newline at end of file
src/store/products/products.slice.ts
View file @
f6961248
...
...
@@ -55,7 +55,7 @@ export const productsSlice = createSlice({
})
.
addCase
(
getProducts
.
fulfilled
,
(
state
,
action
)
=>
{
state
.
loadingProducts
=
false
state
.
products
=
action
.
payload
.
result
as
IProduct
[]
state
.
products
=
action
.
payload
.
result
as
IProduct
[]
||
[]
state
.
messageProducts
=
action
.
payload
.
message
})
.
addCase
(
getProductById
.
rejected
,
(
state
)
=>
{
...
...
src/store/store.ts
View file @
f6961248
import
{
configureStore
,
ThunkAction
,
Action
}
from
"@reduxjs/toolkit"
import
{
configureStore
,
ThunkAction
,
Action
,
getDefaultMiddleware
}
from
"@reduxjs/toolkit"
import
{
useDispatch
}
from
'react-redux'
import
{
productsSlice
}
from
"./products/products.slice"
import
{
usersSlice
}
from
"./users/users.slice"
const
localStorageMiddleware
=
({
getState
}:
any
)
=>
{
return
(
next
:
any
)
=>
(
action
:
any
)
=>
{
const
result
=
next
(
action
);
localStorage
.
setItem
(
'applicationState'
,
JSON
.
stringify
(
getState
()));
return
result
;
};
};
const
reHydrateStore
=
()
=>
{
if
(
localStorage
.
getItem
(
'applicationState'
)
!==
null
)
{
return
JSON
.
parse
(
localStorage
.
getItem
(
'applicationState'
)
||
''
);
// re-hydrate the store
}
};
const
makeStore
=
()
=>
{
return
configureStore
({
reducer
:
{
products
:
productsSlice
.
reducer
,
users
:
usersSlice
.
reducer
}
},
preloadedState
:
reHydrateStore
(),
middleware
:
(
mw
)
=>
mw
().
concat
(
localStorageMiddleware
)
})
}
export
const
store
=
makeStore
()
const
store
=
makeStore
()
export
type
AppDispatch
=
typeof
store
.
dispatch
;
export
type
AppStore
=
ReturnType
<
typeof
makeStore
>
;
export
type
AppState
=
ReturnType
<
AppStore
[
"getState"
]
>
;
...
...
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