Clean up code

This commit is contained in:
Ramon Wenger 2018-09-26 09:24:14 +02:00
parent f3eb6ded51
commit cabbceb843
1 changed files with 8 additions and 5 deletions

View File

@ -11,8 +11,6 @@
import NEW_ROOM_ENTRY_MUTATION from '@/graphql/gql/mutations/addRoomEntry.gql';
import ROOM_ENTRIES_QUERY from '@/graphql/gql/roomEntriesQuery.gql';
import store from '@/store/index';
import ContentsForm from '@/components/content-block-form/ContentsForm';
export default {
@ -30,6 +28,12 @@
}
},
computed: {
room() {
return this.$store.state.parentRoom;
}
},
methods: {
saveEntry(entry) {
this.$apollo.mutate({
@ -37,14 +41,14 @@
variables: {
input: {
roomEntry: Object.assign({}, entry, {
room: store.state.parentRoom.id
room: this.room.id
})
}
},
update: (store, {data: {addRoomEntry: {roomEntry}}}) => {
try {
const query = ROOM_ENTRIES_QUERY;
const variables = {slug: this.$store.state.parentRoom.slug};
const variables = {slug: this.room.slug};
const data = store.readQuery({query, variables});
if (data.room && data.room.roomEntries) {
data.room.roomEntries.edges.push({
@ -54,7 +58,6 @@
store.writeQuery({query, variables, data});
}
} catch (e) {
console.error(e);
// Query did not exist in the cache, and apollo throws a generic Error. Do nothing
}
}