MainHeader.vue 6.4 KB

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