From cda9441c69e38373687ef64de00534c8e733e35a Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Tue, 26 Jan 2021 23:56:35 +0000 Subject: [PATCH] Desktop: Fixed installing plugins --- .../gui/ConfigScreen/controls/plugins/PluginBox.tsx | 12 ++++++++---- .../ConfigScreen/controls/plugins/PluginsStates.tsx | 10 +++++----- .../controls/plugins/useOnInstallHandler.ts | 5 +++-- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/packages/app-desktop/gui/ConfigScreen/controls/plugins/PluginBox.tsx b/packages/app-desktop/gui/ConfigScreen/controls/plugins/PluginBox.tsx index 527547205..dd3fc4a4b 100644 --- a/packages/app-desktop/gui/ConfigScreen/controls/plugins/PluginBox.tsx +++ b/packages/app-desktop/gui/ConfigScreen/controls/plugins/PluginBox.tsx @@ -20,6 +20,10 @@ export enum UpdateState { HasBeenUpdated = 4, } +export interface ItemEvent { + item: PluginItem; +} + interface Props { item?: PluginItem; manifest?: PluginManifest; @@ -27,10 +31,10 @@ interface Props { updateState?: UpdateState; themeId: number; isCompatible: boolean; - onToggle?: Function; - onDelete?: Function; - onInstall?: Function; - onUpdate?: Function; + onToggle?: (event: ItemEvent)=> void; + onDelete?: (event: ItemEvent)=> void; + onInstall?: (event: ItemEvent)=> void; + onUpdate?: (event: ItemEvent)=> void; } function manifestToItem(manifest: PluginManifest): PluginItem { diff --git a/packages/app-desktop/gui/ConfigScreen/controls/plugins/PluginsStates.tsx b/packages/app-desktop/gui/ConfigScreen/controls/plugins/PluginsStates.tsx index 7c80dff61..be49ea0a2 100644 --- a/packages/app-desktop/gui/ConfigScreen/controls/plugins/PluginsStates.tsx +++ b/packages/app-desktop/gui/ConfigScreen/controls/plugins/PluginsStates.tsx @@ -4,7 +4,7 @@ import PluginService, { defaultPluginSetting, Plugins, PluginSetting, PluginSett import { _ } from '@joplin/lib/locale'; import styled from 'styled-components'; import SearchPlugins from './SearchPlugins'; -import PluginBox, { UpdateState } from './PluginBox'; +import PluginBox, { ItemEvent, UpdateState } from './PluginBox'; import Button, { ButtonLevel } from '../../../Button/Button'; import bridge from '../../../../services/bridge'; import produce from 'immer'; @@ -128,8 +128,8 @@ export default function(props: Props) { }; }, [manifestsLoaded, pluginItems]); - const onDelete = useCallback(async (event: any) => { - const item: PluginItem = event.item; + const onDelete = useCallback(async (event: ItemEvent) => { + const item = event.item; const confirm = await bridge().showConfirmMessageBox(_('Delete plugin "%s"?', item.manifest.name)); if (!confirm) return; @@ -141,8 +141,8 @@ export default function(props: Props) { props.onChange({ value: pluginService.serializePluginSettings(newSettings) }); }, [pluginSettings, props.onChange]); - const onToggle = useCallback((event: any) => { - const item: PluginItem = event.item; + const onToggle = useCallback((event: ItemEvent) => { + const item = event.item; const newSettings = produce(pluginSettings, (draft: PluginSettings) => { if (!draft[item.manifest.id]) draft[item.manifest.id] = defaultPluginSetting(); diff --git a/packages/app-desktop/gui/ConfigScreen/controls/plugins/useOnInstallHandler.ts b/packages/app-desktop/gui/ConfigScreen/controls/plugins/useOnInstallHandler.ts index 231ed1df0..3031b0c56 100644 --- a/packages/app-desktop/gui/ConfigScreen/controls/plugins/useOnInstallHandler.ts +++ b/packages/app-desktop/gui/ConfigScreen/controls/plugins/useOnInstallHandler.ts @@ -3,6 +3,7 @@ import PluginService, { defaultPluginSetting, PluginSettings } from '@joplin/lib import produce from 'immer'; import { _ } from '@joplin/lib/locale'; import Logger from '@joplin/lib/Logger'; +import { ItemEvent } from './PluginBox'; const logger = Logger.create('useOnInstallHandler'); @@ -13,8 +14,8 @@ export interface OnPluginSettingChangeEvent { type OnPluginSettingChangeHandler = (event: OnPluginSettingChangeEvent)=> void; export default function(setInstallingPluginIds: Function, pluginSettings: PluginSettings, repoApi: Function, onPluginSettingsChange: OnPluginSettingChangeHandler, isUpdate: boolean) { - return useCallback(async (event: any) => { - const pluginId = event.item.id; + return useCallback(async (event: ItemEvent) => { + const pluginId = event.item.manifest.id; setInstallingPluginIds((prev: any) => { return {