edit-collection.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <modal v-if="show" @close="hideModal">
  3. <div slot="header">
  4. <ul>
  5. <li>
  6. <div class="row-wrapper">
  7. <h3 class="title">{{ $t("edit_collection") }}</h3>
  8. <div>
  9. <button class="icon" @click="hideModal">
  10. <closeIcon class="material-icons" />
  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="row-wrapper">
  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 "~/helpers/fb"
  46. import closeIcon from "~/static/icons/close-24px.svg?inline"
  47. export default {
  48. components: {
  49. closeIcon,
  50. },
  51. props: {
  52. show: Boolean,
  53. editingCollection: Object,
  54. editingCollectionIndex: Number,
  55. },
  56. data() {
  57. return {
  58. name: undefined,
  59. }
  60. },
  61. methods: {
  62. syncCollections() {
  63. if (fb.currentUser !== null) {
  64. if (fb.currentSettings[0].value) {
  65. fb.writeCollections(JSON.parse(JSON.stringify(this.$store.state.postwoman.collections)))
  66. }
  67. }
  68. },
  69. saveCollection() {
  70. if (!this.$data.name) {
  71. this.$toast.info(this.$t("invalid_collection_name"))
  72. return
  73. }
  74. const collectionUpdated = {
  75. ...this.$props.editingCollection,
  76. name: this.$data.name,
  77. }
  78. this.$store.commit("postwoman/editCollection", {
  79. collection: collectionUpdated,
  80. collectionIndex: this.$props.editingCollectionIndex,
  81. })
  82. this.$emit("hide-modal")
  83. this.syncCollections()
  84. },
  85. hideModal() {
  86. this.$emit("hide-modal")
  87. },
  88. },
  89. }
  90. </script>