Skip to content

Commit

Permalink
feat: add Merge All button
Browse files Browse the repository at this point in the history
  • Loading branch information
shonya3 committed Sep 3, 2023
1 parent 47e2679 commit 5ee3d74
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 20 deletions.
44 changes: 26 additions & 18 deletions packages/app/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,32 @@ const openStashWindow = async () => {
/>
</div>

<Transition>
<SampleCard
v-if="sampleStore.merged"
v-bind="sampleStore.merged"
@delete="sampleStore.deleteMerged"
@update:minimumCardPrice="price => sampleStore.merged && (sampleStore.merged.minimumCardPrice = price)"
@update:league="sampleStore.replaceMerged"
/>
</Transition>

<div v-if="sampleStore.sampleCards.length > 0">
<h2>Select files you want to merge</h2>
<button class="btn" @click="sampleStore.downloadAll">Download All</button>
<button :disabled="sampleStore.samples.length < 2" class="btn" @click="sampleStore.mergeAll">
Merge All
</button>
<button
:disabled="sampleStore.selectedSampleCards.length < 2"
class="btn"
@click="sampleStore.mergeSelected"
>
Merge selected
</button>
<button class="btn" @click="sampleStore.deleteAllFiles">Remove samples</button>
</div>

<Transition>
<div ref="filesTemplateRef" class="samples" v-show="sampleStore.sampleCards.length">
<SampleCard
Expand All @@ -68,24 +94,6 @@ const openStashWindow = async () => {
/>
</div>
</Transition>

<div v-if="sampleStore.sampleCards.length > 0">
<h2>Select files you want to merge</h2>
<button class="btn" @click="sampleStore.downloadAll">Download All</button>
<button :disabled="sampleStore.selectedSampleCards.length < 2" class="btn" @click="sampleStore.merge">
Merge samples
</button>
<button class="btn" @click="sampleStore.deleteAllFiles">Clear all</button>
</div>
<Transition>
<SampleCard
v-if="sampleStore.merged"
v-bind="sampleStore.merged"
@delete="sampleStore.deleteMerged"
@update:minimumCardPrice="price => sampleStore.merged && (sampleStore.merged.minimumCardPrice = price)"
@update:league="sampleStore.replaceMerged"
/>
</Transition>
</div>
</template>

Expand Down
12 changes: 10 additions & 2 deletions packages/app/src/stores/sample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,24 @@ export const useSampleStore = defineStore('sampleCards', {
this.sampleCards.push(sampleCard);
},

async merge() {
async mergeSelected() {
const sample = await command('merge', { samples: this.selectedSamples });
const merged = await createSampleCard('merged.csv', sample.csv, ACTIVE_LEAGUE);
const merged = createSampleCardFromSample('merged.csv', sample, ACTIVE_LEAGUE);

// No point to select merged file, `null` makes it nonselectable by removing checkbox
// maybe should refactor later
merged.selected = null;
this.merged = merged;
},

async mergeAll() {
const sample = await command('merge', { samples: this.samples });
const merged = createSampleCardFromSample('merged.csv', sample, ACTIVE_LEAGUE);

merged.selected = null;
this.merged = merged;
},

downloadAll() {
for (const file of this.sampleCards) {
downloadText(file.filename, file.sample.csv);
Expand Down

0 comments on commit 5ee3d74

Please sign in to comment.