MainHeader.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. <template>
  2. <nav class="nav is-info" :class="{ transparent }">
  3. <div class="nav-left">
  4. <router-link v-if="!hideLogo" class="nav-item is-brand" to="/">
  5. <img
  6. :src="siteSettings.logo_white"
  7. :alt="siteSettings.sitename || `Musare`"
  8. />
  9. </router-link>
  10. </div>
  11. <span
  12. v-if="loggedIn || !hideLoggedOut"
  13. class="nav-toggle"
  14. :class="{ 'is-active': isMobile }"
  15. tabindex="0"
  16. @click="isMobile = !isMobile"
  17. @keyup.enter="isMobile = !isMobile"
  18. >
  19. <span />
  20. <span />
  21. <span />
  22. </span>
  23. <div class="nav-right nav-menu" :class="{ 'is-active': isMobile }">
  24. <span v-if="loggedIn" class="grouped">
  25. <router-link
  26. v-if="role === 'admin'"
  27. class="nav-item admin"
  28. to="/admin"
  29. >
  30. <strong>Admin</strong>
  31. </router-link>
  32. <router-link
  33. class="nav-item"
  34. :to="{
  35. name: 'profile',
  36. params: { username }
  37. }"
  38. >
  39. Profile
  40. </router-link>
  41. <router-link class="nav-item" to="/settings"
  42. >Settings</router-link
  43. >
  44. <a class="nav-item" @click="logout()">Logout</a>
  45. </span>
  46. <span v-if="!loggedIn && !hideLoggedOut" class="grouped">
  47. <a class="nav-item" @click="openModal('login')">Login</a>
  48. <a class="nav-item" @click="openModal('register')">Register</a>
  49. </span>
  50. <div class="nav-item" id="nightmode-toggle">
  51. <p class="is-expanded checkbox-control">
  52. <label class="switch">
  53. <input
  54. type="checkbox"
  55. id="instant-nightmode"
  56. v-model="localNightmode"
  57. />
  58. <span class="slider round"></span>
  59. </label>
  60. <label for="instant-nightmode">
  61. <p>Nightmode</p>
  62. </label>
  63. </p>
  64. </div>
  65. </div>
  66. <christmas-lights
  67. v-if="siteSettings.christmas"
  68. :lights="Math.min(Math.floor(windowWidth / 175), 15)"
  69. />
  70. </nav>
  71. </template>
  72. <script>
  73. import Toast from "toasters";
  74. import { mapState, mapGetters, mapActions } from "vuex";
  75. import { defineAsyncComponent } from "vue";
  76. export default {
  77. components: {
  78. ChristmasLights: defineAsyncComponent(() =>
  79. import("@/components/ChristmasLights.vue")
  80. )
  81. },
  82. props: {
  83. hideLogo: { type: Boolean, default: false },
  84. transparent: { type: Boolean, default: false },
  85. hideLoggedOut: { type: Boolean, default: false }
  86. },
  87. data() {
  88. return {
  89. localNightmode: null,
  90. isMobile: false,
  91. frontendDomain: "",
  92. siteSettings: {
  93. logo: "",
  94. sitename: "",
  95. christmas: false
  96. },
  97. windowWidth: 0
  98. };
  99. },
  100. computed: {
  101. ...mapState({
  102. modals: state => state.modalVisibility.modals.header,
  103. role: state => state.user.auth.role,
  104. loggedIn: state => state.user.auth.loggedIn,
  105. username: state => state.user.auth.username,
  106. nightmode: state => state.user.preferences.nightmode
  107. }),
  108. ...mapGetters({
  109. socket: "websockets/getSocket"
  110. })
  111. },
  112. watch: {
  113. localNightmode(newValue, oldValue) {
  114. if (oldValue === null) return;
  115. localStorage.setItem("nightmode", this.localNightmode);
  116. if (this.loggedIn) {
  117. this.socket.dispatch(
  118. "users.updatePreferences",
  119. { nightmode: this.localNightmode },
  120. res => {
  121. if (res.status !== "success") new Toast(res.message);
  122. }
  123. );
  124. }
  125. this.changeNightmode(this.localNightmode);
  126. },
  127. nightmode(nightmode) {
  128. if (this.localNightmode !== nightmode)
  129. this.localNightmode = nightmode;
  130. }
  131. },
  132. async mounted() {
  133. this.localNightmode = JSON.parse(localStorage.getItem("nightmode"));
  134. if (this.localNightmode === null) this.localNightmode = false;
  135. this.frontendDomain = await lofig.get("frontendDomain");
  136. this.siteSettings = await lofig.get("siteSettings");
  137. this.$nextTick(() => {
  138. this.onResize();
  139. window.addEventListener("resize", this.onResize);
  140. });
  141. },
  142. methods: {
  143. onResize() {
  144. this.windowWidth = window.innerWidth;
  145. },
  146. ...mapActions("modalVisibility", ["openModal"]),
  147. ...mapActions("user/auth", ["logout"]),
  148. ...mapActions("user/preferences", ["changeNightmode"])
  149. }
  150. };
  151. </script>
  152. <style lang="scss" scoped>
  153. .night-mode {
  154. .nav {
  155. background-color: var(--dark-grey-3) !important;
  156. }
  157. @media screen and (max-width: 768px) {
  158. .nav-menu {
  159. background-color: var(--dark-grey-3) !important;
  160. }
  161. }
  162. .nav-item {
  163. color: var(--light-grey-2) !important;
  164. }
  165. }
  166. .nav {
  167. flex-shrink: 0;
  168. display: flex;
  169. position: relative;
  170. background-color: var(--primary-color);
  171. height: 64px;
  172. border-radius: 0% 0% 33% 33% / 0% 0% 7% 7%;
  173. z-index: 2;
  174. &.transparent {
  175. background-color: transparent !important;
  176. }
  177. @media (max-width: 650px) {
  178. border-radius: 0;
  179. }
  180. .nav-left,
  181. .nav-right {
  182. flex: 1;
  183. display: flex;
  184. }
  185. .nav-right {
  186. justify-content: flex-end;
  187. }
  188. a.nav-item.is-tab:hover {
  189. border-bottom: none;
  190. border-top: solid 1px var(--white);
  191. padding-top: 9px;
  192. }
  193. .nav-toggle {
  194. height: 64px;
  195. width: 50px;
  196. position: relative;
  197. background-color: transparent;
  198. display: none;
  199. position: relative;
  200. cursor: pointer;
  201. &.is-active {
  202. span:nth-child(1) {
  203. margin-left: -5px;
  204. transform: rotate(45deg);
  205. transform-origin: left top;
  206. }
  207. span:nth-child(2) {
  208. opacity: 0;
  209. }
  210. span:nth-child(3) {
  211. margin-left: -5px;
  212. transform: rotate(-45deg);
  213. transform-origin: left bottom;
  214. }
  215. }
  216. span {
  217. background-color: var(--white);
  218. display: block;
  219. height: 1px;
  220. left: 50%;
  221. margin-left: -7px;
  222. position: absolute;
  223. top: 50%;
  224. width: 15px;
  225. transition: none 86ms ease-out;
  226. transition-property: opacity, transform;
  227. &:nth-child(1) {
  228. margin-top: -6px;
  229. }
  230. &:nth-child(2) {
  231. margin-top: -1px;
  232. }
  233. &:nth-child(3) {
  234. margin-top: 4px;
  235. }
  236. }
  237. }
  238. .nav-item {
  239. font-size: 17px;
  240. color: var(--white);
  241. border-top: 0;
  242. display: flex;
  243. align-items: center;
  244. padding: 10px;
  245. cursor: pointer;
  246. &:hover,
  247. &:focus {
  248. color: var(--white);
  249. }
  250. &.is-brand {
  251. font-size: 2.1rem !important;
  252. line-height: 38px !important;
  253. padding: 0 20px;
  254. font-family: Pacifico, cursive;
  255. display: flex;
  256. align-items: center;
  257. img {
  258. max-height: 38px;
  259. color: var(--primary-color);
  260. user-select: none;
  261. }
  262. }
  263. }
  264. .nav-menu {
  265. // box-shadow: 0 4px 7px rgb(10 10 10 / 10%);
  266. // left: 0;
  267. // display: block;
  268. // right: 0;
  269. // top: 100%;
  270. // position: absolute;
  271. // background: var(--white);
  272. }
  273. }
  274. .grouped {
  275. margin: 0;
  276. display: flex;
  277. text-decoration: none;
  278. .nav-item {
  279. &:hover,
  280. &:focus {
  281. border-top: 1px solid var(--white);
  282. height: calc(100% - 1px);
  283. }
  284. }
  285. }
  286. @media screen and (max-width: 768px) {
  287. .nav-toggle {
  288. display: block !important;
  289. }
  290. .nav-menu {
  291. display: none !important;
  292. box-shadow: 0 4px 7px rgba(10, 10, 10, 0.1);
  293. left: 0;
  294. right: 0;
  295. top: 100%;
  296. position: absolute;
  297. background: var(--white);
  298. }
  299. .nav-menu.is-active {
  300. display: block !important;
  301. .nav-item {
  302. color: var(--dark-grey-2);
  303. &:hover {
  304. color: var(--dark-grey-2);
  305. }
  306. }
  307. }
  308. .nav .nav-menu .grouped {
  309. flex-direction: column;
  310. .nav-item {
  311. padding: 10px 20px;
  312. &:hover,
  313. &:focus {
  314. border-top: 0;
  315. height: unset;
  316. }
  317. }
  318. }
  319. }
  320. </style>