Skip to content

Commit

Permalink
Add toasts to build library
Browse files Browse the repository at this point in the history
  • Loading branch information
Arzte committed Sep 16, 2024
1 parent 8bf7daa commit e44c91d
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions components/viewer/utils/BuildLibrary.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<template>
<div class="build-library">
<div class="input-group">
<input v-model="buildName" type="text" class="form-control" />
<input
v-model="buildName"
type="text"
class="form-control"
placeholder="Name of build"
/>
<button class="btn btn-outline-primary" @click="addStuff">Save</button>
</div>
<div v-show="loading" class="spinner-border" role="status">
Expand Down Expand Up @@ -29,7 +34,7 @@
</button>
<button
class="btn btn-sm btn-outline-danger"
@click="deleteBuild(build.id)"
@click="deleteBuild(build)"
>
Delete
</button>
Expand All @@ -41,11 +46,13 @@

<script setup lang="ts">
import * as R from 'ramda';
import { useToast } from 'vue-toastification';

import BuildChoices from '~/components/viewer/utils/BuildChoices.vue';
import { Selections, useProjectRefs } from '~/composables/store/project';
import { IndexedDB } from '~/composables/utils/idb';

const $toast = useToast();
const { selected } = useProjectRefs();
let db: IndexedDB;

Expand Down Expand Up @@ -88,6 +95,7 @@ const addStuff = async () => {
selected: R.clone(selected.value),
});
builds.value = await store.getAll();
$toast.success(`Saved build: ${buildName.value}`);
buildName.value = '';
});
};
Expand All @@ -101,19 +109,22 @@ const saveBuild = async (build: BuildData) => {
selected: R.clone(selected.value),
});
builds.value = await store.getAll();
$toast.success(`Updated Build: ${build.name}`);
});
};

const deleteBuild = async (id: number) => {
const deleteBuild = async (build: BuildData) => {
await db.transaction('builds', 'readwrite', async (tx) => {
const store = tx.objectStore('builds');
await store.delete(id);
await store.delete(build.id);
builds.value = await store.getAll();
});
$toast.success(`Deleted Build: ${build.name}`);
};

const loadBuild = (build: BuildData) => {
selected.value = build.selected;
$toast.info(`Loaded Build: ${build.name}`);
};
</script>

Expand Down

0 comments on commit e44c91d

Please sign in to comment.