Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
Newspaper Frontend
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
lap nguyen
Newspaper Frontend
Commits
f511a2a1
Commit
f511a2a1
authored
Nov 23, 2022
by
Ken
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fetch category api
parent
24ed1500
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
79 additions
and
44 deletions
+79
-44
_styles.scss
src/_styles.scss
+3
-3
categoryApi.ts
src/api/categoryApi.ts
+10
-0
store.ts
src/app/store.ts
+4
-1
headerSlice.ts
src/components/Header/headerSlice.ts
+29
-0
index.tsx
src/components/Header/index.tsx
+16
-25
index.tsx
src/components/Sidenav/index.tsx
+4
-3
interface.ts
src/components/interface.ts
+4
-0
environmentConfig.ts
src/configuration/environmentConfig.ts
+1
-1
MainPage.tsx
src/pages/MainPage.tsx
+2
-2
_index.scss
src/styles/_index.scss
+2
-0
tsconfig.json
tsconfig.json
+4
-9
No files found.
src/_styles.scss
View file @
f511a2a1
@use
"~bootstrap/scss/bootstrap"
;
@use
"
./
styles/components.scss"
;
@use
"
./
styles/pages.scss"
;
@use
"
./
styles/common.scss"
;
@use
"styles/components.scss"
;
@use
"styles/pages.scss"
;
@use
"styles/common.scss"
;
src/api/categoryApi.ts
0 → 100644
View file @
f511a2a1
import
axiosClient
from
"./axiosClient"
;
const
categoryApi
=
{
getCategories
:
()
=>
{
const
url
=
"/api/category"
;
return
axiosClient
.
get
(
url
);
},
};
export
default
categoryApi
;
src/app/store.ts
View file @
f511a2a1
import
{
configureStore
}
from
"@reduxjs/toolkit"
;
import
headerReducer
from
"components/Header/headerSlice"
;
const
rootReducer
=
{};
const
rootReducer
=
{
header
:
headerReducer
,
};
const
store
=
configureStore
({
reducer
:
rootReducer
});
...
...
src/components/Header/headerSlice.ts
0 → 100644
View file @
f511a2a1
import
{
createAsyncThunk
,
createSlice
,
PayloadAction
}
from
"@reduxjs/toolkit"
;
import
categoryApi
from
"api/categoryApi"
;
import
{
ICategory
}
from
"components/interface"
;
const
initialState
:
{
data
:
ICategory
[]
}
=
{
data
:
[],
};
export
const
getCategories
=
createAsyncThunk
(
"header/categories"
,
async
()
=>
{
const
res
=
await
categoryApi
.
getCategories
();
return
res
;
});
const
header
=
createSlice
({
name
:
"header"
,
initialState
,
reducers
:
{},
extraReducers
:
(
builder
)
=>
{
builder
.
addCase
(
getCategories
.
fulfilled
,
(
state
,
action
:
PayloadAction
<
any
>
)
=>
{
state
.
data
=
action
.
payload
.
data
;
}
);
},
});
const
{
reducer
}
=
header
;
export
default
reducer
;
src/components/Header/index.tsx
View file @
f511a2a1
import
React
,
{
useRef
,
useState
}
from
"react"
;
import
React
,
{
use
Effect
,
use
Ref
,
useState
}
from
"react"
;
import
AppBar
from
"@mui/material/AppBar"
;
import
Box
from
"@mui/material/Box"
;
import
IconButton
from
"@mui/material/IconButton"
;
...
...
@@ -8,35 +8,26 @@ import Button from "@mui/material/Button";
import
HomeIcon
from
"@mui/icons-material/Home"
;
import
Sidenav
from
"../Sidenav"
;
import
{
Typography
}
from
"@mui/material"
;
const
navItems
=
[
"Media"
,
"thời sự"
,
"thế giới"
,
"pháp luật"
,
"kinh doanh"
,
"công nghệ"
,
"xe"
,
"du lịch"
,
"nhịp sống trẻ"
,
"văn hóa"
,
"giải trí"
,
"thể thao"
,
"giáo dục"
,
"khoa học"
,
"sức khỏe"
,
"giả - thật"
,
"bạn đọc"
,
];
import
{
useAppDispatch
,
useAppSelector
}
from
"app/hooks"
;
import
{
getCategories
}
from
"./headerSlice"
;
export
default
function
Header
()
{
const
dispatch
=
useAppDispatch
();
const
headerRef
=
useRef
<
HTMLElement
>
(
null
);
const
[
mobileOpen
,
setMobileOpen
]
=
useState
<
boolean
>
(
false
);
const
{
data
:
categoryData
}
=
useAppSelector
((
state
)
=>
state
.
header
);
useEffect
(()
=>
{
dispatch
(
getCategories
());
// eslint-disable-next-line react-hooks/exhaustive-deps
},
[]);
const
handleDrawerToggle
=
()
=>
{
setMobileOpen
(
!
mobileOpen
);
};
console
.
log
(
categoryData
);
return
(
<
Box
sx=
{
{
display
:
"flex"
}
}
className=
"header"
>
<
AppBar
...
...
@@ -81,10 +72,10 @@ export default function Header() {
alignItems
:
"center"
,
}
}
>
{
navItems
.
map
((
item
)
=>
(
{
categoryData
.
map
((
item
)
=>
(
<
Box
component=
"li"
key=
{
item
}
key=
{
item
.
id
}
sx=
{
{
color
:
"#000"
,
fontWeight
:
700
,
...
...
@@ -94,7 +85,7 @@ export default function Header() {
}
}
className=
"header-list__item"
>
{
item
}
{
item
.
label
}
</
Box
>
))
}
</
Box
>
...
...
@@ -123,7 +114,7 @@ export default function Header() {
</
AppBar
>
<
Sidenav
handleDrawerToggle=
{
handleDrawerToggle
}
navItems=
{
navItems
}
navItems=
{
categoryData
}
mobileOpen=
{
mobileOpen
}
/>
</
Box
>
...
...
src/components/Sidenav/index.tsx
View file @
f511a2a1
...
...
@@ -9,10 +9,11 @@ import {
ListItemText
,
Typography
,
}
from
"@mui/material"
;
import
{
ICategory
}
from
"components/interface"
;
type
Props
=
{
handleDrawerToggle
:
()
=>
void
;
navItems
:
Array
<
string
>
;
navItems
:
Array
<
ICategory
>
;
mobileOpen
:
boolean
;
};
...
...
@@ -43,9 +44,9 @@ const Sidenav = (props: Props) => {
<
Divider
/>
<
List
>
{
navItems
.
map
((
item
)
=>
(
<
ListItem
key=
{
item
}
disablePadding
>
<
ListItem
key=
{
item
.
id
}
disablePadding
>
<
ListItemButton
sx=
{
{
textAlign
:
"center"
}
}
>
<
ListItemText
primary=
{
item
}
/>
<
ListItemText
primary=
{
item
.
label
}
/>
</
ListItemButton
>
</
ListItem
>
))
}
...
...
src/components/interface.ts
0 → 100644
View file @
f511a2a1
export
interface
ICategory
{
id
:
string
;
label
:
string
;
}
src/configuration/environmentConfig.ts
View file @
f511a2a1
const
enviromentConfig
=
{
development
:
{
endPoint
:
"http
://localhost:5223
"
,
endPoint
:
"http
s://localhost:44386
"
,
},
production
:
{
endPoint
:
""
,
...
...
src/pages/MainPage.tsx
View file @
f511a2a1
...
...
@@ -44,8 +44,8 @@ const newspapers: Array<INewspaper> = [
const
MainPage
=
()
=>
{
return
(
<
main
className=
"container py-3"
>
{
newspapers
.
map
((
newspaper
)
=>
(
<
Newspaper
key=
{
newspaper
.
label
}
data=
{
newspaper
}
/>
{
newspapers
.
map
((
newspaper
,
idx
)
=>
(
<
Newspaper
key=
{
`newspaper-${idx}`
}
data=
{
newspaper
}
/>
))
}
</
main
>
);
...
...
src/styles/_index.scss
0 → 100644
View file @
f511a2a1
@forward
"./mixins"
;
@forward
"./variables"
;
tsconfig.json
View file @
f511a2a1
{
"compilerOptions"
:
{
"target"
:
"es5"
,
"lib"
:
[
"dom"
,
"dom.iterable"
,
"esnext"
],
"lib"
:
[
"dom"
,
"dom.iterable"
,
"esnext"
],
"allowJs"
:
true
,
"skipLibCheck"
:
true
,
"esModuleInterop"
:
true
,
...
...
@@ -18,9 +14,8 @@
"resolveJsonModule"
:
true
,
"isolatedModules"
:
true
,
"noEmit"
:
true
,
"jsx"
:
"react-jsx"
"jsx"
:
"react-jsx"
,
"baseUrl"
:
"./src"
},
"include"
:
[
"src"
]
"include"
:
[
"src"
]
}
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