index.vue 7.9 KB

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