MCPcopy
hub / github.com/monkeytypegame/monkeytype / toggleFunbox

Function toggleFunbox

frontend/src/ts/config/setters.ts:155–207  ·  view source on GitHub ↗
(funbox: FunboxName, nosave?: boolean)

Source from the content-addressed store, hash-verified

153}
154
155export function toggleFunbox(funbox: FunboxName, nosave?: boolean): boolean {
156 if (TestState.isActive && Config.funbox.includes("no_quit")) {
157 showNoticeNotification(
158 "No quit funbox is active. Please finish the test.",
159 {
160 important: true,
161 },
162 );
163 return false;
164 }
165
166 const funboxCheck = canSetFunboxWithConfig(funbox, Config);
167 if (!funboxCheck.ok) {
168 const errorStrings = funboxCheck.errors.map(
169 (e) =>
170 `${capitalizeFirstLetter(
171 camelCaseToWords(e.key),
172 )} cannot be set to ${String(e.value)}.`,
173 );
174 showNoticeNotification(
175 `You can't enable ${escapeHTML(funbox.replace(/_/g, " "))}:<br />${errorStrings.map((s) => escapeHTML(s)).join("<br />")}`,
176 { durationMs: 5000, useInnerHtml: true },
177 );
178 return false;
179 }
180
181 const previousValue = Config.funbox;
182
183 let newConfig: FunboxName[] = Config.funbox;
184
185 if (newConfig.includes(funbox)) {
186 newConfig = newConfig.filter((it) => it !== funbox);
187 } else {
188 newConfig = [...newConfig, funbox].sort();
189 }
190
191 if (!isConfigValueValid("funbox", newConfig, ConfigSchemas.FunboxSchema)) {
192 return false;
193 }
194
195 Config.funbox = newConfig;
196 saveToLocalStorage("funbox", nosave);
197 configEvent.dispatch({
198 key: "funbox",
199 newValue: Config.funbox,
200 nosave,
201 previousValue,
202 });
203
204 setConfigStore("funbox", newConfig);
205
206 return true;
207}

Callers 5

FunboxFunction · 0.90
addWordFunction · 0.90
getFunboxSectionFunction · 0.90
applyGlobalCSSFunction · 0.90
withWordsFunction · 0.90

Calls 9

showNoticeNotificationFunction · 0.90
canSetFunboxWithConfigFunction · 0.90
capitalizeFirstLetterFunction · 0.90
camelCaseToWordsFunction · 0.90
escapeHTMLFunction · 0.90
isConfigValueValidFunction · 0.90
saveToLocalStorageFunction · 0.90
setConfigStoreFunction · 0.90
dispatchMethod · 0.80

Tested by

no test coverage detected