Skip to content

Commit 5a17173

Browse files
authored
fix: incorrect status when installing extension (#789)
* fix: incorrect status when installing extension * docs: update changelog
1 parent 29d14ff commit 5a17173

2 files changed

Lines changed: 28 additions & 18 deletions

File tree

docs/content.en/docs/release-notes/_index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Information about release notes of Coco Server is provided here.
3030
- fix: resolved minor issues with voice playback #780
3131
- fix: fixed incorrect taskbar icon display on linux #783
3232
- fix: fix data inconsistency issue on secondary pages #784
33+
- fix: incorrect status when installing extension #789
3334

3435
### ✈️ Improvements
3536

src/components/Search/ExtensionStore.tsx

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ const ExtensionStore = () => {
8080
setSelectedExtension,
8181
installingExtensions,
8282
setInstallingExtensions,
83-
uninstallingExtensions,
8483
setUninstallingExtensions,
8584
visibleExtensionDetail,
8685
setVisibleExtensionDetail,
@@ -149,11 +148,7 @@ const ExtensionStore = () => {
149148
useKeyPress(
150149
`${modifierKey}.enter`,
151150
() => {
152-
if (
153-
visibleContextMenu ||
154-
visibleExtensionDetail ||
155-
selectedExtension?.installed
156-
) {
151+
if (visibleContextMenu || visibleExtensionDetail) {
157152
return;
158153
}
159154

@@ -181,42 +176,49 @@ const ExtensionStore = () => {
181176
setSelectedExtension(list[nextIndex]);
182177
});
183178

184-
const toggleInstall = (installed = true) => {
185-
if (!selectedExtension) return;
179+
const toggleInstall = (extension: SearchExtensionItem) => {
180+
if (!extension) return;
186181

187-
const { id } = selectedExtension;
182+
const { id, installed } = extension;
188183

189184
setList((prev) => {
190185
return prev.map((item) => {
191186
if (item.id === id) {
192-
return { ...item, installed };
187+
return { ...item, installed: !installed };
193188
}
194189

195190
return item;
196191
});
197192
});
198193

194+
const { selectedExtension } = useSearchStore.getState();
195+
199196
if (selectedExtension?.id === id) {
200197
setSelectedExtension({
201198
...selectedExtension,
202-
installed,
199+
installed: !installed,
203200
});
204201
}
205202
};
206203

207204
const handleInstall = async () => {
205+
const { selectedExtension, installingExtensions } =
206+
useSearchStore.getState();
207+
208208
if (!selectedExtension) return;
209209

210210
const { id, name, installed } = selectedExtension;
211211

212-
try {
213-
if (installed || installingExtensions.includes(id)) return;
212+
if (installed || installingExtensions.includes(id)) return;
214213

214+
try {
215215
setInstallingExtensions(installingExtensions.concat(id));
216216

217-
await platformAdapter.invokeBackend("install_extension_from_store", { id });
217+
await platformAdapter.invokeBackend("install_extension_from_store", {
218+
id,
219+
});
218220

219-
toggleInstall();
221+
toggleInstall(selectedExtension);
220222

221223
addError(
222224
`${name} ${t("extensionStore.hints.installationCompleted")}`,
@@ -225,28 +227,33 @@ const ExtensionStore = () => {
225227
} catch (error) {
226228
addError(String(error), "error");
227229
} finally {
230+
const { installingExtensions } = useSearchStore.getState();
231+
228232
setInstallingExtensions(
229233
installingExtensions.filter((item) => item !== id)
230234
);
231235
}
232236
};
233237

234238
const handleUnInstall = async () => {
239+
const { selectedExtension, uninstallingExtensions } =
240+
useSearchStore.getState();
241+
235242
if (!selectedExtension) return;
236243

237244
const { id, name, installed, developer } = selectedExtension;
238245

239-
try {
240-
if (!installed || uninstallingExtensions.includes(id)) return;
246+
if (!installed || uninstallingExtensions.includes(id)) return;
241247

248+
try {
242249
setUninstallingExtensions(uninstallingExtensions.concat(id));
243250

244251
await platformAdapter.invokeBackend("uninstall_extension", {
245252
developer: developer.id,
246253
extensionId: id,
247254
});
248255

249-
toggleInstall(false);
256+
toggleInstall(selectedExtension);
250257

251258
addError(
252259
`${name} ${t("extensionStore.hints.uninstallationCompleted")}`,
@@ -255,6 +262,8 @@ const ExtensionStore = () => {
255262
} catch (error) {
256263
addError(String(error), "error");
257264
} finally {
265+
const { uninstallingExtensions } = useSearchStore.getState();
266+
258267
setUninstallingExtensions(
259268
uninstallingExtensions.filter((item) => item !== id)
260269
);

0 commit comments

Comments
 (0)