Use one callback for setting sysprompt state
| @@ -86,17 +86,14 @@ function toggleSystemPromptDisabledControls() { | ||
| 86 | 86 | $contentBlock.toggleClass('disabled', !power_user.sysprompt.enabled); |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | -function enableSystemPromptCallback() { | |
| 89 | +/** | |
| 90 | - power_user.sysprompt.enabled = true; | |
| 90 | + * Sets the system prompt state. | |
| 91 | - $enabled.prop('checked', true); | |
| 91 | + * @param {boolean} state System prompt state | |
| 92 | - toggleSystemPromptDisabledControls(); | |
| 92 | + * @returns {string} Empty string | |
| 93 | - saveSettingsDebounced(); | |
| 93 | + */ | |
| 94 | - return ''; | |
| 94 | +function setSystemPromptStateCallback(state) { | |
| 95 | -} | |
| 95 | + power_user.sysprompt.enabled = state; | |
| 96 | - | |
| 96 | + $enabled.prop('checked', state); | |
| 97 | -function disableSystemPromptCallback() { | |
| 98 | - power_user.sysprompt.enabled = false; | |
| 99 | - $enabled.prop('checked', false); | |
| 100 | 97 | toggleSystemPromptDisabledControls(); |
| 101 | 98 | saveSettingsDebounced(); |
| 102 | 99 | return ''; |
| @@ -108,7 +105,7 @@ function toggleSystemPromptCallback(_args, state) { | ||
| 108 | 105 | } |
| 109 | 106 | |
| 110 | 107 | const newState = isTrueBoolean(state); |
| 111 | 108 | newState ? enableSystemPromptCallbacksetSystemPromptStateCallback(true) : disableSystemPromptCallbacksetSystemPromptStateCallback(false); |
| 112 | 109 | return String(power_user.sysprompt.enabled); |
| 113 | 110 | } |
| 114 | 111 | |
| @@ -219,13 +216,13 @@ export function initSystemPrompts() { | ||
| 219 | 216 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ |
| 220 | 217 | name: 'sysprompt-on', |
| 221 | 218 | aliases: ['sysprompt-enable'], |
| 222 | - callback: enableSystemPromptCallback, | |
| 219 | + callback: () => setSystemPromptStateCallback(true), | |
| 223 | 220 | helpString: 'Enables system prompt.', |
| 224 | 221 | })); |
| 225 | 222 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ |
| 226 | 223 | name: 'sysprompt-off', |
| 227 | 224 | aliases: ['sysprompt-disable'], |
| 228 | - callback: disableSystemPromptCallback, | |
| 225 | + callback: () => setSystemPromptStateCallback(false), | |
| 229 | 226 | helpString: 'Disables system prompt', |
| 230 | 227 | })); |
| 231 | 228 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ |