Fix moving resources

Closes #838

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2021-08-20 17:13:04 +02:00
parent 04fff8485e
commit a7a0c58ae3
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773
2 changed files with 23 additions and 7 deletions

View file

@ -59,7 +59,7 @@
{{ $t("No resources in this folder") }}
</p>
<b-pagination
v-if="resource.children.total > RESOURCES_PER_PAGE"
v-if="resource.children && resource.children.total > RESOURCES_PER_PAGE"
:total="resource.children.total"
v-model="page"
size="is-small"

View file

@ -622,8 +622,7 @@ export default class Resources extends Mixins(ResourceMixin) {
}
const updatedResource: IResource = data.updateResource;
// eslint-disable-next-line vue/max-len
oldParentCachedResource.children.elements =
const updatedElementList =
oldParentCachedResource.children.elements.filter(
(cachedResource) => cachedResource.id !== updatedResource.id
);
@ -634,7 +633,15 @@ export default class Resources extends Mixins(ResourceMixin) {
path: parentPath,
username: this.resource.actor.preferredUsername,
},
data: { oldParentCachedResource },
data: {
resource: {
...oldParentCachedResource,
children: {
...oldParentCachedResource.children,
elements: [...updatedElementList],
},
},
},
});
console.log("Finished removing ressource from old parent");
@ -659,15 +666,24 @@ export default class Resources extends Mixins(ResourceMixin) {
return;
}
newParentCachedResource.children.elements.push(resource);
store.writeQuery({
query: GET_RESOURCE,
variables: {
path: updatedResource.parent.path,
username: this.resource.actor.preferredUsername,
},
data: { newParentCachedResource },
data: {
resource: {
...newParentCachedResource,
children: {
...newParentCachedResource.children,
elements: [
...newParentCachedResource.children.elements,
resource,
],
},
},
},
});
console.log("Finished adding resource to new parent");
},