CreatePlaylist.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <modal title="Create Playlist">
  3. <template #body>
  4. <p class="control is-expanded">
  5. <label class="label">Display Name</label>
  6. <input
  7. v-model="playlist.displayName"
  8. class="input"
  9. type="text"
  10. placeholder="Enter display name..."
  11. autofocus
  12. @keyup.enter="createPlaylist()"
  13. />
  14. </p>
  15. <div class="control" id="privacy-selection">
  16. <label class="label">Privacy</label>
  17. <p class="control select">
  18. <select v-model="playlist.privacy">
  19. <option value="private">Private</option>
  20. <option value="public" selected>Public</option>
  21. </select>
  22. </p>
  23. </div>
  24. </template>
  25. <template #footer>
  26. <a class="button is-info" @click="createPlaylist()"
  27. ><i class="material-icons icon-with-button">create</i>Create
  28. Playlist</a
  29. >
  30. </template>
  31. </modal>
  32. </template>
  33. <script>
  34. import { mapActions, mapGetters } from "vuex";
  35. import Toast from "toasters";
  36. import validation from "@/validation";
  37. import Modal from "../Modal.vue";
  38. export default {
  39. components: { Modal },
  40. data() {
  41. return {
  42. playlist: {
  43. displayName: "",
  44. privacy: "public",
  45. songs: []
  46. }
  47. };
  48. },
  49. computed: mapGetters({
  50. socket: "websockets/getSocket"
  51. }),
  52. methods: {
  53. createPlaylist() {
  54. const { displayName } = this.playlist;
  55. if (!validation.isLength(displayName, 2, 32))
  56. return new Toast(
  57. "Display name must have between 2 and 32 characters."
  58. );
  59. if (!validation.regex.ascii.test(displayName))
  60. return new Toast(
  61. "Invalid display name format. Only ASCII characters are allowed."
  62. );
  63. return this.socket.dispatch(
  64. "playlists.create",
  65. this.playlist,
  66. res => {
  67. new Toast(res.message);
  68. if (res.status === "success") {
  69. this.closeModal({
  70. sector: "station",
  71. modal: "createPlaylist"
  72. });
  73. this.editPlaylist(res.data.playlistId);
  74. this.openModal({
  75. sector: "station",
  76. modal: "editPlaylist"
  77. });
  78. }
  79. }
  80. );
  81. },
  82. ...mapActions("modalVisibility", ["closeModal", "openModal"]),
  83. ...mapActions("user/playlists", ["editPlaylist"])
  84. }
  85. };
  86. </script>
  87. <style lang="scss" scoped>
  88. .menu {
  89. padding: 0 20px;
  90. }
  91. .menu-list li {
  92. display: flex;
  93. justify-content: space-between;
  94. }
  95. .menu-list a:hover {
  96. color: var(--black) !important;
  97. }
  98. li a {
  99. display: flex;
  100. align-items: center;
  101. }
  102. #privacy-selection {
  103. margin-top: 15px;
  104. }
  105. .controls {
  106. display: flex;
  107. a {
  108. display: flex;
  109. align-items: center;
  110. }
  111. }
  112. .label {
  113. font-size: 1rem;
  114. }
  115. </style>