index.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <template>
  2. <div>
  3. <page-metadata title="Settings" />
  4. <main-header />
  5. <div class="container">
  6. <h1 id="page-title">Settings</h1>
  7. <div id="sidebar-with-content">
  8. <div class="nav-links">
  9. <a
  10. :class="{ active: tab === 'profile' }"
  11. @click="showTab('profile')"
  12. >
  13. Profile
  14. </a>
  15. <a
  16. :class="{ active: tab === 'account' }"
  17. @click="showTab('account')"
  18. >
  19. Account
  20. </a>
  21. <a
  22. :class="{ active: tab === 'security' }"
  23. @click="showTab('security')"
  24. >
  25. Security
  26. </a>
  27. <a
  28. :class="{ active: tab === 'preferences' }"
  29. @click="showTab('preferences')"
  30. >
  31. Preferences
  32. </a>
  33. </div>
  34. <profile-settings v-if="tab === 'profile'"></profile-settings>
  35. <account-settings v-if="tab === 'account'"></account-settings>
  36. <security-settings
  37. v-if="tab === 'security'"
  38. ></security-settings>
  39. <preferences-settings
  40. v-if="tab === 'preferences'"
  41. ></preferences-settings>
  42. </div>
  43. </div>
  44. <main-footer />
  45. <remove-account v-if="modals.removeAccount" />
  46. </div>
  47. </template>
  48. <script>
  49. import { mapActions, mapGetters, mapState } from "vuex";
  50. import { defineAsyncComponent } from "vue";
  51. import Toast from "toasters";
  52. import ws from "@/ws";
  53. import TabQueryHandler from "@/mixins/TabQueryHandler.vue";
  54. import MainHeader from "@/components/layout/MainHeader.vue";
  55. import MainFooter from "@/components/layout/MainFooter.vue";
  56. export default {
  57. components: {
  58. MainHeader,
  59. MainFooter,
  60. SecuritySettings: defineAsyncComponent(() =>
  61. import("./Tabs/Security.vue")
  62. ),
  63. AccountSettings: defineAsyncComponent(() =>
  64. import("./Tabs/Account.vue")
  65. ),
  66. ProfileSettings: defineAsyncComponent(() =>
  67. import("./Tabs/Profile.vue")
  68. ),
  69. PreferencesSettings: defineAsyncComponent(() =>
  70. import("./Tabs/Preferences.vue")
  71. ),
  72. RemoveAccount: defineAsyncComponent(() =>
  73. import("@/components/modals/RemoveAccount.vue")
  74. )
  75. },
  76. mixins: [TabQueryHandler],
  77. data() {
  78. return {
  79. tab: ""
  80. };
  81. },
  82. computed: {
  83. ...mapGetters({
  84. socket: "websockets/getSocket"
  85. }),
  86. ...mapState("modalVisibility", {
  87. modals: state => state.modals
  88. })
  89. },
  90. mounted() {
  91. if (
  92. this.$route.query.tab === "profile" ||
  93. this.$route.query.tab === "security" ||
  94. this.$route.query.tab === "account" ||
  95. this.$route.query.tab === "preferences"
  96. )
  97. this.tab = this.$route.query.tab;
  98. else this.tab = "profile";
  99. this.localNightmode = this.nightmode;
  100. ws.onConnect(this.init);
  101. this.socket.on("event:user.password.linked", () =>
  102. this.updateOriginalUser({
  103. property: "password",
  104. value: true
  105. })
  106. );
  107. this.socket.on("event:user.password.unlinked", () =>
  108. this.updateOriginalUser({
  109. property: "password",
  110. value: false
  111. })
  112. );
  113. this.socket.on("event:user.github.linked", () =>
  114. this.updateOriginalUser({
  115. property: "github",
  116. value: true
  117. })
  118. );
  119. this.socket.on("event:user.github.unlinked", () =>
  120. this.updateOriginalUser({
  121. property: "github",
  122. value: false
  123. })
  124. );
  125. },
  126. methods: {
  127. init() {
  128. this.socket.dispatch("users.findBySession", res => {
  129. if (res.status === "success") this.setUser(res.data.user);
  130. else new Toast("You're not currently signed in.");
  131. });
  132. },
  133. ...mapActions("settings", ["updateOriginalUser", "setUser"])
  134. }
  135. };
  136. </script>
  137. <style lang="less" scoped>
  138. .night-mode {
  139. .container .content {
  140. box-shadow: 0 !important;
  141. }
  142. }
  143. /deep/ .character-counter {
  144. display: flex;
  145. justify-content: flex-end;
  146. height: 0;
  147. }
  148. .container {
  149. margin-top: 32px;
  150. padding: 24px;
  151. /deep/ .row {
  152. *:not(:last-child) {
  153. margin-right: 5px;
  154. }
  155. }
  156. .content {
  157. background-color: var(--white);
  158. padding: 30px 50px;
  159. border-radius: @border-radius;
  160. box-shadow: @box-shadow;
  161. }
  162. #sidebar-with-content {
  163. display: flex;
  164. flex-direction: column;
  165. }
  166. @media only screen and (min-width: 700px) {
  167. #sidebar-with-content {
  168. width: 962px;
  169. max-width: 100%;
  170. margin: 0 auto;
  171. flex-direction: row;
  172. .nav-links {
  173. margin-left: 0;
  174. margin-right: 64px;
  175. }
  176. .content {
  177. width: 600px;
  178. margin-top: 0px !important;
  179. }
  180. }
  181. }
  182. .nav-links {
  183. width: 250px;
  184. margin-left: auto;
  185. margin-right: auto;
  186. a {
  187. outline: none;
  188. border: none;
  189. box-shadow: 0;
  190. color: var(--primary-color);
  191. font-size: 22px;
  192. line-height: 26px;
  193. padding: 7px 0 7px 12px;
  194. width: 100%;
  195. text-align: left;
  196. cursor: pointer;
  197. border-radius: @border-radius;
  198. background-color: transparent;
  199. display: inline-block;
  200. &.active {
  201. color: var(--white);
  202. background-color: var(--primary-color);
  203. }
  204. }
  205. }
  206. /deep/ .content {
  207. margin: 24px 0;
  208. height: fit-content;
  209. .control:not(:first-of-type) {
  210. margin: 10px 0;
  211. }
  212. label {
  213. font-size: 14px;
  214. color: var(--dark-grey-2);
  215. }
  216. textarea {
  217. height: 96px;
  218. }
  219. button {
  220. width: 100%;
  221. margin-top: 30px;
  222. }
  223. }
  224. }
  225. </style>