add open/close events to TextCard

This commit is contained in:
axolotle
2021-03-10 12:49:19 +01:00
parent f28c1fe4dd
commit e3b17c6aff
2 changed files with 29 additions and 6 deletions
+5 -2
View File
@@ -15,11 +15,14 @@
</h4> </h4>
<b-nav class="ml-auto flex-nowrap"> <b-nav class="ml-auto flex-nowrap">
<b-nav-item v-for="prod in text.prods" :key="prod.id"> <b-nav-item
v-for="prod in text.prods" :key="prod.id"
@click="$emit('open', prod.id)"
>
{{ prod.id }} {{ prod.id }}
</b-nav-item> </b-nav-item>
<b-nav-item> <b-nav-item @click="$emit('close')">
x x
</b-nav-item> </b-nav-item>
</b-nav> </b-nav>
+24 -4
View File
@@ -5,9 +5,13 @@
<!-- FOREGROUND (texts) --> <!-- FOREGROUND (texts) -->
<section v-for="group in groups" :key="group.id" class="split-screen"> <section v-for="group in groups" :key="group.id" class="split-screen">
<text-card :id="group.id" /> <text-card :id="group.id" @open="openText(group, $event)" @close="closeText(group)" />
<div> <div>
<text-card v-for="id in group.prod" :key="id" :id="id" /> <text-card
v-for="id in group.prod" :key="id"
:id="id"
@close="closeText(group, id)"
/>
</div> </div>
</section> </section>
</div> </div>
@@ -53,11 +57,27 @@ export default {
}, },
methods: { methods: {
openText () { openText (group, id) {
if (group.prod.includes(id)) return
group.prod.push(id)
this.updateQuery(this.groups)
},
closeText (group, id) {
if (!id) {
this.updateQuery(this.groups.filter(grp => grp !== group))
} else {
group.prod = group.prod.filter(id_ => id_ !== id)
this.updateQuery(this.groups)
}
},
updateQuery (groups) {
// Update the route's query (will not reload the page) and let vue determine what changed.
this.$router.push({ this.$router.push({
query: { query: {
mode: this.mode, mode: this.mode,
texts: [...this.texts, [50]] texts: groups.map(grp => [grp.id, ...grp.prod])
} }
}) })
} }