Skip to content

Commit 3d135e8

Browse files
committed
App restructure
Define state hooks
1 parent bbd6997 commit 3d135e8

17 files changed

+28
-32
lines changed

docs/drafts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The points below are still in progress
1111
- Typed data entities
1212
- Not just a dummy template
1313
- Uses react hooks
14-
- State management with Redux + Rematch for reducing Redux code boilerplate
14+
- Simpler state management with Redux + Rematch for reducing Redux code boilerplate
1515
- Material UI kit
1616
- Smart basic applications with real-world usage
1717
- Users/Organizations roles with many-to-many relations

src/Dashboard/Content/_api/_mocks/.gitkeep

Whitespace-only changes.

src/Dashboard/DashboardContainer.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1-
import React from 'react'
1+
import React, { useEffect } from 'react'
22
import LinearProgress from '@material-ui/core/LinearProgress'
33

4-
import { useDashboardData } from './DashboardData'
4+
import { useDashboardState, useDashboardEffects } from './_state'
55

66
import Dashboard from './Dashboard'
77

88
// Before showing the dashboard we need to be sure that the
99
// User data is propperly requested
1010
const DashboardContainer: React.FC = props => {
11-
const state = useDashboardData()
11+
const { loading, error } = useDashboardState()
12+
const effects = useDashboardEffects()
13+
14+
useEffect(() => {
15+
effects.request()
16+
}, [effects])
17+
18+
if (loading) return <LinearProgress />
19+
if (error) return <p>Error :(</p>
1220

13-
// if (loading) return <LinearProgress />
14-
// if (error) {
15-
// console.log(error)
16-
// return <p>Error :(</p>
17-
// }
1821
return <Dashboard />
1922
}
2023

src/Dashboard/DashboardData.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,3 @@
11
import { useEffect } from 'react'
22

3-
import { useDispatch, useSelector } from 'react-redux'
4-
import { RootState, RootDispatch } from '_store'
5-
6-
export function useDashboardData() {
7-
const state = useSelector((state: RootState) => state.dashboard)
8-
const dispatch = useDispatch<RootDispatch>()
9-
10-
// Request user data
11-
useEffect(() => {
12-
dispatch.dashboard.request()
13-
}, [dispatch])
14-
15-
return state
16-
}
17-
183
export default {}

0 commit comments

Comments
 (0)