Skip to content
Snippets Groups Projects
TheNavBar.vue 15.4 KiB
Newer Older
raghosh's avatar
raghosh committed
<template>
  <nav
    class="
      relative
raghosh's avatar
raghosh committed
      top-0
raghosh's avatar
raghosh committed
      flex flex-wrap
      items-center
      justify-between
      px-2
      py-3
      mb-3
    "
  >
moon's avatar
moon committed
    <div class="text-right px-8 w-full">
      Last updated: 30-06-2022
    </div>
    <div class="px-4 flex mb-2 flex-wrap w-full items-center justify-between">
raghosh's avatar
raghosh committed
      <div class="ml-4">
raghosh's avatar
raghosh committed
        <a href="/">
          <img
            alt="logo"
            class="w-36 object-contain rounded-lg"
raghosh's avatar
raghosh committed
            src="@/assets/cd-code-logo.png"
moon's avatar
moon committed
          >
raghosh's avatar
raghosh committed
        </a>
      </div>
      <div class="flex items-center space-x-4">
        <router-link
          to="/"
          exact
          :class="{ active: $route.name === 'home' }"
          class="rounded-lg"
moon's avatar
moon committed
          @mouseover.native="openCondensateSubMenu = false"
raghosh's avatar
raghosh committed
        >
          <span
            class="
              px-4
              py-4
              flex
              items-center
              text-4xl
              font-semibold
raghosh's avatar
raghosh committed
            "
moon's avatar
moon committed
          >Home</span>
raghosh's avatar
raghosh committed
        </router-link>

        <router-link
          to="/about"
          :class="{ active: $route.name === 'about' }"
          class="rounded-lg"
moon's avatar
moon committed
          @mouseover.native="openCondensateSubMenu = false"
raghosh's avatar
raghosh committed
        >
          <span
            class="
              px-4
              py-4
              flex
              items-center
raghosh's avatar
raghosh committed
              hover:text-pink-base
              text-4xl
              font-semibold
raghosh's avatar
raghosh committed
            "
moon's avatar
moon committed
          >About</span>
raghosh's avatar
raghosh committed
        </router-link>

        <router-link
          to="/proteins"
          :class="{ active: $route.name === 'proteins' }"
          class="rounded-lg"
moon's avatar
moon committed
          @mouseover.native="openCondensateSubMenu = false"
raghosh's avatar
raghosh committed
        >
          <span
            class="
              px-4
              py-4
              flex
              items-center
raghosh's avatar
raghosh committed
              hover:text-pink-base
              text-4xl
              font-semibold
raghosh's avatar
raghosh committed
              leading-snug
            "
moon's avatar
moon committed
          >Proteins</span>
raghosh's avatar
raghosh committed
        </router-link>
raghosh's avatar
raghosh committed
        <div class="relative rounded-lg">
raghosh's avatar
raghosh committed
          <router-link
            to="/condensates"
            :class="{
              active:
                $route.name === 'condensates' ||
                $route.name === 'biomolecular' ||
                $route.name === 'synthetic' ||
                $route.name === 'addCondensate',
            }"
            class="rounded-lg"
moon's avatar
moon committed
            @mouseover.native="openCondensateMenu"
raghosh's avatar
raghosh committed
          >
            <span
              class="
                px-4
                py-4
                flex
                items-center
raghosh's avatar
raghosh committed
                hover:text-pink-base
                text-4xl
                font-semibold
raghosh's avatar
raghosh committed
                leading-snug
              "
moon's avatar
moon committed
            >Condensates</span>
raghosh's avatar
raghosh committed
          </router-link>
          <div
            v-if="openCondensateSubMenu"
            class="
              absolute
              z-50
              grid grid-cols-1
              left-0
raghosh's avatar
raghosh committed
              min-w-max
              rounded-lg
              shadow-lg
              border border-gray-200
raghosh's avatar
raghosh committed
            "
            @mouseleave="openCondensateSubMenu = false"
          >
raghosh's avatar
raghosh committed
            <div>
moon's avatar
moon committed
              <router-link
                to="/biomolecular"
                class="rounded-lg"
              >
raghosh's avatar
raghosh committed
                <span
                  class="
                    px-4
                    py-4
                    flex
raghosh's avatar
raghosh committed
                    hover:text-pink-base
                    items-center
                    text-4xl
                    font-semibold
                  :class="
                    $route.name === 'biomolecular' ? 'text-pink-base' : ''
                  "
moon's avatar
moon committed
                  Biomolecular Condensates</span>
raghosh's avatar
raghosh committed
              </router-link>
            </div>
raghosh's avatar
raghosh committed
            <div>
moon's avatar
moon committed
              <router-link
                to="/synthetic"
                class="rounded-lg"
              >
raghosh's avatar
raghosh committed
                <span
                  class="
                    px-4
                    py-4
raghosh's avatar
raghosh committed
                    hover:text-pink-base
                    flex
                    items-center
                    text-4xl
                    font-semibold
                  :class="$route.name === 'synthetic' ? 'text-pink-base' : ''"
moon's avatar
moon committed
                >Synthetic Condensates</span>
raghosh's avatar
raghosh committed
              </router-link>
            </div>

            <!-- should uncomment later -->
            <div>
              <router-link
                v-if="
                  userRole !== null &&
moon's avatar
moon committed
                    (userRole === 'Maintainer' || userRole === 'Contributor')
                "
                to="/addCondensate"
                class="rounded-lg"
              >
                <span
                  class="
                    px-4
                    py-4
                    hover:text-pink-base
                    flex
                    items-center
                    text-4xl
                    font-semibold
                  "
                  :class="
                    $route.name === 'addCondensate' ? 'text-pink-base' : ''
                  "
moon's avatar
moon committed
                >Add New Condensate</span>
raghosh's avatar
raghosh committed
          </div>
        </div>

        <router-link
          to="/statistics"
          :class="{ active: $route.name === 'statistics' }"
          class="rounded-lg"
moon's avatar
moon committed
          @mouseover.native="openCondensateSubMenu = false"
raghosh's avatar
raghosh committed
        >
raghosh's avatar
raghosh committed
          <span
            class="
              px-4
              py-4
              hover:text-pink-base
              flex
              items-center
              text-4xl
              font-semibold
moon's avatar
moon committed
          >Statistics</span>
raghosh's avatar
raghosh committed
        </router-link>

        <a
          href="https://wiki.cd-code.org"
          class="rounded-lg"
          target="wiki"
moon's avatar
moon committed
          @mouseover="openCondensateSubMenu = false"
raghosh's avatar
raghosh committed
        >
raghosh's avatar
raghosh committed
          <span
            class="
              px-4
              py-4
              hover:text-pink-base
              flex
              items-center
              text-4xl
              font-semibold
moon's avatar
moon committed
          >Encyclopedia</span>
raghosh's avatar
raghosh committed
        </a>

        <router-link
          to="/help"
          :class="{ active: $route.name === 'help' }"
          class="rounded-lg"
moon's avatar
moon committed
          @mouseover.native="openCondensateSubMenu = false"
raghosh's avatar
raghosh committed
        >
raghosh's avatar
raghosh committed
          <span
            class="
              px-4
              py-4
              hover:text-pink-base
              flex
              items-center
              text-4xl
              font-semibold
moon's avatar
moon committed
          >Help</span>
raghosh's avatar
raghosh committed
        </router-link>
      </div>

raghosh's avatar
raghosh committed
      <div class="relative z-10 mr-4">
        <div class="flex space-x-2">
          <router-link
            v-if="userData === null"
moon's avatar
moon committed
            to="/login"
            role="presentation"
            :class="
              $route.name === 'login' ? 'text-pink-base border-pink-base' : ''
            class="rounded-lg border-2 border-gray-500 hover:border-pink-base"
moon's avatar
moon committed
            @mouseover.native="openCondensateSubMenu = false"
raghosh's avatar
raghosh committed
          >
                hover:text-pink-base
                flex
                items-center
                text-3xl
                font-medium
              "
moon's avatar
moon committed
            >Sign in</span>
          </router-link>
          <router-link
            v-if="userData === null"
moon's avatar
moon committed
            to="/signup"
            role="presentation"
            :class="
              $route.name === 'signup' ? 'text-pink-base border-pink-base' : ''
            "
            class="rounded-lg border-2 border-gray-500 hover:border-pink-base"
moon's avatar
moon committed
            @mouseover.native="openCondensateSubMenu = false"
                hover:text-pink-base
                flex
                items-center
                text-3xl
                font-medium
              "
moon's avatar
moon committed
            >Sign up</span>
raghosh's avatar
raghosh committed
        <button
          v-if="userData !== null"
          type="button"
          class="
            relative
            z-10
            rounded-full
            text-gray-400
raghosh's avatar
raghosh committed
            focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray
          "
          @click="openProfileMenu"
        >
          <div
raghosh's avatar
raghosh committed
            class="
              w-20
              h-20
              p-1
              flex
              hover:text-pink-base
              items-center
              overflow-hidden
              rounded-full
            "
raghosh's avatar
raghosh committed
          >
            <!-- <img
              class="
                object-cover object-center
                w-full
                h-full
                visible
                rounded-full
                group-hover:hidden
              "
              src="https://images.unsplash.com/photo-1531427186611-ecfd6d936c79?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=687&q=80"
              alt="RG"
            /> -->
            <div
              class="
                w-full
                h-full
                flex
                place-content-center
raghosh's avatar
raghosh committed
                align-center
                text-center
                items-center
                visible
raghosh's avatar
raghosh committed
                rounded-full
                font-bold
                align-middle
              "
            >
              <span>{{ userInitials }}</span>
            </div>
          </div>
        </button>
        <button
          v-if="profileMenuOpen"
          tabindex="-1"
          class="fixed inset-0 cursor-default h-full w-full"
moon's avatar
moon committed
          @click="profileMenuOpen = false"
        />
raghosh's avatar
raghosh committed
        <div
          v-if="profileMenuOpen && userData !== null"
          class="
            absolute
            mt-2
            grid grid-cols-1
            right-0
raghosh's avatar
raghosh committed
            rounded-lg
            shadow-lg
            border border-gray-200
raghosh's avatar
raghosh committed
          "
        >
          <div class="p-4">
moon's avatar
moon committed
              {{ userName }}
            </h4>
            <p class="font-medium text-black text-2xl">
moon's avatar
moon committed
              {{ userEmail }}
            </p>
raghosh's avatar
raghosh committed
          </div>
          <div>
raghosh's avatar
raghosh committed
            <div>
raghosh's avatar
raghosh committed
              <router-link
                v-show="userData !== null"
moon's avatar
moon committed
                to="/profile"
raghosh's avatar
raghosh committed
                role="presentation"
                :class="{ active: $route.name === 'profile' }"
                class="rounded-lg"
moon's avatar
moon committed
                @mouseover.native="openCondensateSubMenu = false"
raghosh's avatar
raghosh committed
              >
                <span
                  class="
                    px-4
                    py-4
raghosh's avatar
raghosh committed
                    flex
raghosh's avatar
raghosh committed
                    hover:text-pink-base
raghosh's avatar
raghosh committed
                    items-center
raghosh's avatar
raghosh committed
                    font-medium
                  "
moon's avatar
moon committed
                >Profile</span>
raghosh's avatar
raghosh committed
              </router-link>
            </div>
moon's avatar
moon committed
                    (userRole === 'Contributor' || userRole === 'Maintainer')
moon's avatar
moon committed
                to="/updateItems"
                role="presentation"
                :class="{ active: $route.name === 'updateItems' }"
                class="rounded-lg"
moon's avatar
moon committed
                @mouseover.native="openCondensateSubMenu = false"
                    font-medium
                  "
                >
                  {{
                    userRole === "Maintainer"
                      ? "All Submitted Changes"
                      : "My Submitted Changes"
                  }}
                </span>
              </router-link>
            </div>
            <div>
              <router-link
                v-if="userData !== null"
                to="/newcondensate"
                role="presentation"
                class="rounded-lg"
                @mouseover.native="openCondensateSubMenu = false"
              >
                <span
                  class="
                    px-4
                    py-4
                    text-black
                    flex
                    hover:text-pink-base
                    items-center
                    text-2xl
                    font-medium
                  "
moon's avatar
moon committed
                >All Submitted Condensates</span>
raghosh's avatar
raghosh committed
            <div>
raghosh's avatar
raghosh committed
              <router-link
                v-if="userData !== null"
moon's avatar
moon committed
                to="/login"
raghosh's avatar
raghosh committed
                role="presentation"
                class="rounded-lg"
moon's avatar
moon committed
                @click.native="signOut"
                @mouseover.native="openCondensateSubMenu = false"
raghosh's avatar
raghosh committed
              >
                <span
                  class="
                    px-4
                    py-4
raghosh's avatar
raghosh committed
                    flex
raghosh's avatar
raghosh committed
                    hover:text-pink-base
raghosh's avatar
raghosh committed
                    items-center
raghosh's avatar
raghosh committed
                    font-medium
                  "
moon's avatar
moon committed
                >Logout</span>
raghosh's avatar
raghosh committed
              </router-link>
            </div>
          </div>
        </div>
      </div>
    </div>
  </nav>
</template>

<script>
export default {
  data() {
    return {
      // userData: this.$store.getters['User/userData']
      openCondensateSubMenu: false,
      profileMenuOpen: false,
    };
  },
  computed: {
    userData: function () {
moon's avatar
moon committed
      return this.$store.getters['User/userData'];
raghosh's avatar
raghosh committed
    },
    userName() {
      const data = this.parsingUserData();
      return data.full_name;
    },
    userEmail() {
      const data = this.parsingUserData();
      return data.email;
    },
    userInitials() {
      const data = this.parsingUserData();
      const initials = this.getInitials(data.full_name);
      return initials;
    },
    userRole: function () {
moon's avatar
moon committed
      return this.$store.getters['User/userRole'];
raghosh's avatar
raghosh committed
    },
  },
  mounted: function () {
    const vm = this;

    // console.log(vm.userData)
    // console.log(this.$route.name)
    // if(vm.userData !== null) {
    //   vm.$router.push('/profile')
    // }
  },
  methods: {
    parsingUserData() {
moon's avatar
moon committed
      const data = this.$store.getters['User/userData'];
raghosh's avatar
raghosh committed
      let parsedData = JSON.parse(data);
      return parsedData;
    },
    getInitials(string) {
moon's avatar
moon committed
      var names = string.split(' '),
raghosh's avatar
raghosh committed
        initials = names[0].substring(0, 1).toUpperCase();

      if (names.length > 1) {
        initials += names[names.length - 1].substring(0, 1).toUpperCase();
      }
      return initials;
    },
    openCondensateMenu() {
      this.openCondensateSubMenu = true;
    },
    openProfileMenu() {
      this.profileMenuOpen = !this.profileMenuOpen;
    },
    signOut() {
      const vm = this;
moon's avatar
moon committed
      window.localStorage.removeItem('jwt');
      window.localStorage.removeItem('userData');
      window.localStorage.removeItem('roleName');
      vm.$store.dispatch('User/logOut');
      vm.$router.push('/login');
raghosh's avatar
raghosh committed
    },
  },
};
</script>
<style scoped>
a {
  color: black;
}

.active {
  color: #ef0087 !important;
}
</style>