Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/src/api/controllers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ export async function deleteUser(req: MonkeyRequest): Promise<MonkeyResponse> {

if (error) {
if (error instanceof MonkeyError && error.status === 404) {
//userinfo was already deleted. We ignore this and still try to remove the other data
//userinfo was already deleted. We ignore and still try to remove the other data
} else {
throw error;
}
Expand Down
19 changes: 19 additions & 0 deletions frontend/src/html/pages/account-settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,25 @@
</button>
</div>
</div>
<div class="section resultSaving">
<div class="title">
<i class="fas fa-save"></i>
<span>result saving</span>
</div>
<div class="text">
Toggle result saving. When disabled, results will not be saved (
<b>practice mode</b>
).
</div>
<div class="buttons">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd just use two buttons like we do on the settings page for toggles:

Image

<label class="toggleSwitch">
<input type="checkbox" id="toggleResultSaving" />
<span class="track" aria-hidden="true"></span>
<span class="toggleLabel">on</span>
</label>
</div>
</div>

<!-- -->
</div>
<div class="tab hidden" data-tab="apeKeys">
Expand Down
66 changes: 66 additions & 0 deletions frontend/src/styles/account-settings.scss
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,72 @@
color: var(--error-color);
}
}
&.resultSaving {
.buttons {
justify-items: center;
}
.toggleSwitch {
display: inline-flex;
align-items: center;
gap: 0.75rem;
cursor: pointer;
user-select: none;
}

.toggleSwitch input {
position: absolute;
opacity: 0;
width: 0;
height: 0;
}

.toggleSwitch .track {
width: 3rem;
height: 1.6rem;
border-radius: 999px;
background: var(--sub-alt-color);
border: 1px solid var(--sub-color);
position: relative;
transition:
background 0.2s ease,
border-color 0.2s ease;
}

.toggleSwitch .track::after {
content: "";
position: absolute;
top: 2px;
left: 2px;
width: 1.2rem;
height: 1.2rem;
border-radius: 999px;
background: var(--text-color);
transition:
transform 0.2s ease,
background 0.2s ease;
}

.toggleSwitch input:checked + .track {
background: var(--main-color);
border-color: var(--main-color);
}

.toggleSwitch input:checked + .track::after {
transform: translateX(1.4rem);
background: var(--bg-color);
}

.toggleSwitch .toggleLabel {
color: var(--sub-color);
text-transform: uppercase;
letter-spacing: 0.08em;
font-size: 0.75rem;
}

.toggleSwitch input:checked ~ .toggleLabel {
color: var(--main-color);
}
}
}
&[data-tab="apeKeys"],
&[data-tab="blockedUsers"] {
Expand Down
11 changes: 8 additions & 3 deletions frontend/src/ts/ape/adapters/ts-rest-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@ function buildApi(timeout: number): (args: ApiFetcherArgs) => Promise<{
}> {
return async (request: ApiFetcherArgs) => {
try {
const token = await getIdToken();
if (token !== null) {
request.headers["Authorization"] = `Bearer ${token}`;
// ===== DEV AUTH (LOCAL ONLY) =====
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please revert

if (import.meta.env.DEV) {
request.headers["Authorization"] = "Uid localuser|vishal@test.com";
} else {
const token = await getIdToken();
if (token !== null) {
request.headers["Authorization"] = `Bearer ${token}`;
}
}

const usePolyfill = AbortSignal?.timeout === undefined;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ts/commandline/lists/result-saving.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const commands: Command[] = [
id: "setResultSaving",
display: "Result saving...",
icon: "fa-save",
alias: "results",
alias: "results practice",
subgroup,
},
];
Expand Down
1 change: 1 addition & 0 deletions frontend/src/ts/firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ export async function getIdToken(): Promise<string | null> {
if (user === null) return null;
return firebaseGetIdToken(user);
}

async function setPersistence(
rememberMe: boolean,
store = false,
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/ts/modals/simple-modals-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type PopupKey =
| "deleteAccount"
| "resetAccount"
| "optOutOfLeaderboards"
| "toggleResultSaving"
| "applyCustomFont"
| "resetPersonalBests"
| "resetSettings"
Expand All @@ -38,6 +39,7 @@ export const list: Record<PopupKey, SimpleModal | undefined> = {
deleteAccount: undefined,
resetAccount: undefined,
optOutOfLeaderboards: undefined,
toggleResultSaving: undefined,
applyCustomFont: undefined,
resetPersonalBests: undefined,
resetSettings: undefined,
Expand Down
22 changes: 22 additions & 0 deletions frontend/src/ts/modals/simple-modals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import * as Settings from "../pages/settings";
import * as ThemePicker from "../elements/settings/theme-picker";
import * as CustomText from "../test/custom-text";
import { FirebaseError } from "firebase/app";
import * as TestState from "../test/test-state";
import * as ModesNotice from "../elements/modes-notice";

import {
isAuthenticated,
getAuthenticatedUser,
Expand Down Expand Up @@ -816,6 +819,25 @@ list.optOutOfLeaderboards = new SimpleModal({
},
});

list.toggleResultSaving = new SimpleModal({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused

id: "toggleResultSaving",
title: "Result saving",
text: "Toggle result saving. When disabled, results will not be saved (practice mode).",
buttonText: "toggle",
execFn: async (): Promise<ExecReturn> => {
const current = TestState.savingEnabled;
TestState.setSaving(!current);
await ModesNotice.update();

return {
status: 1,
message: !current
? "Result saving enabled"
: "Result saving disabled (practice mode)",
};
},
});

list.applyCustomFont = new SimpleModal({
id: "applyCustomFont",
title: "Custom font",
Expand Down
34 changes: 34 additions & 0 deletions frontend/src/ts/pages/account-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import { getActivePage } from "../signals/core";
import { swapElements } from "../utils/misc";
import { getSnapshot } from "../db";
import Ape from "../ape";
import * as TestState from "../test/test-state";
import * as StreakHourOffsetModal from "../modals/streak-hour-offset";
import { showLoaderBar } from "../signals/loader-bar";
import * as ApeKeyTable from "../elements/account-settings/ape-key-table";
import * as BlockedUserTable from "../elements/account-settings/blocked-user-table";
import * as Notifications from "../elements/notifications";
import * as ModesNotice from "../elements/modes-notice";
import { z } from "zod";
import * as AuthEvent from "../observables/auth-event";
import { qs, qsa, qsr, onDOMReady } from "../utils/dom";
Expand Down Expand Up @@ -147,11 +149,24 @@ function updateAccountSections(): void {
}
}

function updateResultSavingToggle(): void {
const toggle = pageElement.qs(
"#toggleResultSaving",
) as HTMLInputElement | null;
if (!toggle) return;
Copy link
Contributor

@Leonabcd123 Leonabcd123 Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using this:

pageElement.qs<HTMLInputElement>("#toggleResultSaving")?.setChecked(TestState.savingEnabled);
pageElement
  .qs(".section.resultSaving .toggleLabel")
  ?.setText(TestState.savingEnabled ? "on" : "off");


toggle.checked = TestState.savingEnabled;
pageElement
.qs(".section.resultSaving .toggleLabel")
?.setText(TestState.savingEnabled ? "on" : "off");
}

export function updateUI(): void {
if (getActivePage() !== "accountSettings") return;
updateAuthenticationSections();
updateIntegrationSections();
updateAccountSections();
updateResultSavingToggle();
void ApeKeyTable.update(updateUI);
void BlockedUserTable.update();
updateTabs();
Expand Down Expand Up @@ -241,6 +256,25 @@ qs(".pageAccountSettings")?.onChild(
showPopup("resetPersonalBests");
},
);
qs(".pageAccountSettings")?.onChild(
"change",
"#toggleResultSaving",
(event) => {
const target = event.target as HTMLInputElement | null;
if (!target) return;

TestState.setSaving(target.checked);
void ModesNotice.update();
updateResultSavingToggle();

Notifications.add(
target.checked
? "Result saving enabled"
: "Result saving disabled (practice mode)",
1,
);
},
);

qs(".pageAccountSettings")?.onChild("click", "#updateAccountName", () => {
showPopup("updateName");
Expand Down