index.vue 7.8 KB

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