Add mixin for `me` query

This commit is contained in:
Ramon Wenger 2020-02-26 12:48:07 +01:00
parent dccbf2ae1a
commit e869cc8829
3 changed files with 35 additions and 44 deletions

View File

@ -23,11 +23,10 @@
import CurrentClass from '@/components/school-class/CurrentClass';
import openSidebar from '@/mixins/open-sidebar';
import ME_QUERY from '@/graphql/gql/meQuery.gql';
import me from '@/mixins/me';
export default {
mixins: [openSidebar],
mixins: [openSidebar, me],
components: {
ContentNavigation,
@ -43,19 +42,6 @@
return this.$route.meta.subnavigation;
}
},
data() {
return {
me: {}
}
},
apollo: {
me: {
query: ME_QUERY,
},
},
}
</script>

View File

@ -1,42 +1,19 @@
<template>
<span class="current-class">Klasse: {{currentClassSelection.name}}</span>
<span class="current-class">Klasse: {{currentClassName}}</span>
</template>
<script>
import ME_QUERY from '@/graphql/gql/meQuery.gql';
import me from '@/mixins/me';
export default {
apollo: {
me: {
query: ME_QUERY,
manual: true,
result({data, loading, networkStatus}) {
if (!loading) {
this.me = this.$getRidOfEdges(data).me;
}
}
}
},
data() {
return {
me: {
selectedClass: {
id: ''
},
permissions: [],
schoolClasses: []
},
showPopover: false
}
},
mixins: [me],
computed: {
currentClassSelection() {
currentClassName() {
let currentClass = this.me.schoolClasses.find(schoolClass => {
return schoolClass.id === this.me.selectedClass.id
});
return currentClass || this.me.schoolClasses[0];
return currentClass ? currentClass.name : this.me.schoolClasses.length ? this.me.schoolClasses[0].name : '';
}
}
}

28
client/src/mixins/me.js Normal file
View File

@ -0,0 +1,28 @@
import ME_QUERY from '@/graphql/gql/meQuery.gql';
export default {
data() {
return {
me: {
selectedClass: {
id: ''
},
permissions: [],
schoolClasses: []
},
showPopover: false
}
},
apollo: {
me: {
query: ME_QUERY,
manual: true,
result({data, loading, networkStatus}) {
if (!loading) {
this.me = this.$getRidOfEdges(data).me;
}
}
},
},
}