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

Commit 0564524

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

File tree

5 files changed

+36
-41
lines changed

5 files changed

+36
-41
lines changed

pages/admin/app.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ class App extends React.Component {
206206
<p>
207207
Magic link: <a href={`/maker/${app.accessToken}`}>{`/maker/${app.accessToken}`}</a>
208208
</p>
209+
<p>
210+
Maker portal: <a href={`/maker/apps/${app.id}`}>{`/maker/apps/${app.id}`}</a>
211+
</p>
212+
209213
<Form.Wrapper>
210214
<TextField
211215
value={this.state.name || ''}

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

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,36 +18,34 @@ 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}`
30-
},
31-
{
32-
shallow: true
33-
}
34-
)
35-
}
21+
const updateMakerRoute = id => router.push(
22+
'/maker/apps',
23+
`/maker/apps/${id}`,
24+
{
25+
shallow: true
26+
}
27+
)
3628

3729
const getAppId = () => {
38-
30+
if (!params) return undefined
3931
const id = parseInt(params.appId, 10)
40-
if (isNaN(id)) return null
32+
if (isNaN(id)) return undefined
4133
return id
4234
}
4335

4436
useEffect(() => {
4537
async function fetchAppsOnInit () {
4638
await fetchApps({ apiServer, user })(dispatch)
47-
4839
if (hasAppId) {
4940
dispatch(selectAppAction(getAppId()))
5041
}
42+
if (!hasAppId && process.browser) {
43+
setTimeout(() => {
44+
console.log(appList)
45+
const { id } = appList[0]
46+
dispatch(selectAppAction(id))
47+
})
48+
}
5149
}
5250
fetchAppsOnInit()
5351
}, [])
@@ -64,22 +62,13 @@ const MakerPortal = ({ params, apiServer, user, maker, errorMessage, appList, se
6462
)
6563
}
6664

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-
7565
function handleChangingApp (event) {
7666
event.persist()
7767
const id = event.target.value
7868
dispatch(selectAppAction(id))
7969
updateMakerRoute(id)
8070
}
8171

82-
8372
return (
8473
<Page innerPadding={0} wrap>
8574
<Head title={selectedApp.name} />
@@ -135,7 +124,12 @@ const MakerPortal = ({ params, apiServer, user, maker, errorMessage, appList, se
135124
)
136125
}
137126

138-
const mapStateToProps = (state) => ({
127+
MakerPortal.getInitialProps = (x) => {
128+
console.log(x.userApps)
129+
return { params: x.query.params }
130+
}
131+
132+
const mapStateToProps = state => ({
139133
user: selectUser(state),
140134
apiServer: selectApiServer(state),
141135
maker: selectMaker(state),

server.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ async function renderAndCache(req, res, pagePath, serverData) {
6666
...serverData,
6767
blockstackRankedApps,
6868
appMiningMonths,
69-
appMiningApps
69+
appMiningApps,
70+
params: req.params
7071
}
7172
const html = await app.renderToHTML(req, res, pagePath, dataToPass)
7273
if (cacheKey) {
@@ -220,7 +221,9 @@ app.prepare().then(() => {
220221
/**
221222
* Maker pages
222223
*/
223-
server.get('/maker', (req, res) => renderAndCache(req, res, '/maker'))
224+
server.get('/maker', (req, res) => res.redirect('/maker/apps'))
225+
server.get('/maker/apps', (req, res) => renderAndCache(req, res, '/maker/apps'))
226+
server.get('/maker/apps/:appId', (req, res) => renderAndCache(req, res, '/maker/apps'))
224227
server.get('/maker/:accessToken', (req, res) => renderAndCache(req, res, '/maker/magic-link', { accessToken: req.params.accessToken }))
225228

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

stores/maker/actions.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ export const savePaymentDetails = ({ apiServer, appId, jwt, btcAddress, stxAddre
5555
}
5656

5757
export const fetchApps = ({ user, apiServer }) => async dispatch => {
58-
dispatch(fetchAppsAction())
5958
if (!(user && user.jwt)) {
6059
dispatch(errorAction())
6160
return
6261
}
62+
dispatch(fetchAppsAction())
6363
try {
6464
const uri = `${apiServer}/api/maker/apps`
6565
const response = await fetch(uri, {
@@ -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)