Advertisement
bebo231312312321

Untitled

Jul 25th, 2023
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import page from '../node_modules/page/page.mjs'
  2. import { render } from '../node_modules/lit-html/lit-html.js'
  3.  
  4. import { getUserData } from './util.js'
  5. import { layoutTemplate } from './views/layout.js'
  6. import { homePage } from './views/home.js'
  7. import { loginPage } from './views/login.js'
  8. import { registerPage } from './views/register.js'
  9. import { logOut } from './data/auth.js'
  10.  
  11. //TODO: change  render root depending
  12. const root = document.body
  13.  
  14.  
  15. page(decorateContext);
  16. page('index.html', '/');
  17. page('/', homePage);
  18. page('/login', loginPage)
  19. page('/register', registerPage)
  20. page('/logout', logoutAction)
  21. page.start()
  22.  
  23.  
  24.  
  25. function decorateContext(ctx, next) {
  26.     ctx.render = renderView;
  27.  
  28.     next()
  29. }
  30.  
  31. //TODO: inject dependence
  32. function renderView(content) {
  33.     const userData = getUserData();
  34.     render(layoutTemplate(userData, content), root)
  35. }
  36. function logoutAction(ctx) {
  37.     logOut()
  38.     ctx.page.redirect('/')
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement