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
f10f185b
Commit
f10f185b
authored
Nov 23, 2022
by
Ken
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add loading component
parent
a9990c84
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
73 additions
and
5 deletions
+73
-5
globalSlice.ts
src/app/globalSlice.ts
+15
-0
store.ts
src/app/store.ts
+2
-0
index.tsx
src/components/Header/index.tsx
+14
-3
Loading.scss
src/components/Loading/Loading.scss
+18
-0
index.tsx
src/components/Loading/index.tsx
+16
-0
MainPage.tsx
src/pages/MainPage.tsx
+5
-0
components.scss
src/styles/components.scss
+3
-2
No files found.
src/app/globalSlice.ts
0 → 100644
View file @
f10f185b
import
{
createSlice
}
from
"@reduxjs/toolkit"
;
const
global
=
createSlice
({
name
:
"global"
,
initialState
:
{
isLoading
:
false
},
reducers
:
{
handleLoading
:
(
state
,
action
)
=>
{
state
.
isLoading
=
action
.
payload
;
},
},
});
const
{
actions
,
reducer
}
=
global
;
export
const
{
handleLoading
}
=
actions
;
export
default
reducer
;
src/app/store.ts
View file @
f10f185b
import
{
configureStore
}
from
"@reduxjs/toolkit"
;
import
headerReducer
from
"components/Header/headerSlice"
;
import
globalReducer
from
"./globalSlice"
;
const
rootReducer
=
{
header
:
headerReducer
,
global
:
globalReducer
,
};
const
store
=
configureStore
({
reducer
:
rootReducer
});
...
...
src/components/Header/index.tsx
View file @
f10f185b
...
...
@@ -10,6 +10,7 @@ import Sidenav from "../Sidenav";
import
{
Typography
}
from
"@mui/material"
;
import
{
useAppDispatch
,
useAppSelector
}
from
"app/hooks"
;
import
{
getCategories
}
from
"./headerSlice"
;
import
{
handleLoading
}
from
"app/globalSlice"
;
export
default
function
Header
()
{
const
dispatch
=
useAppDispatch
();
...
...
@@ -18,7 +19,19 @@ export default function Header() {
const
{
data
:
categoryData
}
=
useAppSelector
((
state
)
=>
state
.
header
);
useEffect
(()
=>
{
dispatch
(
getCategories
());
dispatch
(
handleLoading
(
true
));
try
{
const
fetchData
=
async
()
=>
{
await
dispatch
(
getCategories
());
};
fetchData
();
}
catch
(
err
)
{
console
.
error
(
"ERROR: "
,
err
);
}
finally
{
dispatch
(
handleLoading
(
false
));
}
// eslint-disable-next-line react-hooks/exhaustive-deps
},
[]);
...
...
@@ -26,8 +39,6 @@ export default function Header() {
setMobileOpen
(
!
mobileOpen
);
};
console
.
log
(
categoryData
);
return
(
<
Box
sx=
{
{
display
:
"flex"
}
}
className=
"header"
>
<
AppBar
...
...
src/components/Loading/Loading.scss
0 → 100644
View file @
f10f185b
.loading
{
display
:
none
;
&
-open
{
position
:
absolute
;
top
:
0
;
left
:
0
;
width
:
100vw
;
height
:
100vh
;
z-index
:
1000
;
display
:
flex
;
justify-content
:
center
;
align-items
:
center
;
background-color
:
white
;
opacity
:
0
.5
;
cursor
:
not
-
allowed
;
}
}
src/components/Loading/index.tsx
0 → 100644
View file @
f10f185b
import
{
CircularProgress
}
from
"@mui/material"
;
import
React
from
"react"
;
type
Props
=
{
isOpen
:
boolean
;
};
const
Loading
=
({
isOpen
}:
Props
)
=>
{
return
(
<
div
className=
{
`loading${isOpen ? " loading-open" : ""}`
}
>
<
CircularProgress
/>
</
div
>
);
};
export
default
Loading
;
src/pages/MainPage.tsx
View file @
f10f185b
import
{
useAppSelector
}
from
"app/hooks"
;
import
Loading
from
"components/Loading"
;
import
React
from
"react"
;
import
Newspaper
from
"../components/Newspaper"
;
import
{
INewspaper
}
from
"../utils/interface"
;
...
...
@@ -42,8 +44,11 @@ const newspapers: Array<INewspaper> = [
];
const
MainPage
=
()
=>
{
const
{
isLoading
}
=
useAppSelector
((
state
)
=>
state
.
global
);
return
(
<
main
className=
"container py-3"
>
<
Loading
isOpen=
{
isLoading
}
/>
{
newspapers
.
map
((
newspaper
,
idx
)
=>
(
<
Newspaper
key=
{
`newspaper-${idx}`
}
data=
{
newspaper
}
/>
))
}
...
...
src/styles/components.scss
View file @
f10f185b
@use
"../components/Header/Header.scss"
;
@use
"../components/Newspaper/Newspaper.scss"
;
@use
"components/Header/Header.scss"
;
@use
"components/Newspaper/Newspaper.scss"
;
@use
"components/Loading/Loading.scss"
;
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