editCollection.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <template>
  2. <modal v-if="show" @close="hideModal">
  3. <div slot="header">
  4. <ul>
  5. <li>
  6. <div class="flex-wrap">
  7. <h3 class="title">{{ $t("edit_collection") }}</h3>
  8. <div>
  9. <button class="icon" @click="hideModal">
  10. <i class="material-icons">close</i>
  11. </button>
  12. </div>
  13. </div>
  14. </li>
  15. </ul>
  16. </div>
  17. <div slot="body">
  18. <ul>
  19. <li>
  20. <input
  21. type="text"
  22. v-model="name"
  23. :placeholder="editingCollection.name"
  24. @keyup.enter="saveCollection"
  25. />
  26. </li>
  27. </ul>
  28. </div>
  29. <div slot="footer">
  30. <div class="flex-wrap">
  31. <span></span>
  32. <span>
  33. <button class="icon" @click="hideModal">
  34. {{ $t("cancel") }}
  35. </button>
  36. <button class="icon primary" @click="saveCollection">
  37. {{ $t("save") }}
  38. </button>
  39. </span>
  40. </div>
  41. </div>
  42. </modal>
  43. </template>
  44. <script>
  45. import { fb } from "../../functions/fb"
  46. export default {
  47. props: {
  48. show: Boolean,
  49. editingCollection: Object,
  50. editingCollectionIndex: Number,
  51. },
  52. components: {
  53. modal: () => import("../../components/ui/modal"),
  54. },
  55. data() {
  56. return {
  57. name: undefined,
  58. }
  59. },
  60. methods: {
  61. syncCollections() {
  62. if (fb.currentUser !== null) {
  63. if (fb.currentSettings[0].value) {
  64. fb.writeCollections(JSON.parse(JSON.stringify(this.$store.state.postwoman.collections)))
  65. }
  66. }
  67. },
  68. saveCollection() {
  69. if (!this.$data.name) {
  70. this.$toast.info(this.$t("invalid_collection_name"))
  71. return
  72. }
  73. const collectionUpdated = {
  74. ...this.$props.editingCollection,
  75. name: this.$data.name,
  76. }
  77. this.$store.commit("postwoman/editCollection", {
  78. collection: collectionUpdated,
  79. collectionIndex: this.$props.editingCollectionIndex,
  80. })
  81. this.$emit("hide-modal")
  82. this.syncCollections()
  83. },
  84. hideModal() {
  85. this.$emit("hide-modal")
  86. },
  87. },
  88. }
  89. </script>