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
4 changes: 2 additions & 2 deletions apps/www/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,6 @@ Everything above describes the tech mode. Pages under `/hobby` (films, series, a
- **The sentence is the navigation.** The page opens with one sentence whose nouns (films, series, anime, games) are links that narrow the list to that kind, and widen it again when current.
- **A work opens as a sheet.** Choosing a line opens the work over the list in a sheet that covers the screen but for a margin. Its key art fills the whole sheet and stays put while the content scrolls; over it lies the page colour as a wash that is thin at the top and never opaque, thickened only on the side the text stands on, so the art reads through all of it. On that sit the cover, the title at display size, a short comment, then the facts as labelled values (status, a rating out of ten drawn as five stars, dates; for a game, hours played, achievements with a thin meter, last played). A work with a cover but no key art uses the cover, blurred, for its colours. The sheet has its own URL; opened directly, the same content is a page whose art fills the viewport behind the wordmark. The cover is capped by the height of its surface, so the work reads without scrolling in a short window.
- **The cover is a lit card.** It tilts towards the pointer under studio light: a band of light sweeps across as it turns, a glare follows the pointer and the bevelled edge catches both. It sweeps once when the sheet opens, draws only while something moves, and holds still under reduced motion.
- **Chrome stays out of the way.** The wordmark is plain text at the top, beside the portrait that switches mode; the chat launcher and command menu float in the bottom-left corner; theme, language and settings close the page as one row.
- **Where the shader cannot run** (no WebGPU), the key art itself stands in behind the page at low opacity, and the colour still follows the work. With reduced motion the field holds still.
- **Chrome stays out of the way.** The wordmark is plain text at the top, beside the portrait that switches mode; the command menu floats in the bottom-left corner; theme, language and settings close the page as one row.
- **Where the shader cannot run** (no WebGPU), the key art itself stands in behind the page at low opacity, and the colour still follows the work. With reduced motion the field holds still, and so do the field and the card when the reader reduces effects in settings, which is the default on touch devices.
- **Reader palette does not apply.** The palette settings recolour the tech mode only.
47 changes: 47 additions & 0 deletions apps/www/__tests__/hooks/use-reduced-effects.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { renderHook } from "@testing-library/react";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";

import { useReducedEffects } from "@/hooks/use-reduced-effects";
import { useSettingsStore } from "@/stores/settings/store";

const stubHover = (canHover: boolean) => {
vi.stubGlobal("matchMedia", (query: string) => ({
matches: canHover,
media: query,
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
}));
};

describe("useReducedEffects", () => {
beforeEach(() => {
useSettingsStore.setState({ reducedEffects: null });
});

afterEach(() => {
vi.unstubAllGlobals();
});

it("is off by default where the pointer hovers", () => {
stubHover(true);
expect(renderHook(() => useReducedEffects()).result.current).toBe(false);
});

it("is on by default on a touch device", () => {
stubHover(false);
expect(renderHook(() => useReducedEffects()).result.current).toBe(true);
});

it.each([
[true, true],
[false, false],
])("the reader's choice of %s wins on either device", (choice, expected) => {
useSettingsStore.getState().setReducedEffects(choice);
for (const canHover of [true, false]) {
stubHover(canHover);
expect(renderHook(() => useReducedEffects()).result.current).toBe(
expected
);
}
});
});
10 changes: 8 additions & 2 deletions apps/www/src/components/agent/chat-dock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { DockActions, DockMode, DockShell } from "@chia/ui/dock";
import { cn } from "@chia/ui/utils/cn.util";

import { CHBot } from "@/components/commons/ch-bot";
import { usePathname } from "@/libs/i18n/navigation";
import { SiteMode, siteModeOf } from "@/shared/site-mode";
import { useChatDockStore } from "@/stores/chat-dock/store";
import { useSettingsStore } from "@/stores/settings/store";

Expand All @@ -37,6 +39,10 @@ const DEFAULT_WIDTH = 384;
export const ChatDock = () => {
const t = useTranslations("chbot");
const aiEnabled = useSettingsStore((state) => state.aiEnabled);
const pathname = usePathname();
// The agent is not offered in the hobby mode: no launcher there, and a dock left open in the
// tech mode steps aside until the reader is back.
const isOffered = aiEnabled && siteModeOf(pathname) !== SiteMode.Hobby;
const mode = useChatDockStore((state) => state.mode);
const setMode = useChatDockStore((state) => state.setMode);
const toggle = useChatDockStore((state) => state.toggle);
Expand All @@ -48,9 +54,9 @@ export const ChatDock = () => {
void useChatDockStore.persist.rehydrate();
}, []);

useHotkey("Mod+I", toggle, { enabled: aiEnabled });
useHotkey("Mod+I", toggle, { enabled: isOffered });

if (!aiEnabled) {
if (!isOffered) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion apps/www/src/components/commons/footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const Footer: FC<{ locale?: Locale }> = ({ locale: _locale }) => {
}}
/>
<LocaleSelector />
<Settings />
<Settings mode={SiteMode.Tech} />
</div>
</FooterCell>
</div>
Expand Down
94 changes: 69 additions & 25 deletions apps/www/src/components/commons/settings.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,90 @@
"use client";

import { startTransition } from "react";
import type { ReactNode } from "react";

import { Button, Description, Label, Modal, Switch } from "@heroui/react";
import { useTranslations } from "next-intl";

import { PaletteSettings } from "@/components/commons/palette-settings";
import { useReducedEffects } from "@/hooks/use-reduced-effects";
import { SiteMode } from "@/shared/site-mode";
import { useSettingsStore } from "@/stores/settings/store";

/** `palette` is off in a mode that brings its own colours, where the reader palette does not apply. */
export const Settings = ({ palette = true }: { palette?: boolean }) => {
const Toggle = ({
label,
description,
isSelected,
onChange,
}: {
label: string;
description: ReactNode;
isSelected: boolean;
onChange: (isSelected: boolean) => void;
}) => (
<Switch
size="sm"
isSelected={isSelected}
onChange={(next) => startTransition(() => onChange(next))}
aria-label={label}>
<Switch.Content>
<Switch.Control>
<Switch.Thumb />
</Switch.Control>
<div className="-mt-0.5 flex flex-col gap-1">
<Label className="text-sm">{label}</Label>
<Description>{description}</Description>
</div>
</Switch.Content>
</Switch>
);

const TechSettings = () => {
const t = useTranslations("settings");
const aiEnabled = useSettingsStore((s) => s.aiEnabled);
const setAiEnabled = useSettingsStore((s) => s.setAiEnabled);
return (
<>
<Toggle
label={t("aiEnabled")}
description={t("aiEnabledDescription")}
isSelected={aiEnabled}
onChange={setAiEnabled}
/>
<div className="border-separator border-t pt-4">
<PaletteSettings />
</div>
</>
);
};

const HobbySettings = () => {
const t = useTranslations("settings");
const reducedEffects = useReducedEffects();
const setReducedEffects = useSettingsStore((s) => s.setReducedEffects);
return (
<Toggle
label={t("reducedEffects")}
description={t("reducedEffectsDescription")}
isSelected={reducedEffects}
onChange={setReducedEffects}
/>
);
};

/**
* Each mode lists what applies to it: the agent and the reader palette exist only in the tech
* mode, the effects only in the hobby mode.
*/
export const Settings = ({ mode }: { mode: SiteMode }) => {
const t = useTranslations("settings");

return (
<Modal>
<Button size="sm" variant="tertiary" aria-label={t("open")} isIconOnly>
<span className="i-mdi-cog-outline size-4" aria-hidden />
</Button>
{/* The page stays visible so a colour change can be judged against it. */}
{/* The page stays visible so a change can be judged against it. */}
<Modal.Backdrop variant="transparent">
<Modal.Container placement="center">
<Modal.Dialog className="sm:max-w-[400px]">
Expand All @@ -28,28 +93,7 @@ export const Settings = ({ palette = true }: { palette?: boolean }) => {
<Modal.Heading>{t("title")}</Modal.Heading>
</Modal.Header>
<Modal.Body className="flex flex-col gap-4">
<Switch
size="sm"
isSelected={aiEnabled}
onChange={(isSelected) =>
startTransition(() => setAiEnabled(isSelected))
}
aria-label={t("aiEnabled")}>
<Switch.Content>
<Switch.Control>
<Switch.Thumb />
</Switch.Control>
<div className="-mt-0.5 flex flex-col gap-1">
<Label className="text-sm">{t("aiEnabled")}</Label>
<Description>{t("aiEnabledDescription")}</Description>
</div>
</Switch.Content>
</Switch>
{palette ? (
<div className="border-separator border-t pt-4">
<PaletteSettings />
</div>
) : null}
{mode === SiteMode.Tech ? <TechSettings /> : <HobbySettings />}
</Modal.Body>
</Modal.Dialog>
</Modal.Container>
Expand Down
3 changes: 2 additions & 1 deletion apps/www/src/components/hobby/hobby-footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Copyright } from "@/components/commons/copyright";
import { LoadingSkeleton } from "@/components/commons/current-playing";
import LocaleSelector from "@/components/commons/locale-selector";
import { Settings } from "@/components/commons/settings";
import { SiteMode } from "@/shared/site-mode";

const CurrentPlaying = dynamic(
() =>
Expand Down Expand Up @@ -56,7 +57,7 @@ export const HobbyFooter = () => {
}}
/>
<LocaleSelector />
<Settings palette={false} />
<Settings mode={SiteMode.Hobby} />
</div>
</footer>
);
Expand Down
4 changes: 1 addition & 3 deletions apps/www/src/components/hobby/hobby-frame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { ReactNode } from "react";

import type { Locale } from "next-intl";

import { ChatLauncher } from "@/components/agent/chat-launcher";
import { CommandMenu } from "@/components/commons/command-menu";
import { ModeSwitch } from "@/components/commons/mode-switch";
import { HobbyFooter } from "@/components/hobby/hobby-footer";
Expand Down Expand Up @@ -42,8 +41,7 @@ const HobbyFrame = ({
{/* What a header would hold, kept out of the way. No backdrop blur: the field redraws under it. */}
<div
data-testid="nav-menu"
className="bg-background/85 fixed bottom-4 left-(--hobby-gutter) z-50 flex items-center gap-1 rounded-full p-1">
<ChatLauncher />
className="bg-background/85 fixed bottom-4 left-(--hobby-gutter) z-50 flex items-center gap-1 rounded-xl p-1">
<CommandMenu locale={locale} mode={SiteMode.Hobby} />
</div>
</div>
Expand Down
6 changes: 5 additions & 1 deletion apps/www/src/components/hobby/hobby-stage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { AsciiField, AsciiFieldStatus } from "@chia/shaders/ascii-field";
import { cn } from "@chia/ui/utils/cn.util";
import useTheme, { Theme } from "@chia/ui/utils/use-theme";

import { useReducedEffects } from "@/hooks/use-reduced-effects";
import { readableImageSourceOf } from "@/libs/image-source";
import { HOBBY_IDLE_COLOR } from "@/shared/media";
import { useHobbyStore } from "@/stores/hobby/store";
Expand Down Expand Up @@ -94,11 +95,13 @@ export const HobbyStage = () => {
const focus = useSettledFocus();
const pinned = useHobbyStore((state) => state.pinned);
const color = (pinned ?? focus)?.color ?? null;
const backdrop = useBackdrop(pinned ? null : (focus?.backdropUrl ?? null));
// Kept while a work is open: dropping it would revoke a blob the shader may still be decoding.
const backdrop = useBackdrop(focus?.backdropUrl ?? null);
const [status, setStatus] = useState<AsciiFieldStatus>(
AsciiFieldStatus.Pending
);
const isDark = resolvedTheme === Theme.Dark;
const reducedEffects = useReducedEffects();

useEffect(() => {
const { style } = document.documentElement;
Expand Down Expand Up @@ -131,6 +134,7 @@ export const HobbyStage = () => {
color={toneOf(color ?? HOBBY_IDLE_COLOR, isDark)}
cellSize={10}
paused={pinned !== null}
reducedMotion={reducedEffects}
onStatusChange={setStatus}
className={cn(
"absolute inset-0 transition-opacity duration-700",
Expand Down
33 changes: 33 additions & 0 deletions apps/www/src/components/hobby/media-cover.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"use client";

import Image from "next/image";

import { ReflectiveCard } from "@chia/shaders/reflective-card";

import { useReducedEffects } from "@/hooks/use-reduced-effects";

/** A work's cover under studio light, which holds still when the reader's effects are reduced. */
export const MediaCover = ({
src,
className,
}: {
src: string;
className?: string;
}) => {
const reducedEffects = useReducedEffects();
return (
<ReflectiveCard
radius={6}
reducedMotion={reducedEffects}
className={className}>
<Image
src={src}
alt=""
fill
sizes="(min-width: 768px) 224px, 144px"
referrerPolicy="no-referrer"
className="object-cover"
/>
</ReflectiveCard>
);
};
18 changes: 5 additions & 13 deletions apps/www/src/components/hobby/media-detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import type { ReactNode } from "react";
import { getFormatter, getLocale, getTranslations } from "next-intl/server";

import { MediaKind } from "@chia/db/types";
import { ReflectiveCard } from "@chia/shaders/reflective-card";
import { cn } from "@chia/ui/utils/cn.util";

import { MediaCover } from "@/components/hobby/media-cover";
import { MediaPin } from "@/components/hobby/media-pin";
import { StarRating } from "@/components/hobby/star-rating";
import { dbLocaleResolver } from "@/libs/utils/i18n";
Expand Down Expand Up @@ -127,19 +127,11 @@ export const MediaDetail = async ({
: "pt-6 pb-10"
)}>
{entry.posterUrl ? (
<ReflectiveCard
radius={12}
<MediaCover
src={entry.posterUrl}
// Capped by the surface's height, so a short window still shows the whole cover.
className="aspect-2/3 h-[min(13.5rem,40cqh)] shadow-lg md:h-[min(21rem,42cqh)]">
<Image
src={entry.posterUrl}
alt=""
fill
sizes="(min-width: 768px) 224px, 144px"
referrerPolicy="no-referrer"
className="object-cover"
/>
</ReflectiveCard>
className="aspect-2/3 h-[min(13.5rem,40cqh)] shadow-lg md:h-[min(21rem,42cqh)]"
/>
) : null}
<div className="flex min-w-0 flex-col gap-8 [text-shadow:0_1px_16px_var(--background)]">
<header className="flex flex-col gap-2">
Expand Down
17 changes: 3 additions & 14 deletions apps/www/src/components/hobby/media-list.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
"use client";

import { useEffect, useRef, useSyncExternalStore } from "react";
import { useEffect, useRef } from "react";

import { useCanHover } from "@/hooks/use-can-hover";
import { Link } from "@/libs/i18n/navigation";
import type { MediaRow } from "@/shared/media";
import { useHobbyStore } from "@/stores/hobby/store";

const HOVER_QUERY = "(hover: hover)";

const subscribeHover = (onChange: () => void) => {
const query = window.matchMedia(HOVER_QUERY);
query.addEventListener("change", onChange);
return () => query.removeEventListener("change", onChange);
};

/** A row is in focus on a touch screen while it crosses this band in the middle of the viewport. */
const CENTRE_BAND = "-45% 0px -45% 0px";

Expand All @@ -27,11 +20,7 @@ const ROW_CLASS_NAME =
export const MediaList = ({ rows }: { rows: readonly MediaRow[] }) => {
const focusId = useHobbyStore((state) => state.focus?.id ?? null);
const setFocus = useHobbyStore((state) => state.setFocus);
const canHover = useSyncExternalStore(
subscribeHover,
() => window.matchMedia(HOVER_QUERY).matches,
() => true
);
const canHover = useCanHover();
const list = useRef<HTMLUListElement>(null);

useEffect(() => {
Expand Down
Loading
Loading