Show.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  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. <div class="item activity">
  83. <div class="thumbnail">
  84. <img
  85. src="https://cdn8.openculture.com/2018/02/26214611/Arlo-safe-e1519715317729.jpg"
  86. alt=""
  87. />
  88. <i class="material-icons activity-type-icon"
  89. >playlist_add</i
  90. >
  91. </div>
  92. <div class="left-part">
  93. <p class="top-text">
  94. Added
  95. <strong>3 songs</strong>
  96. to the playlist
  97. <strong>Blues</strong>
  98. </p>
  99. <p class="bottom-text">3 hours ago</p>
  100. </div>
  101. <div class="actions">
  102. <a class="hide-icon" href="#" @click="hideActivity()">
  103. <i class="material-icons">visibility_off</i>
  104. </a>
  105. </div>
  106. </div>
  107. </div>
  108. <div class="content playlists-tab" v-if="activeTab === 'playlists'">
  109. <div
  110. class="item playlist"
  111. v-for="playlist in playlists"
  112. :key="playlist._id"
  113. >
  114. <div class="left-part">
  115. <p class="top-text">{{ playlist.displayName }}</p>
  116. <p class="bottom-text">
  117. {{ totalLength(playlist) }} •
  118. {{ playlist.songs.length }}
  119. {{ playlist.songs.length === 1 ? "song" : "songs" }}
  120. </p>
  121. </div>
  122. <div class="actions">
  123. <button
  124. class="button is-primary"
  125. @click="editPlaylistClick(playlist._id)"
  126. >
  127. Edit
  128. </button>
  129. </div>
  130. </div>
  131. <button
  132. class="button is-primary"
  133. @click="
  134. openModal({
  135. sector: 'station',
  136. modal: 'createPlaylist'
  137. })
  138. "
  139. >
  140. Create new playlist
  141. </button>
  142. </div>
  143. </div>
  144. <main-footer />
  145. </div>
  146. </template>
  147. <script>
  148. import { mapState, mapActions } from "vuex";
  149. import { format, parseISO } from "date-fns";
  150. import MainHeader from "../MainHeader.vue";
  151. import MainFooter from "../MainFooter.vue";
  152. import io from "../../io";
  153. import utils from "../../js/utils";
  154. export default {
  155. components: {
  156. MainHeader,
  157. MainFooter,
  158. CreatePlaylist: () => import("../Modals/Playlists/Create.vue"),
  159. EditPlaylist: () => import("../Modals/Playlists/Edit.vue")
  160. },
  161. data() {
  162. return {
  163. utils,
  164. user: {},
  165. notes: "",
  166. isUser: false,
  167. activeTab: "recentActivity",
  168. playlists: []
  169. };
  170. },
  171. computed: mapState({
  172. role: state => state.user.auth.role,
  173. userId: state => state.user.auth.userId,
  174. ...mapState("modals", {
  175. modals: state => state.modals.station
  176. })
  177. }),
  178. mounted() {
  179. lofig.get("frontendDomain").then(frontendDomain => {
  180. this.frontendDomain = frontendDomain;
  181. this.notes = encodeURI(`${this.frontendDomain}/assets/notes.png`);
  182. });
  183. io.getSocket(socket => {
  184. this.socket = socket;
  185. this.socket.emit(
  186. "users.findByUsername",
  187. this.$route.params.username,
  188. res => {
  189. if (res.status === "error") this.$router.go("/404");
  190. else {
  191. this.user = res.data;
  192. this.user.createdAt = format(
  193. parseISO(this.user.createdAt),
  194. "MMMM do yyyy"
  195. );
  196. this.isUser = true;
  197. if (this.user._id === this.userId) {
  198. this.socket.emit("playlists.indexForUser", res => {
  199. if (res.status === "success")
  200. this.playlists = res.data;
  201. });
  202. this.socket.on(
  203. "event:playlist.create",
  204. playlist => {
  205. this.playlists.push(playlist);
  206. }
  207. );
  208. this.socket.on(
  209. "event:playlist.delete",
  210. playlistId => {
  211. this.playlists.forEach(
  212. (playlist, index) => {
  213. if (playlist._id === playlistId) {
  214. this.playlists.splice(index, 1);
  215. }
  216. }
  217. );
  218. }
  219. );
  220. this.socket.on("event:playlist.addSong", data => {
  221. this.playlists.forEach((playlist, index) => {
  222. if (playlist._id === data.playlistId) {
  223. this.playlists[index].songs.push(
  224. data.song
  225. );
  226. }
  227. });
  228. });
  229. this.socket.on(
  230. "event:playlist.removeSong",
  231. data => {
  232. this.playlists.forEach(
  233. (playlist, index) => {
  234. if (
  235. playlist._id === data.playlistId
  236. ) {
  237. this.playlists[
  238. index
  239. ].songs.forEach(
  240. (song, index2) => {
  241. if (
  242. song._id ===
  243. data.songId
  244. ) {
  245. this.playlists[
  246. index
  247. ].songs.splice(
  248. index2,
  249. 1
  250. );
  251. }
  252. }
  253. );
  254. }
  255. }
  256. );
  257. }
  258. );
  259. this.socket.on(
  260. "event:playlist.updateDisplayName",
  261. data => {
  262. this.playlists.forEach(
  263. (playlist, index) => {
  264. if (
  265. playlist._id === data.playlistId
  266. ) {
  267. this.playlists[
  268. index
  269. ].displayName =
  270. data.displayName;
  271. }
  272. }
  273. );
  274. }
  275. );
  276. }
  277. }
  278. }
  279. );
  280. });
  281. },
  282. methods: {
  283. switchTab(tabName) {
  284. this.activeTab = tabName;
  285. },
  286. editPlaylistClick(playlistId) {
  287. console.log(playlistId);
  288. this.editPlaylist(playlistId);
  289. this.openModal({ sector: "station", modal: "editPlaylist" });
  290. },
  291. totalLength(playlist) {
  292. let length = 0;
  293. playlist.songs.forEach(song => {
  294. length += song.duration;
  295. });
  296. return this.utils.formatTimeLong(length);
  297. },
  298. hideActivity() {
  299. console.log("hidden activity");
  300. },
  301. ...mapActions("modals", ["openModal"]),
  302. ...mapActions("user/playlists", ["editPlaylist"])
  303. }
  304. };
  305. </script>
  306. <style lang="scss" scoped>
  307. @import "styles/global.scss";
  308. .info-section {
  309. width: 912px;
  310. margin-left: auto;
  311. margin-right: auto;
  312. margin-top: 32px;
  313. padding: 24px;
  314. .picture-name-row {
  315. display: flex;
  316. flex-direction: row;
  317. align-items: center;
  318. justify-content: center;
  319. margin-bottom: 24px;
  320. }
  321. .profile-picture {
  322. width: 100px;
  323. height: 100px;
  324. border-radius: 100%;
  325. margin-right: 32px;
  326. }
  327. .name-role-row {
  328. display: flex;
  329. flex-direction: row;
  330. align-items: center;
  331. }
  332. .name {
  333. font-size: 34px;
  334. line-height: 40px;
  335. color: $dark-grey-3;
  336. }
  337. .role {
  338. padding: 2px 24px;
  339. color: $white;
  340. text-transform: uppercase;
  341. font-size: 12px;
  342. line-height: 14px;
  343. height: 18px;
  344. border-radius: 5px;
  345. margin-left: 12px;
  346. &.admin {
  347. background-color: $red;
  348. }
  349. }
  350. .username {
  351. font-size: 24px;
  352. line-height: 28px;
  353. color: $dark-grey;
  354. }
  355. .buttons {
  356. width: 388px;
  357. display: flex;
  358. flex-direction: row;
  359. margin-left: auto;
  360. margin-right: auto;
  361. margin-bottom: 24px;
  362. .button {
  363. flex: 1;
  364. font-size: 17px;
  365. line-height: 20px;
  366. &:nth-child(2) {
  367. margin-left: 20px;
  368. }
  369. }
  370. }
  371. .bio-row,
  372. .date-location-row {
  373. i {
  374. font-size: 24px;
  375. color: $dark-grey-2;
  376. margin-right: 12px;
  377. }
  378. p {
  379. font-size: 17px;
  380. line-height: 20px;
  381. color: $dark-grey-2;
  382. word-break: break-word;
  383. }
  384. }
  385. .bio-row {
  386. max-width: 608px;
  387. margin-bottom: 24px;
  388. margin-left: auto;
  389. margin-right: auto;
  390. display: flex;
  391. width: max-content;
  392. }
  393. .date-location-row {
  394. max-width: 608px;
  395. margin-left: auto;
  396. margin-right: auto;
  397. margin-bottom: 24px;
  398. display: flex;
  399. width: max-content;
  400. margin-bottom: 24px;
  401. > div:nth-child(2) {
  402. margin-left: 48px;
  403. }
  404. }
  405. .date,
  406. .location {
  407. display: flex;
  408. }
  409. }
  410. .bottom-section {
  411. width: 962px;
  412. margin-left: auto;
  413. margin-right: auto;
  414. margin-top: 32px;
  415. padding: 24px;
  416. display: flex;
  417. .buttons {
  418. height: 100%;
  419. width: 250px;
  420. margin-right: 64px;
  421. button {
  422. outline: none;
  423. border: none;
  424. box-shadow: none;
  425. color: $musareBlue;
  426. font-size: 22px;
  427. line-height: 26px;
  428. padding: 7px 0 7px 12px;
  429. width: 100%;
  430. text-align: left;
  431. cursor: pointer;
  432. border-radius: 5px;
  433. background-color: transparent;
  434. &.active {
  435. color: $white;
  436. background-color: $musareBlue;
  437. }
  438. }
  439. }
  440. .content {
  441. width: 600px;
  442. .item {
  443. width: 100%;
  444. height: 72px;
  445. border: 0.5px $light-grey-2 solid;
  446. margin-bottom: 12px;
  447. border-radius: 0 5px 5px 0;
  448. display: flex;
  449. .top-text {
  450. color: $dark-grey-2;
  451. font-size: 20px;
  452. line-height: 23px;
  453. margin-bottom: 0;
  454. }
  455. .bottom-text {
  456. color: $dark-grey-2;
  457. font-size: 16px;
  458. line-height: 19px;
  459. margin-bottom: 0;
  460. margin-top: 6px;
  461. }
  462. .thumbnail {
  463. display: flex;
  464. align-items: center;
  465. justify-content: center;
  466. width: 70.5px;
  467. height: 70.5px;
  468. background-color: #000;
  469. img {
  470. opacity: 0.4;
  471. }
  472. .activity-type-icon {
  473. position: absolute;
  474. color: #fff;
  475. }
  476. }
  477. .left-part {
  478. flex: 1;
  479. padding: 12px;
  480. }
  481. .actions {
  482. display: flex;
  483. align-items: center;
  484. padding: 12px;
  485. .hide-icon {
  486. border-bottom: 0;
  487. display: flex;
  488. i {
  489. color: #bdbdbd;
  490. }
  491. }
  492. }
  493. button {
  494. font-size: 17px;
  495. }
  496. }
  497. }
  498. .playlists-tab > button {
  499. width: 100%;
  500. font-size: 17px;
  501. }
  502. }
  503. .night-mode {
  504. .name,
  505. .username,
  506. .bio-row i,
  507. .bio-row p,
  508. .date-location-row i,
  509. .date-location-row p {
  510. color: $light-grey;
  511. }
  512. }
  513. </style>