Skip to content

Commit

Permalink
Update extension list after removing an obsolete extension (#579)
Browse files Browse the repository at this point in the history
The removed extension was never removed from the cached list
  • Loading branch information
schroda authored Jan 29, 2024
1 parent cee566d commit 506e0aa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/components/ExtensionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}"`);
Expand Down
30 changes: 17 additions & 13 deletions src/lib/requests/RequestManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>(
Expand All @@ -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;
}

return {
...extension,
...response.data?.updateExtension.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,
};
}),
},
},
};
Expand Down

0 comments on commit 506e0aa

Please sign in to comment.