Add filter function
This commit is contained in:
parent
77aede3948
commit
ce645001a1
|
|
@ -4,9 +4,9 @@
|
||||||
<input
|
<input
|
||||||
class="filter-bar__search-input"
|
class="filter-bar__search-input"
|
||||||
type="text"
|
type="text"
|
||||||
:value="searchText"
|
|
||||||
@input="debouncedUpdate"
|
|
||||||
placeholder="Suchbegriff eingeben..."
|
placeholder="Suchbegriff eingeben..."
|
||||||
|
v-model="searchQuery"
|
||||||
|
@input="updateSearch"
|
||||||
/>
|
/>
|
||||||
<SearchMagnifyingGlass class="filter-bar__search-icon"></SearchMagnifyingGlass>
|
<SearchMagnifyingGlass class="filter-bar__search-icon"></SearchMagnifyingGlass>
|
||||||
<!-- Font Awesome search icon as an example -->
|
<!-- Font Awesome search icon as an example -->
|
||||||
|
|
@ -21,43 +21,24 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import debounce from 'lodash/debounce';
|
import { ref } from 'vue';
|
||||||
import { ref, watchEffect } from 'vue';
|
|
||||||
import NoteIcon from '@/components/icons/NoteIcon.vue';
|
|
||||||
import PillRadioButtons from '@/components/ui/PillRadioButtons.vue';
|
import PillRadioButtons from '@/components/ui/PillRadioButtons.vue';
|
||||||
import SearchMagnifyingGlass from "@/components/icons/SearchMagnifyingGlass.vue";
|
import SearchMagnifyingGlass from '@/components/icons/SearchMagnifyingGlass.vue';
|
||||||
|
|
||||||
const props = defineProps({
|
const searchQuery = ref('');
|
||||||
searchText: {
|
const emit = defineEmits(['update:filter']);
|
||||||
type: String,
|
|
||||||
default: '',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const emit = defineEmits(['filter']);
|
const updateSearch = () => {
|
||||||
|
emit('update:filter', searchQuery.value);
|
||||||
|
};
|
||||||
|
|
||||||
const languageOptions: Array<{ id: number; label: string }> = ref([
|
const languageOptions: Array<{ id: number; label: string }> = ref([
|
||||||
{ id: 1, label: 'De' },
|
{ id: 1, label: 'De' },
|
||||||
{ id: 2, label: 'Fr' },
|
{ id: 2, label: 'Fr' },
|
||||||
{ id: 3, label: 'En' },
|
{ id: 3, label: 'En' },
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const initialLanguage = languageOptions.value[0];
|
const initialLanguage = languageOptions.value[0];
|
||||||
|
|
||||||
const searchText = ref(props.searchText);
|
|
||||||
|
|
||||||
watchEffect(() => {
|
|
||||||
searchText.value = props.searchText;
|
|
||||||
});
|
|
||||||
|
|
||||||
const updateSearchText = (searchText: string) => {
|
|
||||||
console.log('filter', searchText);
|
|
||||||
emit('filter', searchText);
|
|
||||||
};
|
|
||||||
|
|
||||||
const debouncedUpdate = debounce((event: Event) => {
|
|
||||||
const inputElement = event.target as HTMLInputElement;
|
|
||||||
updateSearchText(inputElement.value);
|
|
||||||
}, 200);
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
|
|
|
||||||
|
|
@ -49,11 +49,12 @@ export default defineComponent({
|
||||||
FilterEntry,
|
FilterEntry,
|
||||||
},
|
},
|
||||||
|
|
||||||
apollo: {
|
// TODO: Ramon: I think this code is not needed anymore
|
||||||
instrumentFilter: {
|
// apollo: {
|
||||||
query: INSTRUMENT_FILTER_QUERY,
|
// instrumentFilter: {
|
||||||
},
|
// query: INSTRUMENT_FILTER_QUERY,
|
||||||
},
|
// },
|
||||||
|
// },
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,7 @@
|
||||||
v-else
|
v-else
|
||||||
/>
|
/>
|
||||||
<div class="instrument-overview__list">
|
<div class="instrument-overview__list">
|
||||||
<FilterBar>
|
<FilterBar v-model:filter="searchText"></FilterBar>
|
||||||
</FilterBar>
|
|
||||||
<router-link
|
<router-link
|
||||||
:to="{ name: 'instrument', params: { slug: instrument.slug } }"
|
:to="{ name: 'instrument', params: { slug: instrument.slug } }"
|
||||||
data-cy="instrument"
|
data-cy="instrument"
|
||||||
|
|
@ -29,7 +28,7 @@ import InstrumentFilter from '@/components/instruments/InstrumentFilter.vue';
|
||||||
import InstrumentEntry from '@/components/instruments/InstrumentEntry.vue';
|
import InstrumentEntry from '@/components/instruments/InstrumentEntry.vue';
|
||||||
import INSTRUMENTS_QUERY from '@/graphql/gql/queries/instrumentsQuery.gql';
|
import INSTRUMENTS_QUERY from '@/graphql/gql/queries/instrumentsQuery.gql';
|
||||||
import INSTRUMENT_FILTER_QUERY from 'gql/local/instrumentFilter.gql';
|
import INSTRUMENT_FILTER_QUERY from 'gql/local/instrumentFilter.gql';
|
||||||
import FilterBar from "@/components/instruments/FilterBar.vue";
|
import FilterBar from '@/components/instruments/FilterBar.vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
|
|
@ -71,12 +70,14 @@ export default {
|
||||||
instrumentFilter: {
|
instrumentFilter: {
|
||||||
currentFilter: '',
|
currentFilter: '',
|
||||||
},
|
},
|
||||||
|
searchText: '',
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
filteredInstruments() {
|
filteredInstruments() {
|
||||||
return this.instruments.filter((i) => this.filter(i));
|
let instruments = this.instruments.filter((i) => this.filter(i));
|
||||||
|
return instruments.filter((i) => i.title.toLowerCase().includes(this.searchText.toLowerCase()));
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue