Add.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <template>
  2. <SmartModal v-if="show" @close="hideModal">
  3. <div slot="header">
  4. <div class="row-wrapper">
  5. <h3 class="title">{{ $t("new_collection") }}</h3>
  6. <div>
  7. <button class="icon" @click="hideModal">
  8. <i class="material-icons">close</i>
  9. </button>
  10. </div>
  11. </div>
  12. </div>
  13. <div slot="body" class="flex flex-col">
  14. <label for="selectLabel">{{ $t("label") }}</label>
  15. <input
  16. type="text"
  17. id="selectLabel"
  18. v-model="name"
  19. :placeholder="$t('my_new_collection')"
  20. @keyup.enter="addNewCollection"
  21. />
  22. </div>
  23. <div slot="footer">
  24. <div class="row-wrapper">
  25. <span></span>
  26. <span>
  27. <button class="icon" @click="hideModal">
  28. {{ $t("cancel") }}
  29. </button>
  30. <button class="icon primary" @click="addNewCollection">
  31. {{ $t("save") }}
  32. </button>
  33. </span>
  34. </div>
  35. </div>
  36. </SmartModal>
  37. </template>
  38. <script>
  39. import { fb } from "~/helpers/fb"
  40. export default {
  41. props: {
  42. show: Boolean,
  43. },
  44. data() {
  45. return {
  46. name: undefined,
  47. }
  48. },
  49. methods: {
  50. syncCollections() {
  51. if (fb.currentUser !== null && fb.currentSettings[0]) {
  52. if (fb.currentSettings[0].value) {
  53. fb.writeCollections(JSON.parse(JSON.stringify(this.$store.state.postwoman.collections)))
  54. }
  55. }
  56. },
  57. addNewCollection() {
  58. if (!this.$data.name) {
  59. this.$toast.info(this.$t("invalid_collection_name"))
  60. return
  61. }
  62. this.$store.commit("postwoman/addNewCollection", {
  63. name: this.$data.name,
  64. })
  65. this.$emit("hide-modal")
  66. this.syncCollections()
  67. },
  68. hideModal() {
  69. this.$emit("hide-modal")
  70. this.$data.name = undefined
  71. },
  72. },
  73. }
  74. </script>