Create.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 "toasters";
  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. io.getSocket(socket => {
  40. this.socket = socket;
  41. });
  42. },
  43. methods: {
  44. createPlaylist() {
  45. const { displayName } = this.playlist;
  46. if (!validation.isLength(displayName, 2, 32))
  47. return new Toast({
  48. content:
  49. "Display name must have between 2 and 32 characters.",
  50. timeout: 8000
  51. });
  52. if (!validation.regex.ascii.test(displayName))
  53. return new Toast({
  54. content:
  55. "Invalid display name format. Only ASCII characters are allowed.",
  56. timeout: 8000
  57. });
  58. return this.socket.emit("playlists.create", this.playlist, res => {
  59. new Toast({ content: res.message, timeout: 3000 });
  60. if (res.status === "success") {
  61. this.closeModal({
  62. sector: "station",
  63. modal: "createPlaylist"
  64. });
  65. this.editPlaylist(res.data._id);
  66. this.openModal({
  67. sector: "station",
  68. modal: "editPlaylist"
  69. });
  70. }
  71. });
  72. },
  73. ...mapActions("modals", ["closeModal", "openModal"]),
  74. ...mapActions("user/playlists", ["editPlaylist"])
  75. }
  76. };
  77. </script>
  78. <style lang="scss" scoped>
  79. @import "styles/global.scss";
  80. .menu {
  81. padding: 0 20px;
  82. }
  83. .menu-list li {
  84. display: flex;
  85. justify-content: space-between;
  86. }
  87. .menu-list a:hover {
  88. color: $black !important;
  89. }
  90. li a {
  91. display: flex;
  92. align-items: center;
  93. }
  94. .controls {
  95. display: flex;
  96. a {
  97. display: flex;
  98. align-items: center;
  99. }
  100. }
  101. .table {
  102. margin-bottom: 0;
  103. }
  104. h5 {
  105. padding: 20px 0;
  106. }
  107. </style>