Use one callback for setting sysprompt state

1d124ba7709c1c046884d7b52ae03f5133274a9d

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +11 -14Showing whitespace changes
public/scripts/sysprompt.js+11 -14
@@ -86,17 +86,14 @@ function toggleSystemPromptDisabledControls() {
86 $contentBlock.toggleClass('disabled', !power_user.sysprompt.enabled);86 $contentBlock.toggleClass('disabled', !power_user.sysprompt.enabled);
87}87}
8888
89function 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 '';94function setSystemPromptStateCallback(state) {
95}95 power_user.sysprompt.enabled = state;
9696 $enabled.prop('checked', state);
97function disableSystemPromptCallback() {
98 power_user.sysprompt.enabled = false;
99 $enabled.prop('checked', false);
100 toggleSystemPromptDisabledControls();97 toggleSystemPromptDisabledControls();
101 saveSettingsDebounced();98 saveSettingsDebounced();
102 return '';99 return '';
@@ -108,7 +105,7 @@ function toggleSystemPromptCallback(_args, state) {
108 }105 }
109106
110 const newState = isTrueBoolean(state);107 const newState = isTrueBoolean(state);
111 newState ? enableSystemPromptCallback() : disableSystemPromptCallback();108 newState ? setSystemPromptStateCallback(true) : setSystemPromptStateCallback(false);
112 return String(power_user.sysprompt.enabled);109 return String(power_user.sysprompt.enabled);
113}110}
114111
@@ -219,13 +216,13 @@ export function initSystemPrompts() {
219 SlashCommandParser.addCommandObject(SlashCommand.fromProps({216 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
220 name: 'sysprompt-on',217 name: 'sysprompt-on',
221 aliases: ['sysprompt-enable'],218 aliases: ['sysprompt-enable'],
222 callback: enableSystemPromptCallback,219 callback: () => setSystemPromptStateCallback(true),
223 helpString: 'Enables system prompt.',220 helpString: 'Enables system prompt.',
224 }));221 }));
225 SlashCommandParser.addCommandObject(SlashCommand.fromProps({222 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
226 name: 'sysprompt-off',223 name: 'sysprompt-off',
227 aliases: ['sysprompt-disable'],224 aliases: ['sysprompt-disable'],
228 callback: disableSystemPromptCallback,225 callback: () => setSystemPromptStateCallback(false),
229 helpString: 'Disables system prompt',226 helpString: 'Disables system prompt',
230 }));227 }));
231 SlashCommandParser.addCommandObject(SlashCommand.fromProps({228 SlashCommandParser.addCommandObject(SlashCommand.fromProps({