1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-07-16 00:14:34 +02:00

Mobile: Plugin settings: Fix plugins without settings can't be disabled without reinstall (#10579)

Co-authored-by: Laurent Cozic <laurent22@users.noreply.github.com>
This commit is contained in:
Henry Heino
2024-06-14 11:36:26 -07:00
committed by GitHub
parent 9e2b9e5b8d
commit ce22d8238c
3 changed files with 51 additions and 12 deletions

View File

@ -2,7 +2,7 @@ import { ItemEvent, OnPluginSettingChangeEvent } from '@joplin/lib/components/sh
import useOnDeleteHandler from '@joplin/lib/components/shared/config/plugins/useOnDeleteHandler';
import useOnInstallHandler from '@joplin/lib/components/shared/config/plugins/useOnInstallHandler';
import NavService from '@joplin/lib/services/NavService';
import { PluginSettings } from '@joplin/lib/services/plugins/PluginService';
import { PluginSettings, defaultPluginSetting } from '@joplin/lib/services/plugins/PluginService';
import RepositoryApi from '@joplin/lib/services/plugins/RepositoryApi';
import { useCallback, useMemo, useState } from 'react';
@ -29,14 +29,18 @@ const usePluginCallbacks = (props: Props) => {
const updatePluginEnabled = useCallback((pluginId: string, enabled: boolean) => {
const newSettings = { ...props.pluginSettings };
newSettings[pluginId].enabled = enabled;
newSettings[pluginId] = {
...defaultPluginSetting(),
...newSettings[pluginId],
enabled,
};
props.updatePluginStates(newSettings);
}, [props.pluginSettings, props.updatePluginStates]);
const onToggle = useCallback((event: ItemEvent) => {
const pluginId = event.item.manifest.id;
const settings = props.pluginSettings[pluginId];
const settings = props.pluginSettings[pluginId] ?? defaultPluginSetting();
updatePluginEnabled(pluginId, !settings.enabled);
}, [props.pluginSettings, updatePluginEnabled]);