Band filter by genre

This commit is contained in:
2024-10-22 20:11:09 +02:00
parent cf9a888a97
commit 048a8c30ff
5 changed files with 87 additions and 7 deletions

View File

@@ -178,5 +178,6 @@
"allConcerts": "Alle Konzerte", "allConcerts": "Alle Konzerte",
"more": "Mehr", "more": "Mehr",
"upcomingConcerts": "Nächste Konzerte", "upcomingConcerts": "Nächste Konzerte",
"pleaseLogin": "Bitte anmelden" "pleaseLogin": "Bitte anmelden",
"genres": "Genres"
} }

View File

@@ -178,5 +178,6 @@
"allConcerts": "All Concerts", "allConcerts": "All Concerts",
"more": "More", "more": "More",
"upcomingConcerts": "Upcoming Concerts", "upcomingConcerts": "Upcoming Concerts",
"pleaseLogin": "Please login" "pleaseLogin": "Please login",
"genres": "Genres"
} }

View File

@@ -0,0 +1,43 @@
<script setup lang="ts">
import cardView from '@/components/basics/cardView.vue';
import { useBandStore } from '@/stores/band.store';
import outlinedButton from '@/components/basics/outlinedButton.vue';
import { GenreModel } from '@/data/models/acts/genreModel';
const bandStore = useBandStore()
function itemProps(item: GenreModel) {
return {
title: item.name
}
}
</script>
<template>
<card-view :title="$t('filtering')">
<v-row>
<v-col>
<v-select
v-model="bandStore.filteredGenres"
:items="bandStore.availableGenres"
variant="outlined"
:label="$t('genres')"
:item-props="itemProps"
chips
clearable
hide-details
multiple
/>
</v-col>
<v-col cols="auto">
<outlined-button
@click="bandStore.getBands"
height="100%"
>
{{ $t('filtering') }}
</outlined-button>
</v-col>
</v-row>
</card-view>
</template>

View File

@@ -2,6 +2,7 @@
import { useBandStore } from '@/stores/band.store'; import { useBandStore } from '@/stores/band.store';
import cardViewHorizontal from '@/components/basics/cardViewHorizontal.vue'; import cardViewHorizontal from '@/components/basics/cardViewHorizontal.vue';
import bandListItem from '@/components/pageParts/bandListItem.vue'; import bandListItem from '@/components/pageParts/bandListItem.vue';
import bandFilterbar from './bandFilterbar.vue';
const bandStore = useBandStore() const bandStore = useBandStore()
@@ -16,7 +17,7 @@ bandStore.getBands()
<v-col cols="10"> <v-col cols="10">
<v-row> <v-row>
<v-col> <v-col>
Filterbar <band-filterbar />
</v-col> </v-col>
</v-row> </v-row>

View File

@@ -3,6 +3,8 @@ import { ref } from "vue";
import { BandApiModel } from "../data/models/acts/bandApiModel"; import { BandApiModel } from "../data/models/acts/bandApiModel";
import { fetchAllBands, fetchBandByName } from "../data/api/bandApi"; import { fetchAllBands, fetchBandByName } from "../data/api/bandApi";
import { BandDetailsApiModel } from "../data/models/acts/bandDetailsApiModel"; import { BandDetailsApiModel } from "../data/models/acts/bandDetailsApiModel";
import { GenreModel } from "@/data/models/acts/genreModel";
import { fetchAllGenres } from "@/data/api/genreApi";
export const useBandStore = defineStore("bandStore", { export const useBandStore = defineStore("bandStore", {
state: () => ({ state: () => ({
@@ -11,22 +13,54 @@ export const useBandStore = defineStore("bandStore", {
/** All information about a single band */ /** All information about a single band */
band: ref<BandDetailsApiModel>(new BandDetailsApiModel()), band: ref<BandDetailsApiModel>(new BandDetailsApiModel()),
filteredGenres: ref<Array<GenreModel>>([]),
availableGenres: ref<Array<GenreModel>>([]),
/** Request to server sent, waiting for data response */ /** Request to server sent, waiting for data response */
fetchInProgress: ref(false) fetchInProgress: ref(false)
}), }),
actions: { actions: {
/**
* Get all bands from server
*/
async getBands() { async getBands() {
this.fetchInProgress = true this.fetchInProgress = true
fetchAllBands() await fetchAllBands()
.then(result => { .then(result => {
this.bands = result.data this.bands = result.data.filter((band: BandApiModel) => {
this.fetchInProgress = false if (this.filteredGenres.length == 0) {
return true
}
for (let bandGenre of band.genres) {
for (let filteredGenres of this.filteredGenres) {
if (bandGenre.name == filteredGenres.name) {
return true
}
}
}
return false
})
}) })
await fetchAllGenres()
.then(result => {
this.availableGenres = result.data
})
this.fetchInProgress = false
}, },
/**
* Get all available data about a specific band
*
* @param name Name of band
*/
async getBand(name: string) { async getBand(name: string) {
this.fetchInProgress = true this.fetchInProgress = true
@@ -35,6 +69,6 @@ export const useBandStore = defineStore("bandStore", {
this.band = result.data this.band = result.data
this.fetchInProgress = false this.fetchInProgress = false
}) })
} }
} }
}) })