Skip to content

Commit

Permalink
refactor(config): remove "show live progress" and move it to "live pr…
Browse files Browse the repository at this point in the history
…ogress style: off"
  • Loading branch information
Miodec committed Apr 25, 2024
1 parent aa00a0b commit 79e8566
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 91 deletions.
3 changes: 1 addition & 2 deletions backend/src/api/schemas/config-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const CONFIG_SCHEMA = joi.object({
favThemes: joi.array().items(joi.string().max(50).token()),
showKeyTips: joi.boolean(),
showLiveWpm: joi.boolean(),
showTimerProgress: joi.boolean(),
smoothCaret: joi.string().valid("off", "slow", "medium", "fast"),
quickRestart: joi.string().valid("off", "tab", "esc", "enter"),
punctuation: joi.boolean(),
Expand Down Expand Up @@ -53,7 +52,7 @@ const CONFIG_SCHEMA = joi.object({
.regex(/[\w#]+/),
confidenceMode: joi.string().valid("off", "on", "max"),
indicateTypos: joi.string().valid("off", "below", "replace"),
timerStyle: joi.string().valid("bar", "text", "mini"),
timerStyle: joi.string().valid("off", "bar", "text", "mini"),
colorfulMode: joi.boolean(),
randomTheme: joi
.string()
Expand Down
15 changes: 1 addition & 14 deletions frontend/src/html/pages/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,7 @@
Change the style of the timer/word count during a timed test.
</div>
<div class="buttons">
<button data-config-value="off">off</button>
<button data-config-value="bar">bar</button>
<button data-config-value="text">text</button>
<button data-config-value="mini">mini</button>
Expand Down Expand Up @@ -1414,20 +1415,6 @@
<button data-config-value="true">show</button>
</div>
</div>
<div class="section" data-config-name="showTimerProgress">
<div class="groupTitle">
<i class="fas fa-chart-pie"></i>
<span>live progress</span>
</div>
<div class="text">
Displays a live timer for timed tests and word count for word based
tests (word, quote or custom mode).
</div>
<div class="buttons">
<button data-config-value="false">hide</button>
<button data-config-value="true">show</button>
</div>
</div>
<div class="section" data-config-name="showKeyTips">
<div class="groupTitle">
<i class="fas fa-question"></i>
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/ts/commandline/lists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import LiveWpmCommands from "./lists/live-wpm";
import LiveAccCommands from "./lists/live-acc";
import LiveBurstCommands from "./lists/live-burst";
import ShowAverageCommands from "./lists/show-average";
import ShowTimerCommands from "./lists/show-timer";
import KeyTipsCommands from "./lists/key-tips";
import FreedomModeCommands from "./lists/freedom-mode";
import StrictSpaceCommands from "./lists/strict-space";
Expand Down Expand Up @@ -328,7 +327,6 @@ export const commands: MonkeyTypes.CommandsSubgroup = {
...LiveWpmCommands,
...LiveAccCommands,
...LiveBurstCommands,
...ShowTimerCommands,
...KeyTipsCommands,
...OutOfFocusWarningCommands,
...CapsLockWarningCommands,
Expand Down
37 changes: 0 additions & 37 deletions frontend/src/ts/commandline/lists/show-timer.ts

This file was deleted.

12 changes: 9 additions & 3 deletions frontend/src/ts/commandline/lists/timer-style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@ const subgroup: MonkeyTypes.CommandsSubgroup = {
title: "Live progress style...",
configKey: "timerStyle",
list: [
{
id: "setTimerStyleOff",
display: "off",
configValue: "off",
exec: (): void => {
UpdateConfig.setTimerStyle("off");
},
},
{
id: "setTimerStyleBar",
display: "bar",
configValue: "bar",
alias: "timer",
exec: (): void => {
UpdateConfig.setTimerStyle("bar");
},
Expand All @@ -17,7 +24,6 @@ const subgroup: MonkeyTypes.CommandsSubgroup = {
id: "setTimerStyleText",
display: "text",
configValue: "text",
alias: "timer",
exec: (): void => {
UpdateConfig.setTimerStyle("text");
},
Expand All @@ -26,7 +32,6 @@ const subgroup: MonkeyTypes.CommandsSubgroup = {
id: "setTimerStyleMini",
display: "mini",
configValue: "mini",
alias: "timer",
exec: (): void => {
UpdateConfig.setTimerStyle("mini");
},
Expand All @@ -39,6 +44,7 @@ const commands: MonkeyTypes.Command[] = [
id: "changeTimerStyle",
display: "Live progress style...",
icon: "fa-chart-pie",
alias: "timer",
subgroup,
},
];
Expand Down
25 changes: 8 additions & 17 deletions frontend/src/ts/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -822,21 +822,6 @@ export function setPaceCaretStyle(
return true;
}

export function setShowTimerProgress(
timer: boolean,
nosave?: boolean
): boolean {
if (!isConfigValueValid("show timer progress", timer, ["boolean"])) {
return false;
}

config.showTimerProgress = timer;
saveToLocalStorage("showTimerProgress", nosave);
ConfigEvent.dispatch("showTimerProgress", config.showTimerProgress);

return true;
}

export function setShowLiveWpm(live: boolean, nosave?: boolean): boolean {
if (!isConfigValueValid("show live speed", live, ["boolean"])) return false;

Expand Down Expand Up @@ -949,7 +934,9 @@ export function setTimerStyle(
style: SharedTypes.Config.TimerStyle,
nosave?: boolean
): boolean {
if (!isConfigValueValid("timer style", style, [["bar", "text", "mini"]])) {
if (
!isConfigValueValid("timer style", style, [["off", "bar", "text", "mini"]])
) {
return false;
}

Expand Down Expand Up @@ -1851,7 +1838,6 @@ export async function apply(
setShowLiveWpm(configObj.showLiveWpm, true);
setShowLiveAcc(configObj.showLiveAcc, true);
setShowLiveBurst(configObj.showLiveBurst, true);
setShowTimerProgress(configObj.showTimerProgress, true);
setAlwaysShowDecimalPlaces(configObj.alwaysShowDecimalPlaces, true);
setAlwaysShowWordsHistory(configObj.alwaysShowWordsHistory, true);
setSingleListCommandLine(configObj.singleListCommandLine, true);
Expand Down Expand Up @@ -1966,6 +1952,11 @@ function replaceLegacyValues(
configObj.playSoundOnError = configObj.playSoundOnError ? "1" : "off";
}

//@ts-expect-error
if (configObj.showTimerProgress === false) {
configObj.timerStyle = "off";
}

return configObj;
}

Expand Down
1 change: 0 additions & 1 deletion frontend/src/ts/constants/default-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export default {
favThemes: [],
showKeyTips: true,
showLiveWpm: false,
showTimerProgress: true,
smoothCaret: "medium",
quickRestart: "off",
punctuation: false,
Expand Down
5 changes: 0 additions & 5 deletions frontend/src/ts/pages/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ async function initGroups(): Promise<void> {
UpdateConfig.setShowLiveBurst,
"button"
) as SettingsGroup<SharedTypes.ConfigValue>;
groups["showTimerProgress"] = new SettingsGroup(
"showTimerProgress",
UpdateConfig.setShowTimerProgress,
"button"
) as SettingsGroup<SharedTypes.ConfigValue>;
groups["showAverage"] = new SettingsGroup(
"showAverage",
UpdateConfig.setShowAverage,
Expand Down
10 changes: 2 additions & 8 deletions frontend/src/ts/test/timer-progress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as TestState from "./test-state";
import * as ConfigEvent from "../observables/config-event";

export function show(): void {
const op = Config.showTimerProgress ? parseFloat(Config.timerOpacity) : 0;
const op = Config.timerStyle !== "off" ? parseFloat(Config.timerOpacity) : 0;
if (Config.mode !== "zen" && Config.timerStyle === "bar") {
$("#timerWrapper").stop(true, true).removeClass("hidden").animate(
{
Expand Down Expand Up @@ -219,18 +219,12 @@ export function updateStyle(): void {
if (!TestState.isActive) return;
hide();
update();
if (Config.timerStyle === "off") return;
setTimeout(() => {
show();
}, 125);
}

ConfigEvent.subscribe((eventKey, eventValue) => {
if (eventKey === "showTimerProgress") {
if (eventValue === true && TestState.isActive) {
show();
} else {
hide();
}
}
if (eventKey === "timerStyle") updateStyle();
});
2 changes: 1 addition & 1 deletion shared-types/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ declare namespace SharedTypes.Config {
type Mode2Custom<M extends Mode> = Mode2<M> | "custom";
type ConfidenceMode = "off" | "on" | "max";
type IndicateTypos = "off" | "below" | "replace";
type TimerStyle = "bar" | "text" | "mini";
type TimerStyle = "off" | "bar" | "text" | "mini";
type RandomTheme = "off" | "on" | "fav" | "light" | "dark" | "custom";
type TimerColor = "black" | "sub" | "text" | "main";
type TimerOpacity = "0.25" | "0.5" | "0.75" | "1";
Expand Down
1 change: 0 additions & 1 deletion shared-types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,6 @@ declare namespace SharedTypes {
favThemes: string[];
showKeyTips: boolean;
showLiveWpm: boolean;
showTimerProgress: boolean;
smoothCaret: SharedTypes.Config.SmoothCaret;
quickRestart: SharedTypes.Config.QuickRestart;
punctuation: boolean;
Expand Down

0 comments on commit 79e8566

Please sign in to comment.