Advertisement
EntropyStarRover

connector

Mar 18th, 2021
56
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import page from "//unpkg.com/page/page.mjs"
  2. import {
  3. html,
  4. render
  5. } from 'https://unpkg.com/lit-html?module';
  6. import {
  7. displayCatalog
  8. } from "./catalog.js"
  9. import {
  10. createItem
  11. } from "./create.js";
  12. import {
  13. loginF
  14. } from "./login.js"
  15. import {
  16. registerF
  17. } from "./register.js"
  18. import {
  19. showDetails
  20. } from "./details.js"
  21. import {
  22. getMyFurniture
  23. } from "./myFurniture.js"
  24.  
  25. function connector() {
  26.  
  27. page('/',loadData, displayCatalog);
  28. page('/index.html',loadData, displayCatalog);
  29. page('/login', loginF);
  30. page('/register', registerF);
  31. page('/create', createItem);
  32. page('/details/:id', loadData, showDetails);
  33. page('/my-furniture', getMyFurniture);
  34.  
  35. page.start();
  36.  
  37.  
  38. function setNavigation() {
  39. let nav = document.getElementsByTagName('nav')[0];
  40. let logedUser = sessionStorage.getItem("userId");
  41.  
  42. function navigationTemplate() {
  43. return html `
  44. <a id="catalogLink" href="index.html" class="active">Dashboard</a>
  45. ${logedUser ? html`<div id="user">
  46. <a id="createLink" href="/create" >Create Furniture</a>
  47. <a id="profileLink" href="/my-furniture" >My Publications</a>
  48. <a id="logoutBtn" @click=${logOut} href="javascript:void(0)">Logout</a>
  49. </div>`: html`<div id="guest">
  50. <a id="loginLink" href="/login">Login</a>
  51. <a id="registerLink" href="/register">Register</a>
  52. </div>`}
  53. `
  54. }
  55. render(navigationTemplate(), nav)
  56. }
  57. setNavigation();
  58.  
  59. function loadData(context, next) {
  60. setNavigation();
  61. next();
  62. }
  63. async function logOut() {
  64. let response = await fetch("http://localhost:3030/user/logout");
  65. let result = await response.json();
  66. console.log("result is eeeeemptyyy");
  67. sessionStorage.clear();
  68. setNavigation();
  69. page.redirect('/')
  70.  
  71. }
  72.  
  73. }
  74.  
  75. connector();
  76.  
  77.  
Advertisement
RAW Paste Data Copied
Advertisement