Add language filter to instruments

This commit is contained in:
Lorenz Padberg 2023-08-29 15:10:47 +02:00
parent 6de2cc3ff0
commit 2246e9ca3c
5 changed files with 27 additions and 2 deletions

View File

@ -121,7 +121,6 @@ const filterByCategory = (module: ModuleNode, category: ModuleCategoryNode) => {
}; };
const filterByLanguage = (module: ModuleNode, language: string) => { const filterByLanguage = (module: ModuleNode, language: string) => {
// TODO: implement filter by language here.
return module.language === language; return module.language === language;
}; };

View File

@ -3,6 +3,7 @@ fragment InstrumentParts on InstrumentNode {
title title
intro intro
slug slug
language
bookmarks { bookmarks {
uuid uuid
note { note {

View File

@ -4,6 +4,7 @@ query InstrumentsQuery {
title title
contents contents
slug slug
language
type { type {
id id
type type

View File

@ -29,6 +29,8 @@ 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';
import ME_QUERY from '@/graphql/gql/queries/meQuery.gql';
import { graphql } from '@/__generated__';
export default { export default {
components: { components: {
@ -61,6 +63,15 @@ export default {
return instrumentFilter; return instrumentFilter;
}, },
}, },
me: {
query: graphql(`
query MeLanguage {
me {
language @client
}
}
`),
},
}, },
data() { data() {
@ -71,14 +82,23 @@ export default {
currentFilter: '', currentFilter: '',
}, },
searchText: '', searchText: '',
me: { language: 'de' },
}; };
}, },
computed: { computed: {
filteredInstruments() { filteredInstruments() {
// Filter by category and category type
let instruments = 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())); // Filter by language
instruments = instruments.filter((i) => i.language === this.me.language);
// Filter by search text
instruments = instruments.filter((i) => i.title.toLowerCase().includes(this.searchText.toLowerCase()));
return instruments;
}, },
// language() {
// return this.instruments.value?.me.language || 'de';
// },
}, },
methods: { methods: {

View File

@ -44,6 +44,7 @@ class InstrumentNode(DjangoObjectType):
bookmarks = graphene.List(InstrumentBookmarkNode) bookmarks = graphene.List(InstrumentBookmarkNode)
type = graphene.Field(InstrumentTypeNode) type = graphene.Field(InstrumentTypeNode)
contents = GenericStreamFieldType() contents = GenericStreamFieldType()
language = graphene.String()
class Meta: class Meta:
model = BasicKnowledge model = BasicKnowledge
@ -63,6 +64,9 @@ class InstrumentNode(DjangoObjectType):
instrument=self instrument=self
) )
def resolve_language(self, info, **kwargs):
return self.locale.language_code
class InstrumentQuery(object): class InstrumentQuery(object):
instrument = graphene.Field(InstrumentNode, slug=graphene.String(), id=graphene.ID()) instrument = graphene.Field(InstrumentNode, slug=graphene.String(), id=graphene.ID())