Create.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template>
  2. <modal title="Create Playlist">
  3. <template v-slot:body>
  4. <p class="control is-expanded">
  5. <input
  6. v-model="playlist.displayName"
  7. class="input"
  8. type="text"
  9. placeholder="Playlist Display Name"
  10. autofocus
  11. @keyup.enter="createPlaylist()"
  12. />
  13. </p>
  14. </template>
  15. <template v-slot:footer>
  16. <a class="button is-info" v-on:click="createPlaylist()"
  17. >Create Playlist</a
  18. >
  19. </template>
  20. </modal>
  21. </template>
  22. <script>
  23. import { mapActions } from "vuex";
  24. import { Toast } from "vue-roaster";
  25. import Modal from "../Modal.vue";
  26. import io from "../../../io";
  27. import validation from "../../../validation";
  28. export default {
  29. components: { Modal },
  30. data() {
  31. return {
  32. playlist: {
  33. displayName: null,
  34. songs: []
  35. }
  36. };
  37. },
  38. mounted() {
  39. const _this = this;
  40. io.getSocket(socket => {
  41. _this.socket = socket;
  42. });
  43. },
  44. methods: {
  45. createPlaylist() {
  46. const { displayName } = this.playlist;
  47. if (!validation.isLength(displayName, 2, 32))
  48. return Toast.methods.addToast(
  49. "Display name must have between 2 and 32 characters.",
  50. 8000
  51. );
  52. if (!validation.regex.azAZ09_.test(displayName))
  53. return Toast.methods.addToast(
  54. "Invalid display name format. Allowed characters: a-z, A-Z, 0-9 and _.",
  55. 8000
  56. );
  57. return this.socket.emit("playlists.create", this.playlist, res => {
  58. Toast.methods.addToast(res.message, 3000);
  59. if (res.status === "success") {
  60. this.closeModal({
  61. sector: "station",
  62. modal: "createPlaylist"
  63. });
  64. this.editPlaylist(res.data._id);
  65. this.openModal({
  66. sector: "station",
  67. modal: "editPlaylist"
  68. });
  69. }
  70. });
  71. },
  72. ...mapActions("modals", ["closeModal", "openModal"]),
  73. ...mapActions("user/playlists", ["editPlaylist"])
  74. }
  75. };
  76. </script>
  77. <style lang="scss" scoped>
  78. .menu {
  79. padding: 0 20px;
  80. }
  81. .menu-list li {
  82. display: flex;
  83. justify-content: space-between;
  84. }
  85. .menu-list a:hover {
  86. color: #000 !important;
  87. }
  88. li a {
  89. display: flex;
  90. align-items: center;
  91. }
  92. .controls {
  93. display: flex;
  94. a {
  95. display: flex;
  96. align-items: center;
  97. }
  98. }
  99. .table {
  100. margin-bottom: 0;
  101. }
  102. h5 {
  103. padding: 20px 0;
  104. }
  105. </style>