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. methods: {
  77. isEditable() {
  78. return (
  79. this.playlist.isUserModifiable &&
  80. (this.userId === this.playlist.createdBy ||
  81. this.userRole === "admin")
  82. );
  83. },
  84. isAdmin() {
  85. return this.userRole === "admin";
  86. },
  87. renamePlaylist() {
  88. const { displayName } = this.playlist;
  89. if (!validation.isLength(displayName, 2, 32))
  90. return new Toast(
  91. "Display name must have between 2 and 32 characters."
  92. );
  93. if (!validation.regex.ascii.test(displayName))
  94. return new Toast(
  95. "Invalid display name format. Only ASCII characters are allowed."
  96. );
  97. return this.socket.dispatch(
  98. "playlists.updateDisplayName",
  99. this.playlist._id,
  100. this.playlist.displayName,
  101. res => {
  102. new Toast(res.message);
  103. }
  104. );
  105. },
  106. updatePrivacy() {
  107. const { privacy } = this.playlist;
  108. if (privacy === "public" || privacy === "private") {
  109. this.socket.dispatch(
  110. this.playlist.type === "genre"
  111. ? "playlists.updatePrivacyAdmin"
  112. : "playlists.updatePrivacy",
  113. this.playlist._id,
  114. privacy,
  115. res => {
  116. new Toast(res.message);
  117. }
  118. );
  119. }
  120. }
  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>