src/main/webapp/js/navigation-loader.js
/**
 * Adds a login or logout link to the page, depending on whether the user is
 * already logged in.
 */
Adds a login or logout link to the page, depending on whether the user is
already logged in.
Adds a login or logout link to the page depending on whether the user is already logged in .
function addLoginOrLogoutLinkToNavigation() {
  const navigationElement = document.getElementById('navigation');
  if (!navigationElement) {
    console.warn('Navigation element not found!');
    return;
  }
  else {
    navigationElement.appendChild(createListItem(createLink(
      '/index.html', 'Home')));
    navigationElement.appendChild(createListItem(createLink(
      '/aboutus.html', 'About Our Team')));
    navigationElement.appendChild(createListItem(createLink(
      '/feed.html', 'Public Feed')));
  }
  fetch('/login-status')
    .then((response) => {
      return response.json();
    })
    .then((loginStatus) => {
      if (loginStatus.isLoggedIn) {
        navigationElement.appendChild(createListItem(createLink(
          '/user-page.html?user=' + loginStatus.username, 'Your Page')));
        navigationElement.appendChild(
          createListItem(createLink('/advisors.html?user=' + loginStatus.username, 'Your Advisors')));
        navigationElement.appendChild(
          createListItem(createLink('/logout', 'Logout')));
      } else {
        navigationElement.appendChild(
          createListItem(createLink('/login', 'Login')));
      }
    });
}
function addLoginOrLogoutLinkToNavigation ( ) { const navigationElement = document . getElementById ( 'navigation' ) ; if ( ! navigationElement ) { console . warn ( 'Navigation element not found!' ) ; return ; } else { navigationElement . appendChild ( createListItem ( createLink ( '/index.html' , 'Home' ) ) ) ; navigationElement . appendChild ( createListItem ( createLink ( '/aboutus.html' , 'About Our Team' ) ) ) ; navigationElement . appendChild ( createListItem ( createLink ( '/feed.html' , 'Public Feed' ) ) ) ; } fetch ( '/login-status' ) . then ( ( response ) => { return response . json ( ) ; } ) . then ( ( loginStatus ) => { if ( loginStatus . isLoggedIn ) { navigationElement . appendChild ( createListItem ( createLink ( '/user-page.html?user=' + loginStatus . username , 'Your Page' ) ) ) ; navigationElement . appendChild ( createListItem ( createLink ( '/advisors.html?user=' + loginStatus . username , 'Your Advisors' ) ) ) ; navigationElement . appendChild ( createListItem ( createLink ( '/logout' , 'Logout' ) ) ) ; } else { navigationElement . appendChild ( createListItem ( createLink ( '/login' , 'Login' ) ) ) ; } } ) ; }
Adds a login or logout link to the page, depending on whether the user is
 already logged in.
Adds a login or logout link to the page depending on whether the user is already logged in .