-
-
Notifications
You must be signed in to change notification settings - Fork 3k
feat: add practice typing mode (no stats, xp, or pb) (@Vishal27alpha) #7482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) ===== | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, | ||
|
|
@@ -816,6 +819,25 @@ list.optOutOfLeaderboards = new SimpleModal({ | |
| }, | ||
| }); | ||
|
|
||
| list.toggleResultSaving = new SimpleModal({ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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"; | ||
|
|
@@ -147,11 +149,24 @@ function updateAccountSections(): void { | |
| } | ||
| } | ||
|
|
||
| function updateResultSavingToggle(): void { | ||
| const toggle = pageElement.qs( | ||
| "#toggleResultSaving", | ||
| ) as HTMLInputElement | null; | ||
| if (!toggle) return; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using this: |
||
|
|
||
| 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(); | ||
|
|
@@ -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"); | ||
|
|
||
There was a problem hiding this comment.
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: