Skip to content
Snippets Groups Projects
TheNavBar.vue 12 KiB
Newer Older
raghosh's avatar
raghosh committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460
<template>
  <nav
    class="
      relative
      shadow-md
      bg-secondary
      flex flex-wrap
      items-center
      justify-between
      px-2
      py-3
      mb-3
    "
  >
    <div class="px-4 flex flex-wrap w-full items-center justify-between">
      <div>
        <a href="/">
          <img
            alt="logo"
            class="w-64 rounded-lg"
            src="@/assets/dd-code-logo.png"
          />
        </a>
      </div>
      <div class="flex items-center space-x-4">
        <router-link
          to="/"
          exact
          :class="{ active: $route.name === 'home' }"
          @mouseover.native="openCondensateSubMenu = false"
          class="rounded-lg"
        >
          <span
            class="
              px-4
              py-4
              flex
              items-center
              text-3xl
              font-medium
              hover:opacity-75
            "
            >Home</span
          >
        </router-link>

        <router-link
          to="/about"
          :class="{ active: $route.name === 'about' }"
          @mouseover.native="openCondensateSubMenu = false"
          class="rounded-lg"
        >
          <span
            class="
              px-4
              py-4
              flex
              items-center
              text-3xl
              font-medium
              hover:opacity-75
            "
            >About</span
          >
        </router-link>

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

            <!-- should uncomment later -->
            <!-- <li
            v-if="
              userRole !== null &&
                (userRole === 'Maintainer' ||
                userRole === 'Contributor')
            "
            role="presentation"
          >
            <router-link
              to="/addCondensate"
              class="dropdown-item hover:no-underline h-16 pt-4"
            >
              <span class="text-2xl">Add New Condensate</span>
            </router-link>
          </li> -->
          </div>
        </div>

        <router-link
          to="/statistics"
          :class="{ active: $route.name === 'statistics' }"
          @mouseover.native="openCondensateSubMenu = false"
          class="rounded-lg"
        >
          <span class="px-4 py-4 flex items-center text-3xl font-medium"
            >Statistics</span
          >
        </router-link>

        <a
          href="https://wiki.cd-code.org"
          @mouseover="openCondensateSubMenu = false"
          class="rounded-lg"
        >
          <span class="px-4 py-4 flex items-center text-3xl font-medium"
            >Encyclopedia</span
          >
        </a>

        <router-link
          to="/updateItems"
          v-show="
            userData !== null &&
            (userRole === 'Contributor' || userRole === 'Maintainer')
          "
          role="presentation"
          :class="{ active: $route.name === 'updateItems' }"
          @mouseover.native="openCondensateSubMenu = false"
          class="rounded-lg"
        >
          <span class="px-4 py-4 flex items-center text-3xl font-medium">
            {{
              userRole === "Maintainer"
                ? "All Submitted Changes"
                : "My Submitted Changes"
            }}
          </span>
        </router-link>

        <router-link
          to="/help"
          :class="{ active: $route.name === 'help' }"
          @mouseover.native="openCondensateSubMenu = false"
          class="rounded-lg"
        >
          <span class="px-4 py-4 flex items-center text-3xl font-medium"
            >Help</span
          >
        </router-link>
      </div>

      <div class="relative mr-4">
        <router-link
          to="/login"
          v-if="userData === null"
          role="presentation"
          :class="{ active: $route.name === 'login' }"
          @mouseover.native="openCondensateSubMenu = false"
          class="rounded-lg"
        >
          <span class="px-4 py-4 submenu flex items-center text-3xl font-medium"
            >Login</span
          >
        </router-link>
        <button
          v-if="userData !== null"
          type="button"
          class="
            relative
            z-10
            rounded-full
            text-gray-400
            ring-2 ring-gray-400
            focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray
          "
          @click="openProfileMenu"
        >
          <div
            class="w-20 h-20 p-1 flex items-center overflow-hidden rounded-full"
          >
            <!-- <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="
                avatar
                w-full
                h-full
                flex
                place-content-center
                align-center
                text-center
                items-center
                visible
                bg-blue-300
                text-gray-700 text-center
                rounded-full
                font-bold
                align-middle
              "
            >
              <span>{{ userInitials }}</span>
            </div>
          </div>
        </button>
        <button
          v-if="profileMenuOpen"
          tabindex="-1"
          @click="profileMenuOpen = false"
          class="fixed inset-0 cursor-default h-full w-full"
        ></button>
        <div
          v-if="profileMenuOpen && userData !== null"
          class="
            absolute
            mt-2
            z-50
            grid grid-cols-1
            right-0
            bg-gray-800
            w-80
            rounded-lg
            shadow-lg
            border border-gray-200
            divide-y divide-white-500
            bg-white
          "
        >
          <div class="p-4">
            <h4 class="font-bold text-white">{{ userName }}</h4>
            <p class="font-medium text-white text-2xl">{{ userEmail }}</p>
          </div>
          <div>
            <div class="submenu">
              <router-link
                to="/profile"
                v-show="userData !== null"
                role="presentation"
                :class="{ active: $route.name === 'profile' }"
                @mouseover.native="openCondensateSubMenu = false"
                class="rounded-lg"
              >
                <span
                  class="
                    px-4
                    py-4
                    text-white
                    flex
                    items-center
                    text-3xl
                    font-medium
                  "
                  >Profile</span
                >
              </router-link>
            </div>
            <div class="submenu">
              <router-link
                to="/login"
                @click.native="signOut"
                v-if="userData !== null"
                role="presentation"
                @mouseover.native="openCondensateSubMenu = false"
                class="rounded-lg"
              >
                <span
                  class="
                    px-4
                    py-4
                    text-white
                    flex
                    items-center
                    text-3xl
                    font-medium
                  "
                  >Logout</span
                >
              </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 () {
      return this.$store.getters["User/userData"];
    },
    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 () {
      return this.$store.getters["User/userRole"];
    },
  },
  mounted: function () {
    const vm = this;

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

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

a:hover {
  color: #ef0087 !important;
  background-color: #a7ebfb;
}
.avatar {
  background-color: #a7ebfb;
}

.submenu span:hover {
  color: #ef0087 !important;
}
.submenu:hover {
  background-color: #a7ebfb;
  border-radius: 5px;
}
.submenu a:hover {
  color: #ef0087 !important;
  border-radius: 5px;
}

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