Fix snapshot list bug

This commit is contained in:
Ramon Wenger 2022-11-10 23:11:58 +01:00
parent be651c0489
commit 40f0f1cfb8
6 changed files with 1387 additions and 4474 deletions

View File

@ -141,10 +141,12 @@ describe('Snapshot', () => {
CreateSnapshot: {
createSnapshot: {
snapshot: {
id: '',
title: '',
created: '',
creator: '',
id: 'snapshot-id',
title: 'Mi Snapshot',
created: '2022-01-01',
creator: 'me',
shared: false,
mine: true
},
success: true,
},

5798
client/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -39,6 +39,7 @@
import me from '@/mixins/me';
import CREATE_SNAPSHOT_MUTATION from '@/graphql/gql/mutations/createSnapshot.gql';
import MODULE_SNAPSHOTS_QUERY from '@/graphql/gql/queries/moduleSnapshots.gql';
export default {
mixins: [me],
@ -66,10 +67,38 @@
selectedClass: this.me.selectedClass.id,
},
},
update: (store, {data: {createSnapshot: {snapshot}}}) => {
const slug = this.$route.params.slug;
const query = MODULE_SNAPSHOTS_QUERY;
const variables = {
slug,
};
const cached = store.readQuery({
query,
variables,
});
if (cached) {
const {module} = cached;
const data = {
module: {
...module,
snapshots: [
snapshot,
...module.snapshots,
],
}
};
store.writeQuery({
query,
variables,
data,
});
}
},
}).then(({data: {createSnapshot: {snapshot}}}) => {
this.showPopover = false;
this.$modal.open('snapshot-created', {
snapshot
snapshot,
});
});
},

View File

@ -0,0 +1,8 @@
fragment SnapshotParts on SnapshotNode {
id
title
created
mine
shared
creator
}

View File

@ -1,10 +1,8 @@
#import "../fragments/snapshotParts.gql"
mutation CreateSnapshot($input: CreateSnapshotInput!) {
createSnapshot(input: $input) {
snapshot {
id
title
created
creator
...SnapshotParts
}
success
}

View File

@ -1,3 +1,4 @@
#import "../fragments/snapshotParts.gql"
query ModuleSnapshotsQuery($slug: String!) {
module(slug: $slug) {
id
@ -8,12 +9,7 @@ query ModuleSnapshotsQuery($slug: String!) {
title
}
snapshots {
id
title
created
mine
shared
creator
...SnapshotParts
}
}
}