MainHeader.vue 5.6 KB

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