MainHeader.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  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 { mapState, mapGetters, mapActions } from "vuex";
  89. import { defineAsyncComponent } from "vue";
  90. import Toast from "toasters";
  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.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. toggleNightmode(toggle) {
  144. this.localNightmode = toggle || !this.localNightmode;
  145. localStorage.setItem("nightmode", this.localNightmode);
  146. if (this.loggedIn) {
  147. this.socket.dispatch(
  148. "users.updatePreferences",
  149. { nightmode: this.localNightmode },
  150. res => {
  151. if (res.status !== "success") new Toast(res.message);
  152. }
  153. );
  154. }
  155. this.changeNightmode(this.localNightmode);
  156. },
  157. onResize() {
  158. this.windowWidth = window.innerWidth;
  159. },
  160. ...mapActions("modalVisibility", ["openModal"]),
  161. ...mapActions("user/auth", ["logout"])
  162. }
  163. };
  164. </script>
  165. <style lang="less" scoped>
  166. .night-mode {
  167. .nav {
  168. background-color: var(--dark-grey-3) !important;
  169. }
  170. @media screen and (max-width: 768px) {
  171. .nav:not(.hide-logged-out) .nav-menu {
  172. background-color: var(--dark-grey-3) !important;
  173. }
  174. }
  175. .nav-item {
  176. color: var(--light-grey-2) !important;
  177. }
  178. }
  179. .nav {
  180. flex-shrink: 0;
  181. display: flex;
  182. position: relative;
  183. background-color: var(--primary-color);
  184. height: 64px;
  185. z-index: 3;
  186. &.transparent {
  187. background-color: transparent !important;
  188. }
  189. .nav-left,
  190. .nav-right {
  191. flex: 1;
  192. display: flex;
  193. }
  194. .nav-right {
  195. justify-content: flex-end;
  196. }
  197. a.nav-item.is-tab:hover {
  198. border-bottom: none;
  199. border-top: solid 1px var(--white);
  200. padding-top: 9px;
  201. }
  202. .nav-toggle {
  203. height: 64px;
  204. width: 50px;
  205. position: relative;
  206. background-color: transparent;
  207. display: none;
  208. position: relative;
  209. cursor: pointer;
  210. &.is-active {
  211. span:nth-child(1) {
  212. margin-left: -5px;
  213. transform: rotate(45deg);
  214. transform-origin: left top;
  215. }
  216. span:nth-child(2) {
  217. opacity: 0;
  218. }
  219. span:nth-child(3) {
  220. margin-left: -5px;
  221. transform: rotate(-45deg);
  222. transform-origin: left bottom;
  223. }
  224. }
  225. span {
  226. background-color: var(--white);
  227. display: block;
  228. height: 1px;
  229. left: 50%;
  230. margin-left: -7px;
  231. position: absolute;
  232. top: 50%;
  233. width: 15px;
  234. transition: none 86ms ease-out;
  235. transition-property: opacity, transform;
  236. &:nth-child(1) {
  237. margin-top: -6px;
  238. }
  239. &:nth-child(2) {
  240. margin-top: -1px;
  241. }
  242. &:nth-child(3) {
  243. margin-top: 4px;
  244. }
  245. }
  246. }
  247. .nav-item {
  248. font-size: 17px;
  249. color: var(--white);
  250. border-top: 0;
  251. display: flex;
  252. align-items: center;
  253. padding: 10px;
  254. cursor: pointer;
  255. &:hover,
  256. &:focus {
  257. color: var(--white);
  258. }
  259. &.is-brand {
  260. font-size: 2.1rem !important;
  261. line-height: 38px !important;
  262. padding: 0 20px;
  263. font-family: Pacifico, cursive;
  264. display: flex;
  265. align-items: center;
  266. img {
  267. max-height: 38px;
  268. color: var(--primary-color);
  269. user-select: none;
  270. -webkit-user-drag: none;
  271. }
  272. }
  273. .night-mode-label {
  274. display: none;
  275. }
  276. }
  277. }
  278. .grouped {
  279. margin: 0;
  280. display: flex;
  281. text-decoration: none;
  282. .nav-item {
  283. &:hover,
  284. &:focus {
  285. border-top: 1px solid var(--white);
  286. height: calc(100% - 1px);
  287. }
  288. }
  289. }
  290. @media screen and (max-width: 768px) {
  291. .nav:not(.hide-logged-out) {
  292. .nav-toggle {
  293. display: block !important;
  294. }
  295. .nav-menu {
  296. display: none !important;
  297. box-shadow: @box-shadow-dropdown;
  298. left: 0;
  299. right: 0;
  300. top: 100%;
  301. position: absolute;
  302. background: var(--white);
  303. }
  304. .nav-menu.is-active {
  305. display: flex !important;
  306. flex-direction: column-reverse;
  307. .nav-item {
  308. color: var(--dark-grey-2);
  309. &:hover {
  310. color: var(--dark-grey-2);
  311. }
  312. .night-mode-label {
  313. display: inline;
  314. margin-left: 5px;
  315. }
  316. }
  317. }
  318. .nav-menu {
  319. .grouped {
  320. flex-direction: column;
  321. }
  322. .nav-item {
  323. padding: 10px 20px;
  324. &:hover,
  325. &:focus {
  326. border-top: 0;
  327. height: unset;
  328. }
  329. }
  330. }
  331. }
  332. }
  333. </style>