Show.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. <template>
  2. <div v-if="isUser">
  3. <metadata v-bind:title="`Profile | ${user.username}`" />
  4. <edit-playlist v-if="modals.editPlaylist" />
  5. <create-playlist v-if="modals.createPlaylist" />
  6. <main-header />
  7. <div class="info-section">
  8. <div class="picture-name-row">
  9. <img
  10. class="profile-picture"
  11. :src="
  12. user.avatar
  13. ? `${user.avatar}?d=${notes}&s=250`
  14. : '/assets/notes.png'
  15. "
  16. onerror="this.src='/assets/notes.png'; this.onerror=''"
  17. />
  18. <div>
  19. <div class="name-role-row">
  20. <p class="name">{{ user.name }}</p>
  21. <span class="role admin" v-if="user.role === 'admin'"
  22. >admin</span
  23. >
  24. </div>
  25. <p class="username">@{{ user.username }}</p>
  26. </div>
  27. </div>
  28. <div class="buttons" v-if="userId === user._id || role === 'admin'">
  29. <router-link
  30. :to="`/admin/users?userId=${user._id}`"
  31. class="button is-primary"
  32. v-if="role === 'admin'"
  33. >
  34. Edit
  35. </router-link>
  36. <router-link
  37. to="/settings"
  38. class="button is-primary"
  39. v-if="userId === user._id"
  40. >
  41. Settings
  42. </router-link>
  43. </div>
  44. <div class="bio-row" v-if="user.bio">
  45. <i class="material-icons">notes</i>
  46. <p>{{ user.bio }}</p>
  47. </div>
  48. <div
  49. class="date-location-row"
  50. v-if="user.createdAt || user.location"
  51. >
  52. <div class="date" v-if="user.createdAt">
  53. <i class="material-icons">calendar_today</i>
  54. <p>{{ user.createdAt }}</p>
  55. </div>
  56. <div class="location" v-if="user.location">
  57. <i class="material-icons">location_on</i>
  58. <p>{{ user.location }}</p>
  59. </div>
  60. </div>
  61. </div>
  62. <div class="bottom-section">
  63. <div class="buttons">
  64. <button
  65. :class="{ active: activeTab === 'recentActivity' }"
  66. @click="switchTab('recentActivity')"
  67. >
  68. Recent activity
  69. </button>
  70. <button
  71. :class="{ active: activeTab === 'playlists' }"
  72. @click="switchTab('playlists')"
  73. v-if="user._id === userId"
  74. >
  75. Playlists
  76. </button>
  77. </div>
  78. <div
  79. class="content recent-activity-tab"
  80. v-if="activeTab === 'recentActivity'"
  81. >
  82. Content here
  83. </div>
  84. <div class="content playlists-tab" v-if="activeTab === 'playlists'">
  85. <div
  86. class="playlist"
  87. v-for="playlist in playlists"
  88. :key="playlist._id"
  89. >
  90. <span>{{ playlist.displayName }}</span>
  91. <button
  92. class="button is-primary"
  93. @click="editPlaylistClick(playlist._id)"
  94. >
  95. Edit
  96. </button>
  97. </div>
  98. <button
  99. class="button is-primary"
  100. @click="
  101. openModal({
  102. sector: 'station',
  103. modal: 'createPlaylist'
  104. })
  105. "
  106. >
  107. Make new playlist
  108. </button>
  109. </div>
  110. </div>
  111. <main-footer />
  112. </div>
  113. </template>
  114. <script>
  115. import { mapState, mapActions } from "vuex";
  116. import { format, parseISO } from "date-fns";
  117. import MainHeader from "../MainHeader.vue";
  118. import MainFooter from "../MainFooter.vue";
  119. import io from "../../io";
  120. export default {
  121. components: {
  122. MainHeader,
  123. MainFooter,
  124. CreatePlaylist: () => import("../Modals/Playlists/Create.vue"),
  125. EditPlaylist: () => import("../Modals/Playlists/Edit.vue")
  126. },
  127. data() {
  128. return {
  129. user: {},
  130. notes: "",
  131. isUser: false,
  132. activeTab: "recentActivity",
  133. playlists: []
  134. };
  135. },
  136. computed: mapState({
  137. role: state => state.user.auth.role,
  138. userId: state => state.user.auth.userId,
  139. ...mapState("modals", {
  140. modals: state => state.modals.station
  141. })
  142. }),
  143. mounted() {
  144. lofig.get("frontendDomain").then(frontendDomain => {
  145. this.frontendDomain = frontendDomain;
  146. this.notes = encodeURI(`${this.frontendDomain}/assets/notes.png`);
  147. });
  148. io.getSocket(socket => {
  149. this.socket = socket;
  150. this.socket.emit(
  151. "users.findByUsername",
  152. this.$route.params.username,
  153. res => {
  154. if (res.status === "error") this.$router.go("/404");
  155. else {
  156. this.user = res.data;
  157. this.user.createdAt = format(
  158. parseISO(this.user.createdAt),
  159. "MMMM do yyyy"
  160. );
  161. this.isUser = true;
  162. if (this.user._id === this.userId) {
  163. this.socket.emit("playlists.indexForUser", res => {
  164. if (res.status === "success")
  165. this.playlists = res.data;
  166. });
  167. this.socket.on(
  168. "event:playlist.create",
  169. playlist => {
  170. this.playlists.push(playlist);
  171. }
  172. );
  173. this.socket.on(
  174. "event:playlist.delete",
  175. playlistId => {
  176. this.playlists.forEach(
  177. (playlist, index) => {
  178. if (playlist._id === playlistId) {
  179. this.playlists.splice(index, 1);
  180. }
  181. }
  182. );
  183. }
  184. );
  185. this.socket.on("event:playlist.addSong", data => {
  186. this.playlists.forEach((playlist, index) => {
  187. if (playlist._id === data.playlistId) {
  188. this.playlists[index].songs.push(
  189. data.song
  190. );
  191. }
  192. });
  193. });
  194. this.socket.on(
  195. "event:playlist.removeSong",
  196. data => {
  197. this.playlists.forEach(
  198. (playlist, index) => {
  199. if (
  200. playlist._id === data.playlistId
  201. ) {
  202. this.playlists[
  203. index
  204. ].songs.forEach(
  205. (song, index2) => {
  206. if (
  207. song._id ===
  208. data.songId
  209. ) {
  210. this.playlists[
  211. index
  212. ].songs.splice(
  213. index2,
  214. 1
  215. );
  216. }
  217. }
  218. );
  219. }
  220. }
  221. );
  222. }
  223. );
  224. this.socket.on(
  225. "event:playlist.updateDisplayName",
  226. data => {
  227. this.playlists.forEach(
  228. (playlist, index) => {
  229. if (
  230. playlist._id === data.playlistId
  231. ) {
  232. this.playlists[
  233. index
  234. ].displayName =
  235. data.displayName;
  236. }
  237. }
  238. );
  239. }
  240. );
  241. }
  242. }
  243. }
  244. );
  245. });
  246. },
  247. methods: {
  248. switchTab(tabName) {
  249. this.activeTab = tabName;
  250. },
  251. editPlaylistClick(playlistId) {
  252. console.log(playlistId);
  253. this.editPlaylist(playlistId);
  254. this.openModal({ sector: "station", modal: "editPlaylist" });
  255. },
  256. ...mapActions("modals", ["openModal"]),
  257. ...mapActions("user/playlists", ["editPlaylist"])
  258. }
  259. };
  260. </script>
  261. <style lang="scss" scoped>
  262. @import "styles/global.scss";
  263. .info-section {
  264. width: 912px;
  265. margin-left: auto;
  266. margin-right: auto;
  267. margin-top: 32px;
  268. padding: 24px;
  269. .picture-name-row {
  270. display: flex;
  271. flex-direction: row;
  272. align-items: center;
  273. column-gap: 32px;
  274. justify-content: center;
  275. margin-bottom: 24px;
  276. }
  277. .profile-picture {
  278. width: 100px;
  279. height: 100px;
  280. border-radius: 100%;
  281. }
  282. .name-role-row {
  283. display: flex;
  284. flex-direction: row;
  285. align-items: center;
  286. column-gap: 12px;
  287. }
  288. .name {
  289. font-size: 34px;
  290. line-height: 40px;
  291. color: $dark-grey-3;
  292. }
  293. .role {
  294. padding: 2px 24px;
  295. color: $white;
  296. text-transform: uppercase;
  297. font-size: 12px;
  298. line-height: 14px;
  299. height: 18px;
  300. border-radius: 5px;
  301. &.admin {
  302. background-color: $red;
  303. }
  304. }
  305. .username {
  306. font-size: 24px;
  307. line-height: 28px;
  308. color: $dark-grey;
  309. }
  310. .buttons {
  311. width: 388px;
  312. display: flex;
  313. flex-direction: row;
  314. column-gap: 20px;
  315. margin-left: auto;
  316. margin-right: auto;
  317. margin-bottom: 24px;
  318. .button {
  319. flex: 1;
  320. font-size: 17px;
  321. line-height: 20px;
  322. }
  323. }
  324. .bio-row,
  325. .date-location-row {
  326. i {
  327. font-size: 24px;
  328. color: $dark-grey-2;
  329. margin-right: 12px;
  330. }
  331. p {
  332. font-size: 17px;
  333. line-height: 20px;
  334. color: $dark-grey-2;
  335. word-break: break-word;
  336. }
  337. }
  338. .bio-row {
  339. max-width: 608px;
  340. margin-bottom: 24px;
  341. margin-left: auto;
  342. margin-right: auto;
  343. display: flex;
  344. width: max-content;
  345. }
  346. .date-location-row {
  347. max-width: 608px;
  348. margin-left: auto;
  349. margin-right: auto;
  350. margin-bottom: 24px;
  351. display: flex;
  352. width: max-content;
  353. margin-bottom: 24px;
  354. column-gap: 48px;
  355. }
  356. .date,
  357. .location {
  358. display: flex;
  359. }
  360. }
  361. .bottom-section {
  362. width: 962px;
  363. margin-left: auto;
  364. margin-right: auto;
  365. margin-top: 32px;
  366. padding: 24px;
  367. display: flex;
  368. column-gap: 64px;
  369. .buttons {
  370. height: 100%;
  371. width: 250px;
  372. button {
  373. outline: none;
  374. border: none;
  375. box-shadow: none;
  376. color: $musareBlue;
  377. font-size: 22px;
  378. line-height: 26px;
  379. padding: 7px 0 7px 12px;
  380. width: 100%;
  381. text-align: left;
  382. cursor: pointer;
  383. border-radius: 5px;
  384. background-color: transparent;
  385. &.active {
  386. color: $white;
  387. background-color: $musareBlue;
  388. }
  389. }
  390. }
  391. .content {
  392. outline: 1px solid black;
  393. width: 600px;
  394. }
  395. }
  396. .night-mode {
  397. .name,
  398. .username,
  399. .bio-row i,
  400. .bio-row p,
  401. .date-location-row i,
  402. .date-location-row p {
  403. color: $light-grey;
  404. }
  405. }
  406. </style>