MainHeader.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. <router-link
  25. v-if="role === 'admin'"
  26. class="nav-item admin"
  27. to="/admin"
  28. >
  29. <strong>Admin</strong>
  30. </router-link>
  31. <span v-if="loggedIn" class="grouped">
  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" href="#" @click="logout()">Logout</a>
  45. </span>
  46. <span v-if="!loggedIn && !hideLoggedOut" class="grouped">
  47. <a class="nav-item" href="#" @click="openModal('login')"
  48. >Login</a
  49. >
  50. <a class="nav-item" href="#" @click="openModal('register')"
  51. >Register</a
  52. >
  53. </span>
  54. <div class="nav-item" id="nightmode-toggle">
  55. <p class="is-expanded checkbox-control">
  56. <label class="switch">
  57. <input
  58. type="checkbox"
  59. id="instant-nightmode"
  60. v-model="localNightmode"
  61. />
  62. <span class="slider round"></span>
  63. </label>
  64. <label for="instant-nightmode">
  65. <p>Nightmode</p>
  66. </label>
  67. </p>
  68. </div>
  69. </div>
  70. </nav>
  71. </template>
  72. <script>
  73. import Toast from "toasters";
  74. import { mapState, mapGetters, mapActions } from "vuex";
  75. import ws from "@/ws";
  76. export default {
  77. props: {
  78. hideLogo: { type: Boolean, default: false },
  79. transparent: { type: Boolean, default: false },
  80. hideLoggedOut: { type: Boolean, default: false }
  81. },
  82. data() {
  83. return {
  84. localNightmode: null,
  85. isMobile: false,
  86. frontendDomain: "",
  87. siteSettings: {
  88. logo: "",
  89. sitename: ""
  90. }
  91. };
  92. },
  93. computed: {
  94. ...mapState({
  95. modals: state => state.modalVisibility.modals.header,
  96. role: state => state.user.auth.role,
  97. loggedIn: state => state.user.auth.loggedIn,
  98. username: state => state.user.auth.username
  99. }),
  100. ...mapGetters({
  101. socket: "websockets/getSocket"
  102. })
  103. },
  104. watch: {
  105. localNightmode(newValue, oldValue) {
  106. if (oldValue === null) return;
  107. localStorage.setItem("nightmode", this.localNightmode);
  108. if (this.loggedIn) {
  109. this.socket.dispatch(
  110. "users.updatePreferences",
  111. { nightmode: this.localNightmode },
  112. res => {
  113. if (res.status !== "success") new Toast(res.message);
  114. }
  115. );
  116. }
  117. this.changeNightmode(this.localNightmode);
  118. }
  119. },
  120. async mounted() {
  121. this.localNightmode = JSON.parse(localStorage.getItem("nightmode"));
  122. if (this.localNightmode === null) this.localNightmode = false;
  123. ws.onConnect(this.init);
  124. this.socket.on("keep.event:user.preferences.updated", res => {
  125. if (res.data.preferences.nightmode !== undefined)
  126. this.localNightmode = res.data.preferences.nightmode;
  127. });
  128. this.frontendDomain = await lofig.get("frontendDomain");
  129. this.siteSettings = await lofig.get("siteSettings");
  130. },
  131. methods: {
  132. init() {
  133. this.socket.dispatch("users.getPreferences", res => {
  134. if (res.status === "success")
  135. this.localNightmode = res.data.preferences.nightmode;
  136. });
  137. },
  138. ...mapActions("modalVisibility", ["openModal"]),
  139. ...mapActions("user/auth", ["logout"]),
  140. ...mapActions("user/preferences", ["changeNightmode"])
  141. }
  142. };
  143. </script>
  144. <style lang="scss" scoped>
  145. .night-mode {
  146. .nav {
  147. background-color: var(--dark-grey-3) !important;
  148. }
  149. @media screen and (max-width: 768px) {
  150. .nav-menu {
  151. background-color: var(--dark-grey-3) !important;
  152. }
  153. .nav-item,
  154. .grouped {
  155. border-color: transparent;
  156. }
  157. }
  158. .nav-item {
  159. color: var(--light-grey-2) !important;
  160. }
  161. }
  162. .nav {
  163. flex-shrink: 0;
  164. background-color: var(--primary-color);
  165. height: 64px;
  166. border-radius: 0% 0% 33% 33% / 0% 0% 7% 7%;
  167. &.transparent {
  168. background-color: transparent !important;
  169. }
  170. @media (max-width: 650px) {
  171. border-radius: 0;
  172. }
  173. .nav-menu.is-active {
  174. .nav-item {
  175. color: var(--dark-grey-2);
  176. &:hover {
  177. color: var(--dark-grey-2);
  178. }
  179. }
  180. }
  181. a.nav-item.is-tab:hover {
  182. border-bottom: none;
  183. border-top: solid 1px var(--white);
  184. padding-top: 9px;
  185. }
  186. .nav-toggle {
  187. height: 64px;
  188. background-color: transparent;
  189. span {
  190. background-color: var(--white);
  191. }
  192. }
  193. .is-brand {
  194. font-size: 2.1rem !important;
  195. line-height: 38px !important;
  196. padding: 0 20px;
  197. font-family: Pacifico, cursive;
  198. img {
  199. max-height: 38px;
  200. color: var(--primary-color);
  201. user-select: none;
  202. }
  203. }
  204. .nav-item {
  205. font-size: 17px;
  206. color: var(--white);
  207. &:hover {
  208. color: var(--white);
  209. }
  210. }
  211. }
  212. .grouped {
  213. margin: 0;
  214. display: flex;
  215. text-decoration: none;
  216. border-top: 1px solid rgba(219, 219, 219, 0.5);
  217. .nav-item {
  218. border-top: 0;
  219. }
  220. }
  221. </style>