diff options
Diffstat (limited to 'frontend/ts/src/pages/layout.ts')
-rw-r--r-- | frontend/ts/src/pages/layout.ts | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/frontend/ts/src/pages/layout.ts b/frontend/ts/src/pages/layout.ts new file mode 100644 index 0000000..3140c17 --- /dev/null +++ b/frontend/ts/src/pages/layout.ts @@ -0,0 +1,37 @@ +import { h, Html } from 'lib/rx' +import * as rx from 'lib/rx' +import * as request from 'request' +import * as route from 'route' +import { User } from 'models/user' +import * as modal from 'ui/modal' + +export function view(user: User, children: Html): Html { + return [ + h('header', + h('a', { href: '/' }, 'Maps'), + h('div', + user.name, + rx.withState<string | undefined>(undefined, logoutError => [ + h('button', + { + className: 'g-Logout__Button', + onclick: (event: Event) => { + request + .post_('/api/logout') + .then(_ => window.location.href = '') + .catch(({ message }) => logoutError.update(_ => message)) + } + }, + '(Déconnexion)' + ), + logoutError.map(err => err && modal.error({ + header: 'Erreur lors de la déconnexion', + message: err, + onClose: () => logoutError.update(_ => undefined) + })) + ]) + ) + ), + h('main', children) + ] +} |