refactor(site): extract shared utilities and centralise dialogue IDs
- new src/hooks/ui/useIsMobile.ts (matchMedia + useSyncExternalStore) replacing the resize-handler hook inlined inside pages/site/page.tsx - new src/hooks/ui/usePrefersReducedMotion.ts - new src/data/site/dialogueIds.ts so site and intro components stop carrying hard-coded narrator IDs - siteConfig: add SITE_BACKGROUND_STYLE shared by SiteLayout and SiteMobileBlocker, rename forcedName to presetPlayerName, fix the swapped id/label pairing on situation cards - useSiteStore: rename selectedExperience/Situation to *Index so the stored value (an array index) is obvious in callers - audioConfig: drop dead AUDIO_PATHS placeholders - propagate the renames and SITE_BACKGROUND_STYLE through SiteLayout, SiteWelcomeScreen, SiteSituationScreen and pages/site/page.tsx
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import type { ReactNode } from "react";
|
||||
import { SITE_CONFIG } from "@/data/site/siteConfig";
|
||||
import { SITE_BACKGROUND_STYLE } from "@/data/site/siteConfig";
|
||||
import { Subtitles } from "@/components/ui/Subtitles";
|
||||
|
||||
interface SiteLayoutProps {
|
||||
@@ -16,11 +16,7 @@ export function SiteLayout({ children }: SiteLayoutProps): React.JSX.Element {
|
||||
flexDirection: "column",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
backgroundColor: "#87CEEB",
|
||||
backgroundImage: `url(${SITE_CONFIG.backgroundImage})`,
|
||||
backgroundSize: "cover",
|
||||
backgroundPosition: "center",
|
||||
backgroundRepeat: "no-repeat",
|
||||
...SITE_BACKGROUND_STYLE,
|
||||
fontFamily: "system-ui, -apple-system, sans-serif",
|
||||
color: "#fff",
|
||||
overflow: "hidden",
|
||||
|
||||
@@ -7,13 +7,15 @@ import { SITUATION_CARDS } from "@/data/site/siteConfig";
|
||||
* Screen 2: Situation selection
|
||||
*/
|
||||
export function SiteSituationScreen(): React.JSX.Element {
|
||||
const selectedSituation = useSiteStore((state) => state.selectedSituation);
|
||||
const setSelectedSituation = useSiteStore(
|
||||
(state) => state.setSelectedSituation,
|
||||
const selectedSituationIndex = useSiteStore(
|
||||
(state) => state.selectedSituationIndex,
|
||||
);
|
||||
const setSelectedSituationIndex = useSiteStore(
|
||||
(state) => state.setSelectedSituationIndex,
|
||||
);
|
||||
const setStep = useSiteStore((state) => state.setStep);
|
||||
|
||||
const canProceed = selectedSituation !== null;
|
||||
const canProceed = selectedSituationIndex !== null;
|
||||
|
||||
const handleConfirm = (): void => {
|
||||
if (canProceed) {
|
||||
@@ -63,11 +65,11 @@ export function SiteSituationScreen(): React.JSX.Element {
|
||||
<SiteCard
|
||||
key={card.id}
|
||||
config={card}
|
||||
selected={selectedSituation === index}
|
||||
selected={selectedSituationIndex === index}
|
||||
variant="situation"
|
||||
onSelect={() => {
|
||||
if (!card.disabled) {
|
||||
setSelectedSituation(index);
|
||||
setSelectedSituationIndex(index);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
|
||||
@@ -7,13 +7,15 @@ import { EXPERIENCE_CARDS } from "@/data/site/siteConfig";
|
||||
* Screen 1: Welcome
|
||||
*/
|
||||
export function SiteWelcomeScreen(): React.JSX.Element {
|
||||
const selectedExperience = useSiteStore((state) => state.selectedExperience);
|
||||
const setSelectedExperience = useSiteStore(
|
||||
(state) => state.setSelectedExperience,
|
||||
const selectedExperienceIndex = useSiteStore(
|
||||
(state) => state.selectedExperienceIndex,
|
||||
);
|
||||
const setSelectedExperienceIndex = useSiteStore(
|
||||
(state) => state.setSelectedExperienceIndex,
|
||||
);
|
||||
const setStep = useSiteStore((state) => state.setStep);
|
||||
|
||||
const canProceed = selectedExperience !== null;
|
||||
const canProceed = selectedExperienceIndex !== null;
|
||||
|
||||
const handleNext = (): void => {
|
||||
if (canProceed) {
|
||||
@@ -104,10 +106,10 @@ export function SiteWelcomeScreen(): React.JSX.Element {
|
||||
<SiteCard
|
||||
key={card.id}
|
||||
config={card}
|
||||
selected={selectedExperience === index}
|
||||
selected={selectedExperienceIndex === index}
|
||||
onSelect={() => {
|
||||
if (!card.disabled) {
|
||||
setSelectedExperience(index);
|
||||
setSelectedExperienceIndex(index);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user