api-client/components/collections/addCollection.vue

86 lines
1.9 KiB
Vue
Raw Normal View History

2019-10-01 22:20:23 +00:00
<template>
2019-10-25 08:14:34 +00:00
<modal v-if="show" @close="hideModal">
<div slot="header">
<ul>
<li>
<div class="flex-wrap">
<h3 class="title">{{ $t("new_collection") }}</h3>
2019-10-25 08:14:34 +00:00
<div>
<button class="icon" @click="hideModal">
<i class="material-icons">close</i>
</button>
2019-10-01 22:20:23 +00:00
</div>
2019-10-25 08:14:34 +00:00
</div>
</li>
</ul>
</div>
<div slot="body">
<ul>
<li>
<input
type="text"
v-model="name"
:placeholder="$t('my_new_collection')"
@keyup.enter="addNewCollection"
/>
2019-10-25 08:14:34 +00:00
</li>
</ul>
2019-10-01 22:20:23 +00:00
</div>
2019-10-25 08:14:34 +00:00
<div slot="footer">
2019-12-17 19:13:15 +00:00
<div class="flex-wrap">
<span></span>
<span>
<button class="icon" @click="hideModal">
{{ $t("cancel") }}
2019-10-25 08:14:34 +00:00
</button>
2019-12-17 19:13:15 +00:00
<button class="icon primary" @click="addNewCollection">
{{ $t("save") }}
2019-12-17 19:13:15 +00:00
</button>
</span>
</div>
2019-10-25 08:14:34 +00:00
</div>
</modal>
2019-10-01 22:20:23 +00:00
</template>
<script>
import { fb } from "~/helpers/fb"
2019-11-02 05:32:21 +00:00
export default {
props: {
2020-02-24 18:44:50 +00:00
show: Boolean,
2019-11-02 05:32:21 +00:00
},
components: {
modal: () => import("~/components/ui/modal"),
2019-11-02 05:32:21 +00:00
},
data() {
return {
2020-02-24 18:44:50 +00:00
name: undefined,
}
2019-11-02 05:32:21 +00:00
},
methods: {
syncCollections() {
if (fb.currentUser !== null) {
if (fb.currentSettings[0].value) {
2020-02-24 18:44:50 +00:00
fb.writeCollections(JSON.parse(JSON.stringify(this.$store.state.postwoman.collections)))
}
}
},
2019-11-02 05:32:21 +00:00
addNewCollection() {
2020-01-23 08:40:26 +00:00
if (!this.$data.name) {
this.$toast.info(this.$t("invalid_collection_name"))
2020-02-24 18:44:50 +00:00
return
}
this.$store.commit("postwoman/addNewCollection", {
2020-02-24 18:44:50 +00:00
name: this.$data.name,
})
this.$emit("hide-modal")
2020-02-24 18:44:50 +00:00
this.syncCollections()
2019-10-01 22:20:23 +00:00
},
2019-11-02 05:32:21 +00:00
hideModal() {
this.$emit("hide-modal")
this.$data.name = undefined
2020-02-24 18:44:50 +00:00
},
},
}
2019-10-22 12:02:26 +00:00
</script>