-
Notifications
You must be signed in to change notification settings - Fork 16
/
lists.js
54 lines (48 loc) · 1.31 KB
/
lists.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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',
'users/:username/lists(/)': 'showUserLists',
}
})
new Router({ controller: API })
},
}
async function showList (id) {
const { default: ListLayout } = await import('./components/list_layout.svelte')
try {
const { list, selections } = await getListWithSelectionsById(id)
app.layout.showChildComponent('main', ListLayout, {
props: { list, selections }
})
} catch (err) {
app.execute('show:error', err)
}
}
async function showUserLists (user) {
try {
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: userModel.toJSON()
}
})
app.navigate(`users/${username}/lists`)
} catch (err) {
app.execute('show:error', err)
}
}
const showMainUserLists = () => showUserLists(app.user)
const API = {
showList,
showUserLists,
showMainUserLists
}