Settings.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <template>
  2. <div class="settings-tab section">
  3. <div v-if="isEditable()">
  4. <h4 class="section-title">Edit Details</h4>
  5. <p class="section-description">
  6. Change the display name and privacy of the playlist.
  7. </p>
  8. <hr class="section-horizontal-rule" />
  9. <label class="label"> Change display name </label>
  10. <div class="control is-grouped input-with-button">
  11. <p class="control is-expanded">
  12. <input
  13. v-model="playlist.displayName"
  14. class="input"
  15. type="text"
  16. placeholder="Playlist Display Name"
  17. @keyup.enter="renamePlaylist()"
  18. />
  19. </p>
  20. <p class="control">
  21. <a
  22. class="button is-info"
  23. @click.prevent="renamePlaylist()"
  24. href="#"
  25. >Rename</a
  26. >
  27. </p>
  28. </div>
  29. </div>
  30. <div
  31. v-if="
  32. userId === playlist.createdBy ||
  33. (playlist.type === 'genre' && isAdmin())
  34. "
  35. >
  36. <label class="label"> Change privacy </label>
  37. <div class="control is-grouped input-with-button">
  38. <div class="control is-expanded select">
  39. <select v-model="playlist.privacy">
  40. <option value="private">Private</option>
  41. <option value="public">Public</option>
  42. </select>
  43. </div>
  44. <p class="control">
  45. <a
  46. class="button is-info"
  47. @click.prevent="updatePrivacy()"
  48. href="#"
  49. >Update Privacy</a
  50. >
  51. </p>
  52. </div>
  53. </div>
  54. </div>
  55. </template>
  56. <script>
  57. import { mapState, mapGetters /* , mapActions */ } from "vuex";
  58. import Toast from "toasters";
  59. import validation from "@/validation";
  60. export default {
  61. data() {
  62. return {};
  63. },
  64. computed: {
  65. ...mapState("modals/editPlaylist", {
  66. playlist: state => state.playlist
  67. }),
  68. ...mapGetters({
  69. socket: "websockets/getSocket"
  70. }),
  71. ...mapState({
  72. userId: state => state.user.auth.userId,
  73. userRole: state => state.user.auth.role
  74. })
  75. },
  76. mounted() {},
  77. methods: {
  78. isEditable() {
  79. return (
  80. this.playlist.isUserModifiable &&
  81. (this.userId === this.playlist.createdBy ||
  82. this.userRole === "admin")
  83. );
  84. },
  85. isAdmin() {
  86. return this.userRole === "admin";
  87. },
  88. renamePlaylist() {
  89. const { displayName } = this.playlist;
  90. if (!validation.isLength(displayName, 2, 32))
  91. return new Toast(
  92. "Display name must have between 2 and 32 characters."
  93. );
  94. if (!validation.regex.ascii.test(displayName))
  95. return new Toast(
  96. "Invalid display name format. Only ASCII characters are allowed."
  97. );
  98. return this.socket.dispatch(
  99. "playlists.updateDisplayName",
  100. this.playlist._id,
  101. this.playlist.displayName,
  102. res => {
  103. new Toast(res.message);
  104. }
  105. );
  106. },
  107. updatePrivacy() {
  108. const { privacy } = this.playlist;
  109. if (privacy === "public" || privacy === "private") {
  110. this.socket.dispatch(
  111. "playlists.updatePrivacy",
  112. this.playlist._id,
  113. privacy,
  114. res => {
  115. new Toast(res.message);
  116. }
  117. );
  118. }
  119. }
  120. // ...mapActions("modals/editSong", ["selectDiscogsInfo"])
  121. }
  122. };
  123. </script>
  124. <style lang="scss" scoped>
  125. @media screen and (max-width: 1300px) {
  126. .section {
  127. max-width: 100% !important;
  128. }
  129. }
  130. </style>