Update extension list after removing an obsolete extension (#579)

The removed extension was never removed from the cached list
This commit is contained in:
schroda
2024-01-29 20:56:09 +01:00
committed by GitHub
parent cee566d9b2
commit 506e0aa0e3
2 changed files with 19 additions and 15 deletions

View File

@@ -110,13 +110,13 @@ export function ExtensionCard(props: IProps) {
setInstalledState(state);
switch (action) {
case ExtensionAction.INSTALL:
await requestManager.updateExtension(pkgName, { install: true }).response;
await requestManager.updateExtension(pkgName, { install: true, isObsolete }).response;
break;
case ExtensionAction.UNINSTALL:
await requestManager.updateExtension(pkgName, { uninstall: true }).response;
await requestManager.updateExtension(pkgName, { uninstall: true, isObsolete }).response;
break;
case ExtensionAction.UPDATE:
await requestManager.updateExtension(pkgName, { update: true }).response;
await requestManager.updateExtension(pkgName, { update: true, isObsolete }).response;
break;
default:
throw new Error(`Unexpected ExtensionAction "${action}"`);

View File

@@ -1015,7 +1015,7 @@ export class RequestManager {
public updateExtension(
id: string,
patch: UpdateExtensionPatchInput,
{ isObsolete = false, ...patch }: UpdateExtensionPatchInput & { isObsolete?: boolean },
options?: MutationOptions<UpdateExtensionMutation, UpdateExtensionMutationVariables>,
): AbortableApolloMutationResponse<UpdateExtensionMutation> {
const result = this.doRequest<UpdateExtensionMutation, UpdateExtensionMutationVariables>(
@@ -1042,18 +1042,22 @@ export class RequestManager {
...cachedExtensions.data,
fetchExtensions: {
...cachedExtensions.data.fetchExtensions,
extensions: cachedExtensions.data.fetchExtensions.extensions.map((extension) => {
const isUpdatedExtension =
extension.apkName === response.data?.updateExtension.extension?.apkName;
if (!isUpdatedExtension) {
return extension;
}
extensions: cachedExtensions.data.fetchExtensions.extensions
.filter((extension) => {
const isUpdatedExtension = id === extension.pkgName;
return isUpdatedExtension && !isObsolete;
})
.map((extension) => {
const isUpdatedExtension = id === extension.pkgName;
if (!isUpdatedExtension) {
return extension;
}
return {
...extension,
...response.data?.updateExtension.extension,
};
}),
return {
...extension,
...response.data?.updateExtension.extension,
};
}),
},
},
};