diff options
Diffstat (limited to 'src/router.ts')
-rw-r--r-- | src/router.ts | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/src/router.ts b/src/router.ts index 2d229b0..bcdf8eb 100644 --- a/src/router.ts +++ b/src/router.ts @@ -17,13 +17,12 @@ export function from(location: Location): Route { const xs = entry.split('=') if (xs.length === 2) { const key = xs[0] - const value = parseInt(xs[1]) - if (key == 'warmup') config.warmup = value - else if (key == 'tabatas') config.tabatas = value - else if (key == 'prepare') config.prepare = value - else if (key == 'cycles') config.cycles = value - else if (key == 'work') config.work = value - else if (key == 'rest') config.rest = value + if (key == 'warmup') config.warmup = parseInt(xs[1]) + else if (key == 'tabatas') config.tabatas = decodeTabatas(xs[1]) + else if (key == 'prepare') config.prepare = parseInt(xs[1]) + else if (key == 'cycles') config.cycles = parseInt(xs[1]) + else if (key == 'work') config.work = parseInt(xs[1]) + else if (key == 'rest') config.rest = parseInt(xs[1]) } }) const params = search.split('&') @@ -39,13 +38,23 @@ export function toString(route: Route): string { const { warmup, tabatas, prepare, cycles, work, rest } = route.config const params = [ `warmup=${warmup}`, - `tabatas=${tabatas}`, `prepare=${prepare}`, `cycles=${cycles}`, `work=${work}`, `rest=${rest}`, - ].join('&') - query = `?${params}` + ] + if(tabatas.length > 0) { + params.push(`tabatas=${encodeTabatas(tabatas)}`) + } + query = `?${params.join('&')}` } return `#${path}${query}` } + +function encodeTabatas(xs: string[]): string { + return encodeURIComponent(xs.join(',')) +} + +function decodeTabatas(str: string): string[] { + return decodeURIComponent(str).split(',').map(t => t.trim()) +} |