/
profile-router.ts
41 lines (33 loc) · 1.23 KB
/
profile-router.ts
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
import { get, writable } from 'svelte/store'
import { Subrouter } from '@core/router'
import { ProfileRoute } from '../../enums'
import { IProfileRouterEvent } from '../../interfaces'
import { resetRouterWithDrawerDelay } from '../../utils'
import { dashboardRouter } from '../dashboard-router'
export const profileRoute = writable<ProfileRoute>(null)
export const profileRouter = writable<ProfileRouter>(null)
export class ProfileRouter extends Subrouter<ProfileRoute> {
constructor() {
super(ProfileRoute.Actions, profileRoute, get(dashboardRouter))
}
public next(event: IProfileRouterEvent = {}): void {
const { settings, networkStatus } = event
let nextRoute: ProfileRoute
const currentRoute = get(this.routeStore)
switch (currentRoute) {
case ProfileRoute.Actions: {
if (settings) {
nextRoute = ProfileRoute.Settings
} else if (networkStatus) {
nextRoute = ProfileRoute.NetworkStatus
}
break
}
}
this.setNext(nextRoute)
}
closeDrawer(): void {
get(dashboardRouter).previous()
resetRouterWithDrawerDelay(get(profileRouter))
}
}