Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/user-preferences-addition.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperdx/app': patch
---

feat: small addition to user preferences
4 changes: 4 additions & 0 deletions packages/app/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';

import { usePageTitle } from '@/brand';
import { CrtOverlay } from '@/components/CrtOverlay';
import { MANTINE_FONT_MAP } from '@/config/fonts';
import { ibmPlexMono, inter, roboto, robotoMono } from '@/fonts';
import { fetchServerVersion, installHdxDebug } from '@/hdxDebug';
Expand All @@ -22,6 +23,7 @@ import {
SystemColorSchemeScript,
useContentFontSize,
useResolvedColorScheme,
useUserPreferences,
} from '@/useUserPreferences';

import '@mantine/core/styles.css';
Expand Down Expand Up @@ -79,6 +81,7 @@ function AppContent({
pageProps: AppProps['pageProps'];
}) {
const resolvedColorScheme = useResolvedColorScheme();
const { userPreferences } = useUserPreferences();
const { base: contentFontSize, compact: compactContentFontSize } =
useContentFontSize();

Expand Down Expand Up @@ -107,6 +110,7 @@ function AppContent({
<ConfirmProvider>
{getLayout(<Component {...pageProps} />)}
</ConfirmProvider>
{userPreferences.crtMode && <CrtOverlay />}
</ThemeWrapper>
);
}
Expand Down
48 changes: 47 additions & 1 deletion packages/app/src/UserPreferencesModal.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import * as React from 'react';
import { Badge } from '@clickhouse/click-ui';
import { Divider, Group, Modal, Select, Stack, Text } from '@mantine/core';
import {
Divider,
Group,
Modal,
Select,
Stack,
Switch,
Text,
} from '@mantine/core';

import { CrtUnlockReveal } from './components/CrtUnlockReveal';
import { TimeZoneSelect, TimeZoneShortcuts } from './components/TimeZoneSelect';
import { isContentFontSize, OPTIONS_CONTENT_FONT_SIZE } from './config/fonts';
import { useKonamiCode } from './hooks/useKonamiCode';
import {
DEFAULT_ROW_CLICK_ACTION,
RowClickAction,
Expand Down Expand Up @@ -56,6 +66,36 @@ export const UserPreferencesModal = ({
}) => {
const { userPreferences, setUserPreference } = useUserPreferences();
const { contentFontSize } = useContentFontSize();
const [crtUnlocked, setCrtUnlocked] = React.useState(false);
// AppNav keeps this component mounted while closed, so gate on `opened`.
useKonamiCode(
React.useCallback(() => opened && setCrtUnlocked(true), [opened]),
);
// Stays true once CRT mode has been on while the modal is open, so turning
// the switch off does not remove it mid-click.
const [crtVisible, setCrtVisible] = React.useState(false);
React.useEffect(() => {
if (!opened) {
setCrtUnlocked(false);
setCrtVisible(false);
} else if (userPreferences.crtMode) {
setCrtVisible(true);
}
}, [opened, userPreferences.crtMode]);

const crtSetting = (
<SettingContainer
label="CRT mode"
description="Make the screen look like an old CRT monitor"
>
<Switch

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 P2 — The CRT mode switch has no accessible name

SettingContainer renders "CRT mode" as plain text in a sibling div that is not linked to the Switch, so a screen reader announces only "switch, off". Give the switch a name: pass aria-label="CRT mode", or use the Switch's own label prop.

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

data-testid="crt-mode-switch"
aria-label="CRT mode"
checked={!!userPreferences.crtMode}
onChange={e => setUserPreference({ crtMode: e.currentTarget.checked })}
/>
</SettingContainer>
);

return (
<Modal
Expand Down Expand Up @@ -169,6 +209,12 @@ export const UserPreferencesModal = ({
allowDeselect={false}
/>
</SettingContainer>

{crtUnlocked ? (
<CrtUnlockReveal>{crtSetting}</CrtUnlockReveal>
) : (
crtVisible && crtSetting
)}
</Stack>
</Modal>
);
Expand Down
55 changes: 55 additions & 0 deletions packages/app/src/__tests__/UserPreferencesModal.test.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as React from 'react';
import { Provider } from 'jotai';
import { screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
Expand Down Expand Up @@ -99,4 +100,58 @@ describe('UserPreferencesModal', () => {
expect(readStoredPreferences().rowClickAction).toBe('expand');
});
});

describe('CRT mode', () => {
const KONAMI =
'{ArrowUp}{ArrowUp}{ArrowDown}{ArrowDown}{ArrowLeft}{ArrowRight}{ArrowLeft}{ArrowRight}ba';

it('hides the toggle until the Konami code is typed', async () => {
renderModal();
expect(screen.queryByTestId('crt-mode-switch')).toBeNull();

await userEvent.keyboard(KONAMI);
expect(screen.getByTestId('crt-unlock-scene')).toBeInTheDocument();
await userEvent.click(screen.getByTestId('crt-mode-switch'));

expect(readStoredPreferences().crtMode).toBe(true);
});

it('ignores the Konami code while the modal is closed', async () => {
window.localStorage.clear();
const ClosedThenOpened = () => {
const [opened, setOpened] = React.useState(false);
return (
<>
<button onClick={() => setOpened(true)}>open</button>
<UserPreferencesModal opened={opened} onClose={() => {}} />
</>
);
};
renderWithMantine(
<Provider>
<ClosedThenOpened />
</Provider>,
);
await userEvent.keyboard(KONAMI);
await userEvent.click(screen.getByText('open'));
await screen.findByTestId('time-zone-select');

expect(screen.queryByTestId('crt-mode-switch')).toBeNull();
});

it('shows the toggle while CRT mode is on so it can be turned off', () => {
renderModal({ crtMode: true });

expect(screen.getByTestId('crt-mode-switch')).toBeChecked();
});

it('keeps the toggle after CRT mode is turned off', async () => {
renderModal({ crtMode: true });

await userEvent.click(screen.getByRole('switch', { name: 'CRT mode' }));

expect(readStoredPreferences().crtMode).toBe(false);
expect(screen.getByTestId('crt-mode-switch')).not.toBeChecked();
});
});
});
99 changes: 99 additions & 0 deletions packages/app/src/components/CrtOverlay.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Above modals and notifications; it never takes pointer events.
.overlay {
position: fixed;
inset: 0;
z-index: 2147483647;
pointer-events: none;

// Rounded screen corners plus edge shading read as a curved tube.
border-radius: 3vmin / 4vmin;
box-shadow:
0 0 0 10vmin #000,
inset 0 0 10vmin rgb(0 0 0 / 55%);
background: radial-gradient(
ellipse at center,
rgb(255 255 255 / 3%) 0%,
transparent 55%,
rgb(0 0 0 / 35%) 100%
);

&::before,
&::after {
content: '';
position: absolute;
inset: 0;
}

// The light half keeps the lines visible on the dark theme.
&::before {
background: repeating-linear-gradient(
to bottom,
rgb(0 0 0 / 30%) 0,
rgb(0 0 0 / 30%) 2px,
rgb(255 255 255 / 3%) 2px,
rgb(255 255 255 / 3%) 4px
);
}

// RGB phosphor mask; this layer also carries the flicker.
&::after {
background: repeating-linear-gradient(
to right,
rgb(255 0 0 / 5%) 0,
rgb(255 0 0 / 5%) 1px,
rgb(0 255 0 / 4%) 1px,
rgb(0 255 0 / 4%) 2px,
rgb(0 0 255 / 5%) 2px,
rgb(0 0 255 / 5%) 3px
);
will-change: opacity;
animation: flicker 0.15s steps(1) infinite;

@media (prefers-reduced-motion: reduce) {
animation: none;
}
}
}

.roll {
position: absolute;
inset: 0 0 auto;
height: 15vh;
background: linear-gradient(
to bottom,
transparent,
rgb(255 255 255 / 7%),
transparent
);
transform: translateY(-15vh);
will-change: transform;
animation: roll 8s linear infinite;

@media (prefers-reduced-motion: reduce) {
display: none;
}
}

@keyframes roll {
to {
transform: translateY(100vh);
}
}

@keyframes flicker {
0% {
opacity: 0.7;
}

50% {
opacity: 1;
}
}

// Chromatic aberration and phosphor glow on all text. `.root` goes on <html>.
.root body {
text-shadow:
0.6px 0 rgb(255 0 80 / 35%),
-0.6px 0 rgb(0 200 255 / 35%),
0 0 2px color-mix(in srgb, currentcolor 60%, transparent);
}
18 changes: 18 additions & 0 deletions packages/app/src/components/CrtOverlay.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { useEffect } from 'react';

import styles from './CrtOverlay.module.scss';

/** Full-viewport CRT effect. Mount only while the preference is on. */
export function CrtOverlay() {
useEffect(() => {
// A module class, not a global selector: the production build rejects those.
document.documentElement.classList.add(styles.root);
return () => document.documentElement.classList.remove(styles.root);
}, []);

return (
<div className={styles.overlay} aria-hidden data-testid="crt-overlay">
<div className={styles.roll} />
</div>
);
}
Loading
Loading