Skip to content

Commit 735f7b3

Browse files
committed
fix(frontend): fix delete on car list
1 parent 2e82373 commit 735f7b3

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

frontend/src/app/cars/car-list/car-list.component.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,18 @@ export class CarListComponent implements OnInit, AfterViewInit {
5151
if (accept) {
5252
this.deleteCarGQL.mutate({
5353
id: id,
54+
}, {
55+
update: (proxy, {data: {deleteCar}}) => {
56+
// Read the data from our cache for this query.
57+
const data: any = proxy.readQuery({query: this.allCarsGQL.document});
58+
var index = data.cars.map(x => x.id).indexOf(id);
59+
data.cars.splice(index, 1);
60+
// Write our data back to the cache.
61+
proxy.writeQuery({query: this.allCarsGQL.document, data});
62+
}
5463
})
5564
.subscribe(({data}) => {
5665
console.log('Car deleted');
57-
this.router.navigate(['/cars'])
5866
}, (error) => {
5967
console.log('there was an error sending the query', error);
6068
});

0 commit comments

Comments
 (0)