Skip to content
This repository was archived by the owner on Jan 6, 2023. It is now read-only.

Commit d0ef537

Browse files
committed
feat: Change routing to 'maker/apps'
1 parent edcbd66 commit d0ef537

File tree

4 files changed

+33
-38
lines changed

4 files changed

+33
-38
lines changed

pages/maker/index.js renamed to pages/maker/apps/index.js

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,36 +18,40 @@ const MakerPortal = ({ params, apiServer, user, maker, errorMessage, appList, se
1818

1919
const router = useRouter()
2020

21-
console.log(router)
22-
const updateMakerRoute = id => {
23-
router.push(
24-
{
25-
pathname: '/maker',
26-
query: {
27-
params: { appId: id }
28-
},
29-
as: `/maker/${id}`
21+
const updateMakerRoute = id => router.push(
22+
{
23+
pathname: '/maker/apps',
24+
query: {
25+
params: { appId: id }
3026
},
31-
{
32-
shallow: true
33-
}
34-
)
35-
}
27+
as: `/maker/apps/${id}`
28+
},
29+
{
30+
shallow: true
31+
}
32+
)
3633

3734
const getAppId = () => {
38-
35+
if (!params) return undefined
3936
const id = parseInt(params.appId, 10)
40-
if (isNaN(id)) return null
37+
if (isNaN(id)) return undefined
4138
return id
4239
}
4340

4441
useEffect(() => {
4542
async function fetchAppsOnInit () {
4643
await fetchApps({ apiServer, user })(dispatch)
47-
4844
if (hasAppId) {
4945
dispatch(selectAppAction(getAppId()))
5046
}
47+
if (!hasAppId && process.browser) {
48+
setTimeout(() => {
49+
console.log(appList)
50+
// if (!appList[0]) return
51+
const { id } = appList[0]
52+
dispatch(selectAppAction(id))
53+
})
54+
}
5155
}
5256
fetchAppsOnInit()
5357
}, [])
@@ -64,22 +68,13 @@ const MakerPortal = ({ params, apiServer, user, maker, errorMessage, appList, se
6468
)
6569
}
6670

67-
// if (!hasAppId) {
68-
// if (appList.length === 0) throw new Error('wlkdsfsldfl')
69-
// const { id } = appList[0]
70-
// console.log('has no app id take first', id)
71-
// updateMakerRoute(id)
72-
// dispatch(selectAppAction(id))
73-
// }
74-
7571
function handleChangingApp (event) {
7672
event.persist()
7773
const id = event.target.value
7874
dispatch(selectAppAction(id))
7975
updateMakerRoute(id)
8076
}
8177

82-
8378
return (
8479
<Page innerPadding={0} wrap>
8580
<Head title={selectedApp.name} />
@@ -135,7 +130,12 @@ const MakerPortal = ({ params, apiServer, user, maker, errorMessage, appList, se
135130
)
136131
}
137132

138-
const mapStateToProps = (state) => ({
133+
MakerPortal.getInitialProps = (x) => {
134+
console.log(x.userApps)
135+
return { params: x.query.params }
136+
}
137+
138+
const mapStateToProps = state => ({
139139
user: selectUser(state),
140140
apiServer: selectApiServer(state),
141141
maker: selectMaker(state),

server.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ app.prepare().then(() => {
220220
/**
221221
* Maker pages
222222
*/
223-
server.get('/maker', (req, res) => renderAndCache(req, res, '/maker'))
223+
server.get('/maker', (req, res) => res.redirect('/maker/apps'))
224+
server.get('/maker/apps', (req, res) => renderAndCache(req, res, '/maker/apps'))
224225
server.get('/maker/:accessToken', (req, res) => renderAndCache(req, res, '/maker/magic-link', { accessToken: req.params.accessToken }))
225226

226227
apps.platforms.forEach((platform) => {

stores/maker/actions.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ export const fetchApps = ({ user, apiServer }) => async dispatch => {
6868
}
6969
})
7070
const apps = await response.json()
71-
dispatch(fetchAppsDoneAction(apps))
72-
dispatch(setLoadingDoneAction())
71+
await dispatch(fetchAppsDoneAction(apps))
7372
} catch (error) {
7473
dispatch(fetchAppsFailAction())
7574
}

stores/maker/reducer.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ const initialState = {
1313
function makerReducer(state = initialState, action) {
1414
switch (action.type) {
1515

16-
case MakerActions.SET_LOADING_DONE:
17-
return {
18-
...state,
19-
loading: false
20-
}
21-
2216
case MakerActions.MAKER_AUTH_ERROR:
2317
return {
2418
...state,
@@ -29,9 +23,10 @@ function makerReducer(state = initialState, action) {
2923
case MakerActions.FETCH_APPS_DONE:
3024
return {
3125
...state,
26+
loading: false,
3227
appIds: action.payload.apps.map(app => app.id),
33-
appEntities: keyBy(action.payload.apps, 'id'),
34-
selectedAppId: action.payload.apps.length ? action.payload.apps[0].id : null
28+
appEntities: keyBy(action.payload.apps, 'id')
29+
// selectedAppId: action.payload.apps.length ? action.payload.apps[0].id : null
3530
}
3631

3732
case MakerActions.SELECT_APP:

0 commit comments

Comments
 (0)