Skip to content

Commit

Permalink
add /users/:username/lists route
Browse files Browse the repository at this point in the history
Playing with the idea to then move /inventory/:username to /users/:username/inventory for consistency.
Alternative ideas welcome
  • Loading branch information
maxlath committed Aug 7, 2022
1 parent ab849aa commit 818590f
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions app/modules/lists/lists.js
@@ -1,11 +1,13 @@
import app from '#app/app'
import { getListWithSelectionsById } from './lib/lists.js'

export default {
initialize () {
const Router = Marionette.AppRouter.extend({
appRoutes: {
'lists/(:id)(/)': 'showList',
'lists(/)': 'showMainUserLists'
'lists(/)': 'showMainUserLists',
'users/:username/lists(/)': 'showUserLists',
}
})

Expand All @@ -25,20 +27,28 @@ async function showList (id) {
}
}

async function showMainUserLists () {
const { default: ListsLayout } = await import('./components/user_lists.svelte')
async function showUserLists (user) {
try {
app.layout.showChildComponent('main', ListsLayout, {
const [ { default: UserLists }, userModel ] = await Promise.all([
await import('./components/user_lists.svelte'),
app.request('resolve:to:userModel', user),
])
const username = userModel.get('username')
app.layout.showChildComponent('main', UserLists, {
props: {
user: app.user.toJSON()
user: userModel.toJSON()
}
})
app.navigate(`users/${username}/lists`)
} catch (err) {
app.execute('show:error', err)
}
}

const showMainUserLists = () => showUserLists(app.user)

const API = {
showList,
showUserLists,
showMainUserLists
}

0 comments on commit 818590f

Please sign in to comment.