MainHeader.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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. <div
  67. v-if="siteSettings.christmas"
  68. :class="{ 'christmas-lights': true, loggedIn }"
  69. >
  70. <div class="christmas-wire"></div>
  71. <span class="christmas-light"></span>
  72. <div class="christmas-wire"></div>
  73. <span class="christmas-light"></span>
  74. <div class="christmas-wire"></div>
  75. <span class="christmas-light"></span>
  76. <div class="christmas-wire"></div>
  77. <span class="christmas-light"></span>
  78. <div class="christmas-wire"></div>
  79. <span class="christmas-light"></span>
  80. <div class="christmas-wire"></div>
  81. <span class="christmas-light"></span>
  82. <div class="christmas-wire"></div>
  83. <span class="christmas-light"></span>
  84. <div class="christmas-wire"></div>
  85. <span class="christmas-light"></span>
  86. <div class="christmas-wire"></div>
  87. <span class="christmas-light"></span>
  88. <div class="christmas-wire"></div>
  89. <span class="christmas-light"></span>
  90. <div class="christmas-wire"></div>
  91. </div>
  92. </nav>
  93. </template>
  94. <script>
  95. import Toast from "toasters";
  96. import { mapState, mapGetters, mapActions } from "vuex";
  97. export default {
  98. props: {
  99. hideLogo: { type: Boolean, default: false },
  100. transparent: { type: Boolean, default: false },
  101. hideLoggedOut: { type: Boolean, default: false }
  102. },
  103. data() {
  104. return {
  105. localNightmode: null,
  106. isMobile: false,
  107. frontendDomain: "",
  108. siteSettings: {
  109. logo: "",
  110. sitename: ""
  111. }
  112. };
  113. },
  114. computed: {
  115. ...mapState({
  116. modals: state => state.modalVisibility.modals.header,
  117. role: state => state.user.auth.role,
  118. loggedIn: state => state.user.auth.loggedIn,
  119. username: state => state.user.auth.username,
  120. nightmode: state => state.user.preferences.nightmode
  121. }),
  122. ...mapGetters({
  123. socket: "websockets/getSocket"
  124. })
  125. },
  126. watch: {
  127. localNightmode(newValue, oldValue) {
  128. if (oldValue === null) return;
  129. localStorage.setItem("nightmode", this.localNightmode);
  130. if (this.loggedIn) {
  131. this.socket.dispatch(
  132. "users.updatePreferences",
  133. { nightmode: this.localNightmode },
  134. res => {
  135. if (res.status !== "success") new Toast(res.message);
  136. }
  137. );
  138. }
  139. this.changeNightmode(this.localNightmode);
  140. },
  141. nightmode(nightmode) {
  142. if (this.localNightmode !== nightmode)
  143. this.localNightmode = nightmode;
  144. }
  145. },
  146. async mounted() {
  147. this.localNightmode = JSON.parse(localStorage.getItem("nightmode"));
  148. if (this.localNightmode === null) this.localNightmode = false;
  149. this.frontendDomain = await lofig.get("frontendDomain");
  150. this.siteSettings = await lofig.get("siteSettings");
  151. },
  152. methods: {
  153. ...mapActions("modalVisibility", ["openModal"]),
  154. ...mapActions("user/auth", ["logout"]),
  155. ...mapActions("user/preferences", ["changeNightmode"])
  156. }
  157. };
  158. </script>
  159. <style lang="scss" scoped>
  160. .night-mode {
  161. .nav {
  162. background-color: var(--dark-grey-3) !important;
  163. }
  164. @media screen and (max-width: 768px) {
  165. .nav-menu {
  166. background-color: var(--dark-grey-3) !important;
  167. }
  168. }
  169. .nav-item {
  170. color: var(--light-grey-2) !important;
  171. }
  172. }
  173. .nav {
  174. flex-shrink: 0;
  175. display: flex;
  176. position: relative;
  177. background-color: var(--primary-color);
  178. height: 64px;
  179. border-radius: 0% 0% 33% 33% / 0% 0% 7% 7%;
  180. z-index: 2;
  181. &.transparent {
  182. background-color: transparent !important;
  183. }
  184. @media (max-width: 650px) {
  185. border-radius: 0;
  186. }
  187. .nav-left,
  188. .nav-right {
  189. flex: 1;
  190. display: flex;
  191. }
  192. .nav-right {
  193. justify-content: flex-end;
  194. }
  195. a.nav-item.is-tab:hover {
  196. border-bottom: none;
  197. border-top: solid 1px var(--white);
  198. padding-top: 9px;
  199. }
  200. .nav-toggle {
  201. height: 64px;
  202. width: 50px;
  203. position: relative;
  204. background-color: transparent;
  205. display: none;
  206. position: relative;
  207. cursor: pointer;
  208. &.is-active {
  209. span:nth-child(1) {
  210. margin-left: -5px;
  211. transform: rotate(45deg);
  212. transform-origin: left top;
  213. }
  214. span:nth-child(2) {
  215. opacity: 0;
  216. }
  217. span:nth-child(3) {
  218. margin-left: -5px;
  219. transform: rotate(-45deg);
  220. transform-origin: left bottom;
  221. }
  222. }
  223. span {
  224. background-color: var(--white);
  225. display: block;
  226. height: 1px;
  227. left: 50%;
  228. margin-left: -7px;
  229. position: absolute;
  230. top: 50%;
  231. width: 15px;
  232. transition: none 86ms ease-out;
  233. transition-property: opacity, transform;
  234. &:nth-child(1) {
  235. margin-top: -6px;
  236. }
  237. &:nth-child(2) {
  238. margin-top: -1px;
  239. }
  240. &:nth-child(3) {
  241. margin-top: 4px;
  242. }
  243. }
  244. }
  245. .nav-item {
  246. font-size: 17px;
  247. color: var(--white);
  248. border-top: 0;
  249. display: flex;
  250. align-items: center;
  251. padding: 10px;
  252. cursor: pointer;
  253. &:hover,
  254. &:focus {
  255. color: var(--white);
  256. }
  257. &.is-brand {
  258. font-size: 2.1rem !important;
  259. line-height: 38px !important;
  260. padding: 0 20px;
  261. font-family: Pacifico, cursive;
  262. display: flex;
  263. align-items: center;
  264. img {
  265. max-height: 38px;
  266. color: var(--primary-color);
  267. user-select: none;
  268. }
  269. }
  270. }
  271. .nav-menu {
  272. // box-shadow: 0 4px 7px rgb(10 10 10 / 10%);
  273. // left: 0;
  274. // display: block;
  275. // right: 0;
  276. // top: 100%;
  277. // position: absolute;
  278. // background: var(--white);
  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-toggle {
  295. display: block !important;
  296. }
  297. .nav-menu {
  298. display: none !important;
  299. box-shadow: 0 4px 7px rgba(10, 10, 10, 0.1);
  300. left: 0;
  301. right: 0;
  302. top: 100%;
  303. position: absolute;
  304. background: var(--white);
  305. }
  306. .nav-menu.is-active {
  307. display: block !important;
  308. .nav-item {
  309. color: var(--dark-grey-2);
  310. &:hover {
  311. color: var(--dark-grey-2);
  312. }
  313. }
  314. }
  315. .nav .nav-menu .grouped {
  316. flex-direction: column;
  317. .nav-item {
  318. padding: 10px 20px;
  319. &:hover,
  320. &:focus {
  321. border-top: 0;
  322. height: unset;
  323. }
  324. }
  325. }
  326. }
  327. </style>