Files
FitOS/web/src/sections/Ecosystem.tsx

482 lines
17 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { useCallback, useEffect, useRef, useState } from 'react';
import { Building2, Dumbbell, Shield, UserRound, type LucideIcon } from 'lucide-react';
import { Brandmark } from '../components/Brandmark';
import { Reveal } from '../components/Reveal';
import { cn } from '../lib/utils';
import { Section, SectionHeading } from './shared';
interface Participant {
icon: LucideIcon;
role: string;
brings: string;
gets: string;
link: string;
}
// Cztery strony rdzenia — FitOS nie ma „użytkowników końcowych”,
// każdy uczestnik jednocześnie wnosi wartość i ją pobiera.
export const PARTICIPANTS: Participant[] = [
{
icon: Dumbbell,
role: 'Ćwiczący',
brings: 'zaufanie i realne wyniki treningów — dane, na których trzyma się cała reszta',
gets: 'sprzęt, plan, trener i społeczność w jednym miejscu',
link: 'trenuje w siłowni, której sprzęt limituje jego plan',
},
{
icon: UserRound,
role: 'Trener',
brings: 'wiedzę: plany, progresje i opiekę nad podopiecznymi',
gets: 'dostęp do hal siłowni i podopiecznych, którzy realnie trenują',
link: 'układa plany pod sprzęt siłowni, w której trenuje jego podopieczny',
},
{
icon: Building2,
role: 'Siłownia',
brings: 'sprzęt, godziny, zasady i miejsce do trenowania',
gets: 'ludzi, którzy przychodzą po plan, i głos w swoim feedzie',
link: 'dostarcza sprzęt i ogłasza się ludziom, którzy jej potrzebują',
},
{
icon: Shield,
role: 'Administrator',
brings: 'stabilność: dbałość o jakość danych i bezpieczeństwo ekosystemu',
gets: 'ekosystem, który działa sam — bez domyślnego zaufania i śmieciowych danych',
link: 'nadaje oficjalny status siłowniom po weryfikacji ich autentyczności',
},
];
interface Wire {
x1: number;
y1: number;
x2: number;
y2: number;
spread: number;
id: string;
// v = ściana pionowa (podstawa trójkąta na bocznej krawędzi, rozrzut w y),
// h = ściana pozioma (podstawa na górnej/dolnej krawędzi, rozrzut w x)
axis: 'v' | 'h';
}
// promień wierzchołka na obwodzie rdzenia — dobrany do rozmiaru rdzenia
const HUB_RADIUS = 78;
const HUB_RADIUS_STACK = 70;
const SPREAD_PX = 52;
// impulsy promieniowania wypełniają cały stożek: wachlarz od wierzchołka
// do równomiernie rozmieszczonych punktów podstawy (frakcje ±1)
const STREAKS = [-1, -0.66, -0.33, 0, 0.33, 0.66, 1];
interface WireTarget {
el: HTMLElement | null;
id: string;
// ściana kafelka, do której biegnie promień (strona bliższa rdzenia)
side: 'left' | 'right' | 'top' | 'bottom';
}
function basePoint(r: DOMRect, cr: DOMRect, side: WireTarget['side']) {
switch (side) {
case 'left':
return { x: r.right - cr.left, y: r.top + r.height / 2 - cr.top };
case 'right':
return { x: r.left - cr.left, y: r.top + r.height / 2 - cr.top };
case 'top':
return { x: r.left + r.width / 2 - cr.left, y: r.bottom - cr.top };
case 'bottom':
return { x: r.left + r.width / 2 - cr.left, y: r.top - cr.top };
}
}
/**
* Promienie—trójkąty mierzone w DOM: wierzchołek na obwodzie rdzenia,
* podstawy na ścianach kafelków. Współrzędne w % kontenera (viewBox 0–100).
*/
function measureWires(
container: HTMLElement,
hubEl: HTMLElement,
targets: WireTarget[],
hubRadius: number,
) {
const cr = container.getBoundingClientRect();
if (!cr.width || !cr.height) return { wires: [] as Wire[], hub: { x: 50, y: 50 } };
const hr = hubEl.getBoundingClientRect();
const cx = hr.left + hr.width / 2 - cr.left;
const cy = hr.top + hr.height / 2 - cr.top;
const wires: Wire[] = [];
for (const t of targets) {
if (!t.el) continue;
const r = t.el.getBoundingClientRect();
const midX = r.left + r.width / 2 - cr.left;
const midY = r.top + r.height / 2 - cr.top;
const dx = midX - cx;
const dy = midY - cy;
const len = Math.hypot(dx, dy) || 1;
const base = basePoint(r, cr, t.side);
wires.push({
x1: ((cx + (dx / len) * hubRadius) / cr.width) * 100,
y1: ((cy + (dy / len) * hubRadius) / cr.height) * 100,
x2: (base.x / cr.width) * 100,
y2: (base.y / cr.height) * 100,
// połowa podstawy trójkąta jako % wymiaru kontenera w osi rozrzutu
spread: ((t.side === 'left' || t.side === 'right' ? SPREAD_PX / cr.height : SPREAD_PX / cr.width)) * 100,
id: t.id,
axis: t.side === 'left' || t.side === 'right' ? 'v' : 'h',
});
}
return { wires, hub: { x: (cx / cr.width) * 100, y: (cy / cr.height) * 100 } };
}
/** Warstwy SVG: gradienty promieni + maska miękkiego zanikania od rdzenia. */
function RayDefs({
wires,
idPrefix,
hub,
}: {
wires: Wire[];
idPrefix: string;
hub: { x: number; y: number };
}) {
return (
<>
<defs>
{wires.map((w) => (
<linearGradient
key={w.id}
id={`ray-${idPrefix}${w.id}`}
gradientUnits="userSpaceOnUse"
x1={w.x1}
y1={w.y1}
x2={w.x2}
y2={w.y2}
>
<stop offset="0" stopColor="var(--accent)" stopOpacity="0.55" />
<stop offset="1" stopColor="var(--accent)" stopOpacity="0.04" />
</linearGradient>
))}
<radialGradient
id={`ray-glow-${idPrefix}`}
gradientUnits="userSpaceOnUse"
cx={hub.x}
cy={hub.y}
r="50"
>
<stop offset="0" stopColor="#fff" stopOpacity="1" />
<stop offset="1" stopColor="#fff" stopOpacity="0" />
</radialGradient>
<mask id={`ray-soft-${idPrefix}`}>
<rect x="0" y="0" width="100" height="100" fill={`url(#ray-glow-${idPrefix})`} />
</mask>
</defs>
<g mask={`url(#ray-soft-${idPrefix})`}>
{wires.map((w) => (
<g key={w.id}>
<polygon
points={
w.axis === 'v'
? `${w.x1},${w.y1} ${w.x2},${w.y2 - w.spread} ${w.x2},${w.y2 + w.spread}`
: `${w.x1},${w.y1} ${w.x2 - w.spread},${w.y2} ${w.x2 + w.spread},${w.y2}`
}
fill={`url(#ray-${idPrefix}${w.id})`}
/>
{STREAKS.map((f, i) => (
<line
key={f}
className="ray-flow"
style={{ animationDelay: `${-i * 0.42}s` }}
x1={w.x1}
y1={w.y1}
x2={w.axis === 'v' ? w.x2 : w.x2 + w.spread * f}
y2={w.axis === 'v' ? w.y2 + w.spread * f : w.y2}
pathLength={100}
vectorEffect="non-scaling-stroke"
stroke="var(--accent)"
strokeOpacity="0.5"
strokeWidth="2"
strokeLinecap="round"
/>
))}
</g>
))}
</g>
</>
);
}
/**
* Diagram rdzenia (lg+): kafelki uczestników z naturalną wysokością (nic się nie
* ucina) i promienie—trójkąty mierzone w DOM (ResizeObserver): wierzchołek na
* obwodzie rdzenia, podstawa na ścianie kafelka.
*/
function HubDiagram() {
const containerRef = useRef<HTMLDivElement>(null);
const hubRef = useRef<HTMLDivElement>(null);
const trenerRef = useRef<HTMLDivElement>(null);
const silowniaRef = useRef<HTMLDivElement>(null);
const cwiczacyRef = useRef<HTMLDivElement>(null);
const adminRef = useRef<HTMLDivElement>(null);
const [wires, setWires] = useState<Wire[]>([]);
const [hub, setHub] = useState({ x: 50, y: 50 });
useEffect(() => {
const container = containerRef.current;
if (!container) return;
const compute = () => {
const hubEl = hubRef.current;
if (!hubEl) return;
const targets: WireTarget[] = [
{ el: trenerRef.current, side: 'left', id: 'trener' },
{ el: silowniaRef.current, side: 'left', id: 'silownia' },
{ el: cwiczacyRef.current, side: 'right', id: 'cwiczacy' },
{ el: adminRef.current, side: 'right', id: 'admin' },
];
const measured = measureWires(container, hubEl, targets, HUB_RADIUS);
setWires(measured.wires);
setHub(measured.hub);
};
compute();
// jsdom nie zna ResizeObserver — wystarczy jednorazowy pomiar (i tak puste recty)
if (typeof ResizeObserver !== 'undefined') {
const observer = new ResizeObserver(compute);
observer.observe(container);
window.addEventListener('resize', compute);
return () => {
observer.disconnect();
window.removeEventListener('resize', compute);
};
}
}, []);
return (
<Reveal className="hidden lg:block">
<div
ref={containerRef}
className="relative mt-14 grid h-[680px] grid-cols-2 grid-rows-2 gap-x-10 gap-y-6"
>
<svg
aria-hidden="true"
viewBox="0 0 100 100"
preserveAspectRatio="none"
className="absolute inset-0 h-full w-full"
>
<RayDefs wires={wires} idPrefix="" hub={hub} />
</svg>
<div
ref={hubRef}
className="window-glow absolute left-1/2 top-1/2 z-10 grid size-40 -translate-x-1/2 -translate-y-1/2 place-items-center rounded-full border border-line bg-(image:--card-grad) shadow-glow"
>
<div className="text-center">
<Brandmark size={40} className="mx-auto" />
<p className="mt-2 font-display text-sm font-bold text-ink">FitOS</p>
<p className="font-mono text-[10px] text-accent">rdzeń</p>
</div>
</div>
<div className="col-start-1 row-start-1 flex h-full items-center justify-start">
<div ref={trenerRef} className="h-full w-[65%]">
<ParticipantCard participant={PARTICIPANTS[1]} className="h-full" />
</div>
</div>
<div className="col-start-1 row-start-2 flex h-full items-center justify-start">
<div ref={silowniaRef} className="h-full w-[65%]">
<ParticipantCard participant={PARTICIPANTS[2]} className="h-full" />
</div>
</div>
<div className="col-start-2 row-start-1 flex h-full items-center justify-end">
<div ref={cwiczacyRef} className="h-full w-[65%]">
<ParticipantCard participant={PARTICIPANTS[0]} className="h-full" />
</div>
</div>
<div className="col-start-2 row-start-2 flex h-full items-center justify-end">
<div ref={adminRef} className="h-full w-[65%]">
<ParticipantCard participant={PARTICIPANTS[3]} className="h-full" />
</div>
</div>
</div>
</Reveal>
);
}
/**
* Diagram rdzenia pod lg: układ pionowy (telefon: ćwiczący, trener, rdzeń,
* siłownia, administrator — promienie tylko do dwóch najbliższych kafelków)
* lub dwie pary nad/pod rdzeniem (tablet sm+: promienie do wszystkich czterech).
*/
function StackDiagram() {
const containerRef = useRef<HTMLDivElement>(null);
const hubRef = useRef<HTMLDivElement>(null);
const cwiczacyRef = useRef<HTMLDivElement>(null);
const trenerRef = useRef<HTMLDivElement>(null);
const silowniaRef = useRef<HTMLDivElement>(null);
const adminRef = useRef<HTMLDivElement>(null);
const [wires, setWires] = useState<Wire[]>([]);
const [hub, setHub] = useState({ x: 50, y: 50 });
const [wide, setWide] = useState(() =>
typeof window !== 'undefined' && typeof window.matchMedia === 'function'
? window.matchMedia('(min-width: 640px)').matches
: true,
);
useEffect(() => {
if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') return;
const mq = window.matchMedia('(min-width: 640px)');
const onChange = () => setWide(mq.matches);
onChange();
mq.addEventListener('change', onChange);
return () => mq.removeEventListener('change', onChange);
}, []);
const compute = useCallback(() => {
const container = containerRef.current;
const hubEl = hubRef.current;
if (!container || !hubEl) return;
const targets: WireTarget[] = [
{ el: cwiczacyRef.current, side: 'top', id: 'cwiczacy' },
{ el: trenerRef.current, side: 'top', id: 'trener' },
{ el: silowniaRef.current, side: 'bottom', id: 'silownia' },
{ el: adminRef.current, side: 'bottom', id: 'admin' },
];
// telefon (1 kolumna): promienie tylko do najbliższych — Trener i Siłownia;
// tablet (2 kolumny): rdzeń między parami — promienie do wszystkich czterech
const visible = wide ? targets : targets.filter((t) => t.id === 'trener' || t.id === 'silownia');
const measured = measureWires(container, hubEl, visible, HUB_RADIUS_STACK);
setWires(measured.wires);
setHub(measured.hub);
}, [wide]);
useEffect(() => {
compute();
// jsdom nie zna ResizeObserver — wystarczy jednorazowy pomiar (i tak puste recty)
if (typeof ResizeObserver !== 'undefined') {
const observer = new ResizeObserver(compute);
if (containerRef.current) observer.observe(containerRef.current);
if (hubRef.current) observer.observe(hubRef.current);
window.addEventListener('resize', compute);
return () => {
observer.disconnect();
window.removeEventListener('resize', compute);
};
}
}, [compute]);
return (
<div ref={containerRef} className="relative mt-14 lg:hidden">
<svg
aria-hidden="true"
viewBox="0 0 100 100"
preserveAspectRatio="none"
className="pointer-events-none absolute inset-0 h-full w-full"
>
<RayDefs wires={wires} idPrefix="s-" hub={hub} />
</svg>
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 sm:gap-x-10">
<Reveal className="h-full">
<div ref={cwiczacyRef} className="h-full">
<ParticipantCard participant={PARTICIPANTS[0]} className="h-full" />
</div>
</Reveal>
<Reveal delayMs={60} className="h-full">
<div ref={trenerRef} className="h-full">
<ParticipantCard participant={PARTICIPANTS[1]} className="h-full" />
</div>
</Reveal>
<Reveal className="col-span-full flex justify-center py-10">
<div
ref={hubRef}
className="window-glow relative z-10 grid size-36 place-items-center rounded-full border border-line bg-(image:--card-grad) shadow-glow"
>
<div className="text-center">
<Brandmark size={34} className="mx-auto" />
<p className="mt-1.5 font-display text-sm font-bold text-ink">FitOS</p>
<p className="font-mono text-[10px] text-accent">rdzeń</p>
</div>
</div>
</Reveal>
<Reveal delayMs={120} className="h-full">
<div ref={silowniaRef} className="h-full">
<ParticipantCard participant={PARTICIPANTS[2]} className="h-full" />
</div>
</Reveal>
<Reveal delayMs={180} className="h-full">
<div ref={adminRef} className="h-full">
<ParticipantCard participant={PARTICIPANTS[3]} className="h-full" />
</div>
</Reveal>
</div>
</div>
);
}
/** Sekcja „Ekosystem” — rdzeń (od ogółu): mapa uczestników i legenda zazębień. */
export function Ecosystem() {
return (
<Section id="ekosystem">
<SectionHeading
kicker="/rdzen"
title="Ekosystem — rdzeń systemu"
lead="FitOS nie jest aplikacją treningową z dodatkiem siłowni. To rdzeń, w którym potrzeby ćwiczących, trenerów i siłowni zazębiają się nawzajem — nikt nie jest tu użytkownikiem końcowym."
/>
<HubDiagram />
{/* Telefon/tablet: rdzeń między parami uczestników z promieniowaniem */}
<StackDiagram />
</Section>
);
}
function ParticipantCard({
participant,
className,
}: {
participant: Participant;
className?: string;
}) {
const Icon = participant.icon;
const rows = [
{ key: 'wnosi', text: participant.brings, accent: true },
{ key: 'bierze', text: participant.gets, accent: false },
{ key: 'wiąże', text: participant.link, accent: true, last: true },
];
return (
<div
className={cn(
'window-glow rounded-lg border border-line bg-(image:--card-grad) p-5 shadow-card',
className,
)}
>
<div className="flex items-center gap-2.5">
<span className="grid size-8 place-items-center rounded-md border border-line bg-input text-accent">
<Icon size={15} aria-hidden="true" />
</span>
<span className="font-display text-[15px] font-bold text-ink">{participant.role}</span>
</div>
<dl className="mt-4 border-t border-line pt-3.5 text-[13px] leading-relaxed">
{rows.map((row) => (
<div
key={row.key}
className={cn(
'grid grid-cols-[4.5rem_1fr] items-baseline gap-x-3 pt-2.5',
!row.last && 'pb-2.5',
)}
>
<dt
className={cn(
'font-mono text-[10px] uppercase tracking-[0.14em]',
row.accent ? 'text-accent' : 'text-dim',
)}
>
{row.key}
</dt>
<dd className={row.accent ? 'text-dim' : 'text-ink'}>{row.text}</dd>
</div>
))}
</dl>
</div>
);
}