Files
eventmaster/software/src/data/stores/searchStore.ts
2024-10-11 12:59:21 +02:00

43 lines
1.0 KiB
TypeScript

import { defineStore } from "pinia";
import { ref } from "vue";
import { searchBand } from "../api/bandApi";
import { searchLocation } from "../api/locationApi";
import { searchEvent } from "../api/eventApi";
export const useSearchStore = defineStore("searchStore", {
state: () => ({
searchTerm: ref(""),
bands: ref(),
locations: ref(),
events: ref(),
alreadySearched: ref(false),
searchInProgress: ref(false)
}),
actions: {
/**
* Search for the termin in all bands, locations, events
*/
async startSearch() {
this.alreadySearched = true
this.searchInProgress = true
await searchBand(this.searchTerm)
.then(result => {
this.bands = result.data
})
await searchLocation(this.searchTerm)
.then(result => {
this.locations = result.data
})
await searchEvent(this.searchTerm)
.then(result => {
this.events = result.data
})
this.searchInProgress = false
}
}
})