-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
refactor: solid dev options modal (@miodec) #7561
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
+212
−203
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4af3ed8
convert dev options to solid
Miodec 9708931
style
Miodec e53ece8
use for
Miodec 7269692
refactor: solid dev options modal (@miodec) (#7562)
Copilot 2e74506
fix: resolve lint errors in dev options modal refactor (@copilot) (#7…
Copilot 9f4dce3
error message
Miodec acc4985
extract
Miodec d391a9d
suspense
Miodec File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| import { createSignal, For, JSXElement } from "solid-js"; | ||
| import { envConfig } from "virtual:env-config"; | ||
|
|
||
| import { signIn } from "../../auth"; | ||
| import * as Notifications from "../../elements/notifications"; | ||
| import { update } from "../../elements/xp-bar"; | ||
| import { getInputElement } from "../../input/input-element"; | ||
| import { showPopup } from "../../modals/simple-modals"; | ||
| import { showLoaderBar, hideLoaderBar } from "../../signals/loader-bar"; | ||
| import { hideModal } from "../../stores/modals"; | ||
| import { toggleUserFakeChartData } from "../../test/result"; | ||
| import { disableSlowTimerFail } from "../../test/test-timer"; | ||
| import { FaSolidIcon } from "../../types/font-awesome"; | ||
| import { setMediaQueryDebugLevel } from "../../ui"; | ||
| import { toggleCaretDebug } from "../../utils/caret"; | ||
| import { createErrorMessage } from "../../utils/misc"; | ||
| import { AnimatedModal } from "../common/AnimatedModal"; | ||
| import { Button } from "../common/Button"; | ||
|
|
||
| const [mediaQueryDebugLevel, setLocalMediaQueryDebugLevel] = createSignal(0); | ||
|
|
||
| type DevButton = { | ||
| icon: FaSolidIcon; | ||
| label: () => string; | ||
| onClick: () => void; | ||
| }; | ||
|
|
||
| export function DevOptionsModal(): JSXElement { | ||
| const buttons: DevButton[] = [ | ||
| { | ||
| icon: "fa-database", | ||
| label: () => "Generate Data", | ||
| onClick: () => showPopup("devGenerateData"), | ||
| }, | ||
| { | ||
| icon: "fa-bell", | ||
| label: () => "Test Notifications", | ||
| onClick: () => { | ||
| Notifications.add("This is a test", 1, { duration: 0 }); | ||
| Notifications.add("This is a test", 0, { duration: 0 }); | ||
| Notifications.add("This is a test", -1, { | ||
| duration: 0, | ||
| details: { test: true, error: "Example error message" }, | ||
| }); | ||
| hideModal("DevOptions"); | ||
| }, | ||
| }, | ||
| { | ||
| icon: "fa-ruler", | ||
| label: () => `Media Query Debug (${mediaQueryDebugLevel()})`, | ||
| onClick: () => { | ||
| const next = | ||
| mediaQueryDebugLevel() >= 2 ? 0 : mediaQueryDebugLevel() + 1; | ||
| setLocalMediaQueryDebugLevel(next); | ||
| Notifications.add(`Setting media query debug level to ${next}`, 5); | ||
| setMediaQueryDebugLevel(next); | ||
| }, | ||
| }, | ||
| { | ||
| icon: "fa-eye", | ||
| label: () => "Show Real Words Input", | ||
| onClick: () => { | ||
| const el = getInputElement(); | ||
| el.style.opacity = "1"; | ||
| el.style.marginTop = "1.5em"; | ||
| el.style.caretColor = "red"; | ||
| hideModal("DevOptions"); | ||
| }, | ||
| }, | ||
| { | ||
| icon: "fa-sign-in-alt", | ||
| label: () => "Quick Login", | ||
| onClick: () => { | ||
| if ( | ||
| envConfig.quickLoginEmail === undefined || | ||
| envConfig.quickLoginPassword === undefined | ||
| ) { | ||
| Notifications.add( | ||
| "Quick login credentials not set. Add QUICK_LOGIN_EMAIL and QUICK_LOGIN_PASSWORD to your frontend .env file.", | ||
| -1, | ||
| ); | ||
| return; | ||
| } | ||
| showLoaderBar(); | ||
| void signIn( | ||
| envConfig.quickLoginEmail, | ||
| envConfig.quickLoginPassword, | ||
| true, | ||
| ) | ||
| .then((result) => { | ||
| if (!result.success) { | ||
| Notifications.add(result.message, -1); | ||
| } | ||
| }) | ||
| .catch((error: unknown) => { | ||
| Notifications.add( | ||
| createErrorMessage(error, "Quick login failed"), | ||
| -1, | ||
| ); | ||
| }) | ||
| .finally(() => { | ||
| hideLoaderBar(); | ||
| }); | ||
| hideModal("DevOptions"); | ||
| }, | ||
| }, | ||
| { | ||
| icon: "fa-star", | ||
| label: () => "XP Bar Test", | ||
| onClick: () => { | ||
| setTimeout(() => { | ||
| void update(1000000, 20800, { | ||
| base: 100, | ||
| fullAccuracy: 200, | ||
| accPenalty: 300, | ||
| quote: 400, | ||
| punctuation: 500, | ||
| streak: 10_000, | ||
| configMultiplier: 2, | ||
| }); | ||
| }, 500); | ||
| hideModal("DevOptions"); | ||
| }, | ||
| }, | ||
| { | ||
| icon: "fa-chart-bar", | ||
| label: () => "Toggle Fake Chart Data", | ||
| onClick: toggleUserFakeChartData, | ||
| }, | ||
| { | ||
| icon: "fa-i-cursor", | ||
| label: () => "Toggle Caret Debug", | ||
| onClick: toggleCaretDebug, | ||
| }, | ||
| { | ||
| icon: "fa-clock", | ||
| label: () => "Disable Slow Timer Fail", | ||
| onClick: disableSlowTimerFail, | ||
| }, | ||
| ]; | ||
|
|
||
| return ( | ||
| <AnimatedModal id="DevOptions" title="Dev Options"> | ||
| <div class="flex flex-col gap-4"> | ||
| <For each={buttons}> | ||
| {(btn) => ( | ||
| <Button | ||
| type="button" | ||
| onClick={btn.onClick} | ||
| fa={{ icon: btn.icon, fixedWidth: true }} | ||
| text={btn.label()} | ||
| /> | ||
| )} | ||
| </For> | ||
| </div> | ||
| </AnimatedModal> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,25 @@ | ||
| import { JSXElement } from "solid-js"; | ||
| import { JSXElement, Show, Suspense, lazy } from "solid-js"; | ||
|
|
||
| import { isDevEnvironment } from "../../utils/misc"; | ||
| import { ContactModal } from "./ContactModal"; | ||
| import { SupportModal } from "./SupportModal"; | ||
| import { VersionHistoryModal } from "./VersionHistoryModal"; | ||
|
|
||
| const DevOptionsModal = lazy(async () => | ||
| import("./DevOptionsModal").then((m) => ({ default: m.DevOptionsModal })), | ||
| ); | ||
|
|
||
| export function Modals(): JSXElement { | ||
| return ( | ||
| <> | ||
| <VersionHistoryModal /> | ||
| <ContactModal /> | ||
| <SupportModal /> | ||
| <Show when={isDevEnvironment()}> | ||
| <Suspense fallback={null}> | ||
| <DevOptionsModal /> | ||
| </Suspense> | ||
| </Show> | ||
| </> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
DevOptionsModalis now always imported + rendered inModals, which ships dev-only actions (quick login, test toggles) in production bundles and makes them theoretically triggerable (e.g. via any future call toshowModal("DevOptions")). Gate rendering behindisDevEnvironment()and preferably lazy-load the modal component (dynamic import) to keep dev-only code out of prod bundles.