CreatePlaylist.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <modal title="Create Playlist" :size="'slim'">
  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 is-expanded 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. export default {
  38. data() {
  39. return {
  40. playlist: {
  41. displayName: "",
  42. privacy: "public",
  43. songs: []
  44. }
  45. };
  46. },
  47. computed: mapGetters({
  48. socket: "websockets/getSocket"
  49. }),
  50. unmounted() {
  51. if (window.addToPlaylistDropdown)
  52. window.addToPlaylistDropdown.tippy.setProps({
  53. zIndex: 9999,
  54. hideOnClick: true
  55. });
  56. window.addToPlaylistDropdown = null;
  57. },
  58. methods: {
  59. createPlaylist() {
  60. const { displayName } = this.playlist;
  61. if (!validation.isLength(displayName, 2, 32))
  62. return new Toast(
  63. "Display name must have between 2 and 32 characters."
  64. );
  65. if (!validation.regex.ascii.test(displayName))
  66. return new Toast(
  67. "Invalid display name format. Only ASCII characters are allowed."
  68. );
  69. return this.socket.dispatch(
  70. "playlists.create",
  71. this.playlist,
  72. res => {
  73. new Toast(res.message);
  74. if (res.status === "success") {
  75. this.closeModal("createPlaylist");
  76. if (!window.addToPlaylistDropdown) {
  77. this.openModal({
  78. modal: "editPlaylist",
  79. data: { playlistId: res.data.playlistId }
  80. });
  81. }
  82. }
  83. }
  84. );
  85. },
  86. ...mapActions("modalVisibility", ["closeModal", "openModal"])
  87. }
  88. };
  89. </script>