MainHeader.vue 7.2 KB

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