123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374 |
- <script setup lang="ts">
- import { defineAsyncComponent, ref, onMounted, watch, nextTick } from "vue";
- import Toast from "toasters";
- import { storeToRefs } from "pinia";
- import { useWebsocketsStore } from "@/stores/websockets";
- import { useConfigStore } from "@/stores/config";
- import { useUserAuthStore } from "@/stores/userAuth";
- import { useUserPreferencesStore } from "@/stores/userPreferences";
- import { useModalsStore } from "@/stores/modals";
- const ChristmasLights = defineAsyncComponent(
- () => import("@/components/ChristmasLights.vue")
- );
- defineProps({
- hideLogo: { type: Boolean, default: false },
- transparent: { type: Boolean, default: false },
- hideLoggedOut: { type: Boolean, default: false }
- });
- const userAuthStore = useUserAuthStore();
- const localNightmode = ref(false);
- const isMobile = ref(false);
- const windowWidth = ref(0);
- const broadcastChannel = ref();
- const { socket } = useWebsocketsStore();
- const configStore = useConfigStore();
- const { cookie, sitename, registrationDisabled, christmas } =
- storeToRefs(configStore);
- const { loggedIn, username } = storeToRefs(userAuthStore);
- const { logout, hasPermission } = userAuthStore;
- const userPreferencesStore = useUserPreferencesStore();
- const { nightmode } = storeToRefs(userPreferencesStore);
- const { openModal } = useModalsStore();
- const toggleNightmode = toggle => {
- localNightmode.value =
- toggle === undefined ? !localNightmode.value : toggle;
- if (loggedIn.value) {
- socket.dispatch(
- "users.updatePreferences",
- { nightmode: localNightmode.value },
- res => {
- if (res.status !== "success") new Toast(res.message);
- }
- );
- } else {
- broadcastChannel.value.postMessage(localNightmode.value);
- }
- };
- const onResize = () => {
- windowWidth.value = window.innerWidth;
- };
- watch(nightmode, value => {
- localNightmode.value = value;
- });
- onMounted(async () => {
- localNightmode.value = nightmode.value;
- await nextTick();
- onResize();
- window.addEventListener("resize", onResize);
- broadcastChannel.value = new BroadcastChannel(`${cookie.value}.nightmode`);
- });
- </script>
- <template>
- <nav
- class="nav is-info"
- :class="{ transparent, 'hide-logged-out': !loggedIn && hideLoggedOut }"
- >
- <div class="nav-left">
- <router-link v-if="!hideLogo" class="nav-item is-brand" to="/">
- <img
- v-if="sitename === 'Musare'"
- src="/assets/white_wordmark.png"
- :alt="sitename"
- />
- <span v-else>{{ sitename }}</span>
- </router-link>
- </div>
- <span
- v-if="loggedIn || !hideLoggedOut"
- class="nav-toggle"
- :class="{ 'is-active': isMobile }"
- tabindex="0"
- @click="isMobile = !isMobile"
- @keyup.enter="isMobile = !isMobile"
- >
- <span />
- <span />
- <span />
- </span>
- <div class="nav-right nav-menu" :class="{ 'is-active': isMobile }">
- <div
- class="nav-item"
- id="nightmode-toggle"
- @click="toggleNightmode(!localNightmode)"
- >
- <span
- :class="{
- 'material-icons': true,
- 'night-mode-toggle': true,
- 'night-mode-on': localNightmode
- }"
- :content="`${
- localNightmode ? 'Disable' : 'Enable'
- } Nightmode`"
- v-tippy
- >
- {{ localNightmode ? "dark_mode" : "light_mode" }}
- </span>
- <span class="night-mode-label">Toggle Nightmode</span>
- </div>
- <span v-if="loggedIn" class="grouped">
- <router-link
- v-if="hasPermission('admin.view')"
- class="nav-item admin"
- to="/admin"
- >
- <strong>Admin</strong>
- </router-link>
- <router-link
- class="nav-item"
- :to="{
- name: 'profile',
- params: { username },
- query: { tab: 'playlists' }
- }"
- >
- Playlists
- </router-link>
- <router-link
- class="nav-item"
- :to="{
- name: 'profile',
- params: { username }
- }"
- >
- Profile
- </router-link>
- <router-link class="nav-item" to="/settings"
- >Settings</router-link
- >
- <a class="nav-item" @click="logout()">Logout</a>
- </span>
- <span v-if="!loggedIn && !hideLoggedOut" class="grouped">
- <a class="nav-item" @click="openModal('login')">Login</a>
- <a
- v-if="!registrationDisabled"
- class="nav-item"
- @click="openModal('register')"
- >Register</a
- >
- </span>
- </div>
- <christmas-lights
- v-if="christmas"
- :lights="Math.min(Math.max(Math.floor(windowWidth / 175), 5), 15)"
- />
- </nav>
- </template>
- <style lang="less" scoped>
- .night-mode {
- .nav {
- background-color: var(--dark-grey-3) !important;
- }
- @media screen and (max-width: 768px) {
- .nav:not(.hide-logged-out) .nav-menu {
- background-color: var(--dark-grey-3) !important;
- }
- }
- .nav-item {
- color: var(--light-grey-2) !important;
- }
- }
- .nav {
- flex-shrink: 0;
- display: flex;
- position: relative;
- background-color: var(--primary-color);
- height: 64px;
- z-index: 100;
- &.transparent {
- background-color: transparent !important;
- }
- .nav-left,
- .nav-right {
- flex: 1;
- display: flex;
- }
- .nav-right {
- justify-content: flex-end;
- }
- a.nav-item.is-tab:hover {
- border-bottom: none;
- border-top: solid 1px var(--white);
- padding-top: 9px;
- }
- .nav-toggle {
- height: 64px;
- width: 50px;
- position: relative;
- background-color: transparent;
- display: none;
- position: relative;
- cursor: pointer;
- &.is-active {
- span:nth-child(1) {
- margin-left: -5px;
- transform: rotate(45deg);
- transform-origin: left top;
- }
- span:nth-child(2) {
- opacity: 0;
- }
- span:nth-child(3) {
- margin-left: -5px;
- transform: rotate(-45deg);
- transform-origin: left bottom;
- }
- }
- span {
- background-color: var(--white) !important;
- display: block;
- height: 1px;
- left: 50%;
- margin-left: -7px;
- position: absolute;
- top: 50%;
- width: 15px;
- transition: none 86ms ease-out;
- transition-property: opacity, transform;
- &:nth-child(1) {
- margin-top: -6px;
- }
- &:nth-child(2) {
- margin-top: -1px;
- }
- &:nth-child(3) {
- margin-top: 4px;
- }
- }
- }
- .nav-item {
- font-size: 17px;
- color: var(--white);
- border-top: 0;
- display: flex;
- align-items: center;
- padding: 10px;
- cursor: pointer;
- &:hover,
- &:focus {
- color: var(--white);
- }
- &.is-brand {
- font-size: 2.1rem !important;
- line-height: 38px !important;
- padding: 0 20px;
- font-family: Pacifico, cursive;
- display: flex;
- align-items: center;
- img {
- max-height: 38px;
- color: var(--primary-color);
- user-select: none;
- -webkit-user-drag: none;
- }
- }
- .night-mode-label {
- display: none;
- }
- }
- }
- .grouped {
- margin: 0;
- display: flex;
- text-decoration: none;
- .nav-item {
- &:hover,
- &:focus {
- border-top: 1px solid var(--white);
- height: calc(100% - 1px);
- }
- }
- }
- @media screen and (max-width: 768px) {
- .nav:not(.hide-logged-out) {
- .nav-toggle {
- display: block !important;
- }
- .nav-menu {
- display: none !important;
- box-shadow: @box-shadow-dropdown;
- left: 0;
- right: 0;
- top: 100%;
- position: absolute;
- background: var(--white);
- z-index: 100;
- }
- .nav-menu.is-active {
- display: flex !important;
- flex-direction: column-reverse;
- .nav-item {
- color: var(--dark-grey-2);
- &:hover {
- color: var(--dark-grey-2);
- }
- .night-mode-label {
- display: inline;
- margin-left: 5px;
- }
- }
- }
- .nav-menu {
- .grouped {
- flex-direction: column;
- }
- .nav-item {
- padding: 10px 20px;
- &:hover,
- &:focus {
- border-top: 0;
- height: unset;
- }
- }
- }
- }
- }
- </style>
|