index.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. <script setup lang="ts">
  2. import { defineAsyncComponent, ref, onMounted } from "vue";
  3. import { useRoute, useRouter } from "vue-router";
  4. import { format, parseISO } from "date-fns";
  5. import { storeToRefs } from "pinia";
  6. import { useWebsocketsStore } from "@/stores/websockets";
  7. import { useUserAuthStore } from "@/stores/userAuth";
  8. import ws from "@/ws";
  9. import { useTabQueryHandler } from "@/composables/useTabQueryHandler";
  10. const ProfilePicture = defineAsyncComponent(
  11. () => import("@/components/ProfilePicture.vue")
  12. );
  13. const RecentActivity = defineAsyncComponent(
  14. () => import("./Tabs/RecentActivity.vue")
  15. );
  16. const Playlists = defineAsyncComponent(() => import("./Tabs/Playlists.vue"));
  17. const route = useRoute();
  18. const router = useRouter();
  19. const { tab, showTab } = useTabQueryHandler("recent-activity");
  20. const { socket } = useWebsocketsStore();
  21. const user = ref();
  22. const userId = ref("");
  23. const isUser = ref(false);
  24. const userAuthStore = useUserAuthStore();
  25. const { userId: myUserId } = storeToRefs(userAuthStore);
  26. const { hasPermission } = userAuthStore;
  27. const init = () => {
  28. socket.dispatch("users.getBasicUser", route.params.username, res => {
  29. if (res.status === "error") router.push("/404");
  30. else {
  31. user.value = res.data;
  32. user.value.createdAt = format(
  33. parseISO(user.value.createdAt),
  34. "MMMM do yyyy"
  35. );
  36. isUser.value = true;
  37. userId.value = user.value._id;
  38. }
  39. });
  40. };
  41. onMounted(() => {
  42. if (
  43. route.query.tab === "recent-activity" ||
  44. route.query.tab === "playlists"
  45. )
  46. tab.value = route.query.tab;
  47. ws.onConnect(init);
  48. });
  49. </script>
  50. <template>
  51. <div v-if="isUser">
  52. <page-metadata :title="`Profile | ${user.username}`" />
  53. <main-header />
  54. <div class="container">
  55. <div class="info-section">
  56. <div class="picture-name-row">
  57. <profile-picture
  58. :avatar="user.avatar"
  59. :name="user.name ? user.name : user.username"
  60. />
  61. <div>
  62. <div class="name-row" v-if="user.name">
  63. <p class="name">{{ user.name }}</p>
  64. <span
  65. class="role admin"
  66. v-if="user.role === 'admin'"
  67. >admin</span
  68. >
  69. </div>
  70. <div class="username-row">
  71. <h2 class="username">@{{ user.username }}</h2>
  72. <span
  73. class="role admin"
  74. v-if="user.role === 'admin' && !user.name"
  75. >admin</span
  76. >
  77. </div>
  78. </div>
  79. </div>
  80. <div
  81. class="buttons"
  82. v-if="
  83. myUserId === userId || hasPermission('admin.view.users')
  84. "
  85. >
  86. <router-link
  87. :to="`/admin/users?userId=${user._id}`"
  88. class="button is-primary"
  89. v-if="hasPermission('admin.view.users')"
  90. >
  91. Edit
  92. </router-link>
  93. <router-link
  94. to="/settings"
  95. class="button is-primary"
  96. v-if="myUserId === userId"
  97. >
  98. Settings
  99. </router-link>
  100. </div>
  101. <div class="bio-row" v-if="user.bio">
  102. <i class="material-icons">notes</i>
  103. <p>{{ user.bio }}</p>
  104. </div>
  105. <div
  106. class="date-location-row"
  107. v-if="user.createdAt || user.location"
  108. >
  109. <div class="date" v-if="user.createdAt">
  110. <i
  111. class="material-icons"
  112. content="Account Creation Date"
  113. v-tippy="{ theme: 'info' }"
  114. >calendar_today</i
  115. >
  116. <p>{{ user.createdAt }}</p>
  117. </div>
  118. <div class="location" v-if="user.location">
  119. <i class="material-icons">location_on</i>
  120. <p>{{ user.location }}</p>
  121. </div>
  122. </div>
  123. </div>
  124. <div class="bottom-section">
  125. <div class="buttons">
  126. <button
  127. :class="{ active: tab === 'recent-activity' }"
  128. @click="showTab('recent-activity')"
  129. >
  130. Recent activity
  131. </button>
  132. <button
  133. :class="{ active: tab === 'playlists' }"
  134. @click="showTab('playlists')"
  135. >
  136. Playlists
  137. </button>
  138. </div>
  139. <playlists
  140. :user-id="userId"
  141. :username="user.name"
  142. v-show="tab === 'playlists'"
  143. />
  144. <recent-activity
  145. :user-id="userId"
  146. v-show="tab === 'recent-activity'"
  147. />
  148. </div>
  149. </div>
  150. <main-footer />
  151. </div>
  152. </template>
  153. <style lang="less" scoped>
  154. @media only screen and (max-width: 1250px) {
  155. .bottom-section .content {
  156. width: 650px !important;
  157. }
  158. }
  159. @media only screen and (max-width: 900px) {
  160. .info-section {
  161. margin-top: 0 !important;
  162. .picture-name-row {
  163. flex-direction: column !important;
  164. .profile-picture {
  165. margin-right: 0 !important;
  166. }
  167. }
  168. .name-row {
  169. margin-top: 24px;
  170. }
  171. .username-row {
  172. justify-content: center;
  173. }
  174. .buttons .button:not(:last-of-type) {
  175. margin-bottom: 10px;
  176. margin-right: 5px;
  177. }
  178. .date-location-row {
  179. flex-direction: column;
  180. width: auto !important;
  181. row-gap: 24px;
  182. .date,
  183. .location {
  184. justify-content: center;
  185. }
  186. }
  187. .date-location-row > div:nth-child(2),
  188. .buttons .button:nth-child(2) {
  189. margin-left: 0 !important;
  190. }
  191. }
  192. .bottom-section {
  193. flex-direction: column;
  194. .buttons,
  195. .content {
  196. margin-left: auto;
  197. margin-right: auto !important;
  198. }
  199. }
  200. .content {
  201. margin: 24px 0;
  202. }
  203. }
  204. .info-section {
  205. width: 912px;
  206. max-width: 100%;
  207. margin-left: auto;
  208. margin-right: auto;
  209. margin-top: 32px;
  210. padding: 24px;
  211. .picture-name-row {
  212. display: flex;
  213. flex-direction: row;
  214. align-items: center;
  215. justify-content: center;
  216. margin-bottom: 24px;
  217. .profile-picture {
  218. margin-right: 32px;
  219. }
  220. }
  221. .name-row,
  222. .username-row {
  223. display: flex;
  224. flex-direction: row;
  225. align-items: center;
  226. }
  227. .name {
  228. font-size: 34px;
  229. line-height: 40px;
  230. color: var(--dark-grey-4);
  231. }
  232. .role {
  233. padding: 2px 24px;
  234. color: var(--white);
  235. text-transform: uppercase;
  236. font-size: 12px;
  237. line-height: 14px;
  238. height: 18px;
  239. border-radius: @border-radius;
  240. margin-left: 12px;
  241. &.admin {
  242. background-color: var(--dark-red);
  243. }
  244. }
  245. .username {
  246. font-size: 24px;
  247. line-height: 28px;
  248. color: var(--dark-grey);
  249. margin: 0;
  250. }
  251. .buttons {
  252. width: 388px;
  253. max-width: 100%;
  254. display: flex;
  255. flex-direction: row;
  256. margin-left: auto;
  257. margin-right: auto;
  258. margin-bottom: 24px;
  259. .button {
  260. flex: 1;
  261. font-size: 17px;
  262. line-height: 20px;
  263. &:nth-child(2) {
  264. margin-left: 20px;
  265. }
  266. }
  267. }
  268. .bio-row,
  269. .date-location-row {
  270. i {
  271. font-size: 24px;
  272. color: var(--dark-grey-2);
  273. margin-right: 12px;
  274. }
  275. p {
  276. font-size: 17px;
  277. line-height: 20px;
  278. color: var(--dark-grey-2);
  279. word-break: break-word;
  280. }
  281. }
  282. .bio-row {
  283. max-width: 608px;
  284. margin-bottom: 24px;
  285. margin-left: auto;
  286. margin-right: auto;
  287. display: flex;
  288. width: max-content;
  289. }
  290. .date-location-row {
  291. max-width: 608px;
  292. margin-left: auto;
  293. margin-right: auto;
  294. margin-bottom: 24px;
  295. display: flex;
  296. width: max-content;
  297. margin-bottom: 24px;
  298. > div:nth-child(2) {
  299. margin-left: 48px;
  300. }
  301. }
  302. .date,
  303. .location {
  304. display: flex;
  305. }
  306. }
  307. .bottom-section {
  308. max-width: 100%;
  309. margin-left: auto;
  310. margin-right: auto;
  311. padding: 24px;
  312. display: flex;
  313. .buttons {
  314. height: 100%;
  315. width: 250px;
  316. margin-right: 64px;
  317. button {
  318. outline: none;
  319. border: none;
  320. box-shadow: 0;
  321. color: var(--primary-color);
  322. font-size: 22px;
  323. line-height: 26px;
  324. padding: 7px 0 7px 12px;
  325. width: 100%;
  326. text-align: left;
  327. cursor: pointer;
  328. border-radius: @border-radius;
  329. background-color: transparent;
  330. &.active {
  331. color: var(--white);
  332. background-color: var(--primary-color);
  333. }
  334. }
  335. }
  336. :deep(.content) {
  337. width: 800px;
  338. max-width: 100%;
  339. background-color: var(--white);
  340. padding: 30px 50px;
  341. border-radius: @border-radius;
  342. box-shadow: @box-shadow;
  343. h3 {
  344. font-weight: 400;
  345. }
  346. .item {
  347. overflow: hidden;
  348. &:not(:last-of-type) {
  349. margin-bottom: 10px;
  350. }
  351. }
  352. #create-new-playlist-button {
  353. margin-top: 30px;
  354. width: 100%;
  355. }
  356. }
  357. }
  358. .night-mode {
  359. .name,
  360. .username,
  361. .bio-row i,
  362. .bio-row p,
  363. .date-location-row i,
  364. .date-location-row p,
  365. .item .left-part .top-text,
  366. .item .left-part .bottom-text,
  367. .bottom-section
  368. .content
  369. .item.activity-item
  370. .thumbnail
  371. .activity-type-icon {
  372. color: var(--light-grey-2);
  373. }
  374. :deep(.content) {
  375. box-shadow: 0;
  376. }
  377. }
  378. </style>