More assignment refactor + Single tracker assign rework

This commit is contained in:
loucass003 committed 2026-09-07 21:35:31 +02:00
1 parent f9df514b95
commit bed6f63624
9 files changed
+300 -51

No files matched your search

@@ -376,7 +376,7 @@ export function BodyInteractions({
</div>
<div
ref={personRef}
className="relative flex justify-center flex-grow"
className="relative flex h-full min-w-0 flex-grow justify-center"
>
{figure}
{slotsButtonsPos.map(
@@ -15,7 +15,6 @@ import {
} from '@/components/commons/BodyInteractions';
import { ExtremityFigure } from '@/components/commons/ExtremityFigure';
import { PersonFrontIcon, SIDES } from '@/components/commons/PersonFrontIcon';
import { TrackerPartCard } from '@/components/tracker/TrackerPartCard';
import {
BodyPartError,
COMMONS,
@@ -33,7 +32,11 @@ import {
ExtremityLayoutValue,
ExtremitySlot,
} from './extremities/ExtremityLayout';
import { ExtremityGroupCard, PartCardRenderer } from './parts/PartCard';
import {
AssignmentPartCard,
ExtremityGroupCard,
PartCardRenderer,
} from './parts/PartCard';
type BodySide = (typeof SIDES)[number];
@@ -94,6 +97,7 @@ export type ExtremityAssignmentViewProps = CommonAssignmentProps & {
view: { kind: 'extremity'; descriptor: ExtremityDescriptor };
side: ExtremitySide;
compact?: boolean;
fitContent?: boolean;
renderGroup?: ExtremityGroupRenderer;
};
@@ -118,14 +122,8 @@ type AssignmentRenderState = {
const defaultCard =
(onRoleSelected: (role: BodyPart) => void): PartCardRenderer =>
({ role, direction, td, roleError }) => (
<TrackerPartCard
roleError={roleError}
td={td}
role={role}
onClick={() => onRoleSelected(role)}
direction={direction}
/>
(props) => (
<AssignmentPartCard {...props} onClick={() => onRoleSelected(props.role)} />
);
const defaultGroup =
@@ -265,6 +263,7 @@ function ExtremityAssignmentView({
side,
fillHeight,
compact = false,
fitContent = false,
rolesWithErrors = {},
onRoleSelected,
renderGroup,
@@ -369,6 +368,7 @@ function ExtremityAssignmentView({
const layout = useMemo<ExtremityLayoutValue>(
() => ({
compact,
fitContent,
mirrored,
digit,
figure,
@@ -380,6 +380,7 @@ function ExtremityAssignmentView({
}),
[
compact,
fitContent,
mirrored,
digit,
figure,
@@ -16,6 +16,7 @@ export type DigitFlow = 'rows' | 'columns';
export type ExtremityLayoutValue = {
compact: boolean;
fitContent?: boolean;
mirrored: boolean;
digit: (name: string, slot: ExtremitySlot, flow: DigitFlow) => ReactNode;
figure: (height?: number) => ReactNode;
@@ -76,8 +77,16 @@ export function DigitColumn({
className?: string;
children: ReactNode;
}) {
const { fitContent } = useExtremityLayout();
return (
<div className={classNames('flex flex-col gap-2 h-full', className)}>
<div
className={classNames(
'flex flex-col gap-2',
fitContent ? 'h-fit' : 'h-full',
className
)}
>
{children}
</div>
);
@@ -107,11 +116,13 @@ function Slot({
edge,
children,
}: ExtremitySlot & { children: ReactNode }) {
const { fitContent } = useExtremityLayout();
return (
<SlotContext.Provider value={{ direction, edge }}>
<div
className={classNames(
edge === 'side' && 'h-full',
edge === 'side' && !fitContent && 'h-full',
direction === 'right' && 'text-right'
)}
>
@@ -49,12 +49,12 @@ const JOINT_POSITIONS: Record<HandFinger, [number, number][]> = {
};
function HandLayout() {
const { compact } = useExtremityLayout();
const { compact, fitContent } = useExtremityLayout();
if (compact)
return (
<ExtremityFrame
figureHeight={300}
figureHeight={fitContent ? 428 : 300}
top={
<DigitRow>
<Digit name="middle" />
@@ -63,7 +63,9 @@ function HandLayout() {
</DigitRow>
}
near={
<DigitColumn className="justify-end">
<DigitColumn
className={fitContent ? 'justify-end pb-24' : 'justify-end'}
>
<Digit name="index" />
<Digit name="thumb" />
<Digit name="root" />
@@ -214,14 +214,21 @@ export function BodyAssignmentPanel({
);
}
export function PickerTabs({ compact }: { compact?: boolean }) {
export function PickerTabs({
compact,
className,
}: {
compact?: boolean;
className?: string;
}) {
const { tab, setTab } = usePicker();
return (
<div
className={classNames(
'flex items-center bg-background-70 rounded-lg w-fit',
compact ? 'gap-0.5 p-0.5' : 'gap-1 p-1'
compact ? 'gap-0.5 p-0.5' : 'gap-1 p-1',
className
)}
>
{PICKER_TAB_ORDER.map((key) => (
@@ -267,7 +274,7 @@ function Tab({
);
}
function ExtremitySideToggle({
export function ExtremitySideToggle({
compact,
descriptor,
side,
@@ -27,6 +27,56 @@ export type PartCardProps = {
export type PartCardRenderer = (props: PartCardProps) => ReactNode;
export function AssignmentPartCard({
onClick,
td,
role,
direction,
roleError,
labelId,
compact = false,
number,
connector = true,
}: PartCardProps & { onClick?: () => void }) {
const velocity = useVelocity(td?.tracker);
return (
<button
type="button"
id={BodyPart[role]}
data-connector={connector ? undefined : 'off'}
onClick={onClick}
style={velocityGlowStyle(velocity)}
className={classNames(
'flex flex-col control rounded-md relative overflow-hidden transition-colors duration-150 ease-linear',
compact
? 'gap-0 w-full px-1.5 py-0.5'
: 'gap-1 w-[88px] smol:w-[120px] sm:w-[150px] px-2 py-1',
direction === 'left' ? 'text-left' : 'text-right'
)}
>
<PartCardWarning error={roleError} direction={direction} />
<PartCardLabel
role={role}
direction={direction}
number={number}
labelId={labelId}
/>
{td ? (
<Typography variant="standard">
{getTrackerName(td.tracker.info)}
</Typography>
) : (
<Typography
variant="standard"
color="text-background-30"
id="body_part-NONE"
/>
)}
</button>
);
}
const CARD_WIDTH = 'w-32 smol:w-40 xsAssign:w-44';
const WIDE_CARD_WIDTH =
'w-full max-w-96 smol:max-w-[30rem] xsAssign:max-w-[33rem]';
@@ -122,7 +172,7 @@ export function PartCardLabel({
return (
<div
className={classNames(
'flex items-center gap-1.5 max-w-full min-w-0 overflow-hidden',
'flex items-start gap-1.5 max-w-full min-w-0 break-words',
direction === 'right' && 'flex-row-reverse'
)}
>
@@ -130,8 +180,7 @@ export function PartCardLabel({
<Typography
variant="standard"
bold
truncate
whitespace="whitespace-nowrap"
whitespace="whitespace-normal"
id={labelId ?? 'body_part-' + BodyPart[role]}
/>
</div>
@@ -1,35 +1,80 @@
import classNames from 'classnames';
import ReactModal from 'react-modal';
import { useEffect, useRef } from 'react';
import { BodyPart } from 'solarxr-protocol';
import { Button } from '@/components/commons/Button';
import { Typography } from '@/components/commons/Typography';
import { CrossIcon } from '@/components/commons/icon/CrossIcon';
import {
BodyAssignment,
MirrorLegend,
ShowAllPartsToggle,
} from '@/components/onboarding/BodyAssignment';
import { BodyPartAssignment } from '@/components/onboarding/BodyPartAssignment';
import {
ExtremitySideToggle,
PickerTabs,
} from '@/components/onboarding/pages/trackers-assign/BodyAssignmentPanel';
import { useLocalization } from '@fluent/react';
import { NeckWarningModal } from '@/components/onboarding/NeckWarningModal';
import { useChokerWarning } from '@/hooks/choker-warning';
import { defaultConfig, useConfig } from '@/hooks/config';
import { useConfig } from '@/hooks/config';
import { useBreakpoint } from '@/hooks/breakpoint';
import {
getPickerSelection,
PICKER_TABS,
PickerContext,
providePicker,
} from '@/hooks/tracker-picker';
export function SingleTrackerBodyAssignmentMenu({
isOpen,
onClose,
onRoleSelected,
bodyPart,
}: {
isOpen: boolean;
onClose: () => void;
onRoleSelected: (role: BodyPart) => void;
bodyPart?: BodyPart;
}) {
const { l10n } = useLocalization();
const { config } = useConfig();
const pickerShell = providePicker();
const { isMobileAssign } = useBreakpoint('mobileAssign');
const isMobile = isMobileAssign;
const selectionRef = useRef<HTMLDivElement>(null);
const { closeChokerWarning, tryOpenChokerWarning, shouldShowChokerWarn } =
useChokerWarning({
next: onRoleSelected,
});
const picker = {
...pickerShell,
activePart: BodyPart.NONE,
selectPart: tryOpenChokerWarning,
};
useEffect(() => {
if (!isOpen) return;
const selection = getPickerSelection(bodyPart);
pickerShell.setTab(selection.tab);
pickerShell.setSide(selection.side);
}, [isOpen, bodyPart, pickerShell.setTab, pickerShell.setSide]);
const { view, dotSize } = PICKER_TABS[picker.tab];
const sideControl =
view.kind === 'extremity' ? (
<ExtremitySideToggle
compact
descriptor={view.descriptor}
side={picker.side}
onChange={picker.setSide}
/>
) : (
<MirrorLegend compact />
);
return (
<>
<ReactModal
@@ -38,47 +83,156 @@ export function SingleTrackerBodyAssignmentMenu({
shouldCloseOnEsc
onRequestClose={onClose}
overlayClassName={classNames(
'fixed top-0 right-0 left-0 bottom-0 flex flex-col items-center w-full h-full justify-center bg-background-90 bg-opacity-90 z-20'
'fixed inset-0 flex bg-background-90 bg-opacity-90 z-20'
)}
className={classNames(
'focus:ring-transparent focus:ring-offset-transparent focus:outline-transparent outline-none mt-12 z-10 overflow-y-auto'
'focus:ring-transparent focus:ring-offset-transparent focus:outline-transparent',
'relative h-full w-full outline-none z-10 text-background-10',
'overflow-hidden'
)}
>
<div className="flex w-full h-full flex-col gap-10 px-3">
<div className="flex flex-col h-full items-center xsAssign:flex-row xsAssign:gap-8 xsAssign:justify-center">
<div className="flex flex-col gap-4 xsAssign:max-w-sm">
<Typography variant="mobile-title" bold>
{l10n.getString('body_assignment_menu')}
</Typography>
<Typography>
{l10n.getString('body_assignment_menu-description')}
</Typography>
<div className="flex">
<Button
variant="secondary"
to="/onboarding/trackers-assign"
state={{ alonePage: true }}
<div
className={classNames(
'grid min-w-0',
isMobile
? 'h-full min-h-0 grid-cols-1 grid-rows-[auto_minmax(0,1fr)] gap-3 overflow-hidden px-1 pt-[calc(var(--topbar-h)+0.5rem)]'
: 'h-full min-h-0 grid-rows-1 grid-cols-[minmax(15rem,0.7fr)_minmax(0,1.5fr)] gap-8 overflow-hidden p-7'
)}
>
<div
className={classNames(
'flex min-h-0 min-w-0 flex-col',
isMobile ? 'gap-2' : 'gap-5 overflow-y-auto pt-3'
)}
>
<div className="flex min-w-0 flex-col gap-3">
<div className="flex items-center gap-2">
<div className="min-w-0 flex-1 [overflow-wrap:anywhere]">
<Typography
variant={isMobile ? 'section-title' : 'main-title'}
bold
>
{l10n.getString('body_assignment_menu')}
</Typography>
</div>
<button
type="button"
className={classNames(
'flex h-10 w-10 shrink-0 items-center justify-center rounded-md fill-background-10 hover:bg-background-50 focus-visible:ring-2 focus-visible:ring-background-20',
!isMobile &&
'absolute right-7 top-[calc(var(--topbar-h)+0.5rem)] z-10'
)}
onClick={onClose}
aria-label={l10n.getString('mounting_selection_menu-close')}
title={l10n.getString('mounting_selection_menu-close')}
>
{l10n.getString('body_assignment_menu-manage_trackers')}
</Button>
<CrossIcon size={24} />
</button>
</div>
<ShowAllPartsToggle />
<MirrorLegend />
<div className="mobileAssign:hidden">
<Typography>
{l10n.getString('body_assignment_menu-description')}
</Typography>
</div>
</div>
<div className="flex flex-wrap items-center gap-2">
<Button
variant="secondary"
onClick={() => onRoleSelected(BodyPart.NONE)}
className="mobileAssign:px-3 mobileAssign:py-1.5 min-w-0 max-w-full"
to="/onboarding/trackers-assign"
state={{ alonePage: true }}
>
{l10n.getString('body_assignment_menu-unassign_tracker')}
{l10n.getString('body_assignment_menu-manage_trackers')}
</Button>
</div>
<div className="flex flex-col gap-4 rounded-xl fill-background-50 py-2 xsAssign:flex-grow">
<BodyAssignment
mirror={config?.mirrorView ?? defaultConfig.mirrorView}
onRoleSelected={tryOpenChokerWarning}
<Button
variant="secondary"
className="mobileAssign:px-3 mobileAssign:py-1.5 min-w-0 max-w-full"
onClick={() => onRoleSelected(BodyPart.NONE)}
id="body_assignment_menu-unassign_tracker"
/>
</div>
<ShowAllPartsToggle compact={isMobile} />
</div>
<div
ref={selectionRef}
className={classNames(
'flex min-h-0 min-w-0 flex-col gap-3',
isMobile ? 'h-full min-h-0' : 'h-full p-4'
)}
>
{!isMobile && (
<div className="grid grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)] items-center gap-2">
<PickerContext.Provider value={picker}>
<PickerTabs compact />
{sideControl}
</PickerContext.Provider>
</div>
)}
<div className="flex-1 min-h-0 min-w-0">
<PickerContext.Provider value={picker}>
<div
className={classNames(
isMobile
? 'h-full min-h-0 overflow-y-auto pb-[calc(7.5rem+env(safe-area-inset-bottom))]'
: view.kind === 'body'
? 'h-full min-h-0 overflow-hidden'
: 'h-full min-h-0 overflow-y-auto'
)}
>
<div className={classNames('h-full min-h-fit')}>
{view.kind === 'extremity' ? (
<BodyPartAssignment
view={view}
side={picker.side}
dotSize={dotSize.tap}
compact={isMobile}
fitContent={isMobile}
fillHeight
onRoleSelected={picker.selectPart}
/>
) : (
<BodyPartAssignment
view={view}
mirror={config?.mirrorView ?? false}
dotSize={dotSize.tap}
fillHeight
onRoleSelected={picker.selectPart}
/>
)}
</div>
</div>
</PickerContext.Provider>
</div>
</div>
</div>
{isMobile && (
<div className="pointer-events-none fixed inset-x-3 bottom-[calc(0.5rem+env(safe-area-inset-bottom))] z-20 mx-auto flex max-w-md flex-col items-center gap-2">
<PickerContext.Provider
value={{
...picker,
setTab: (tab) => {
picker.setTab(tab);
const selection = selectionRef.current;
const modal = selection?.closest('[role="dialog"]');
if (
selection &&
modal &&
selection.getBoundingClientRect().top <
modal.getBoundingClientRect().top
) {
selection.scrollIntoView({ block: 'start' });
}
},
}}
>
<div className="pointer-events-auto w-fit">{sideControl}</div>
<PickerTabs
compact
className="pointer-events-auto w-full shadow-lg ring-1 ring-background-50 [&>div]:flex [&>div]:min-h-11 [&>div]:min-w-0 [&>div]:flex-1 [&>div]:items-center [&>div]:justify-center [&>div]:text-center"
/>
</PickerContext.Provider>
</div>
)}
</ReactModal>
<NeckWarningModal
@@ -160,6 +160,7 @@ export function TrackerSettingsPage() {
isOpen={selectBodyPart}
onClose={() => setSelectBodyPart(false)}
onRoleSelected={onRoleSelected}
bodyPart={tracker?.tracker.info?.bodyPart}
/>
<MountingSelectionMenu
bodyPart={tracker?.tracker.info?.bodyPart}
+24
View File
@@ -156,6 +156,30 @@ export const PICKER_TABS: Record<PickerTab, PickerTabSpec> = {
export const PICKER_TAB_ORDER: PickerTab[] = ['body', 'fingers', 'toes'];
export function getPickerSelection(bodyPart?: BodyPart): {
tab: PickerTab;
side: ExtremitySide;
} {
if (bodyPart == null) return { tab: 'body', side: 'right' };
for (const tab of PICKER_TAB_ORDER) {
const view = PICKER_TABS[tab].view;
if (view.kind !== 'extremity') continue;
for (const side of ['left', 'right'] as ExtremitySide[]) {
const extremity = view.descriptor.sides[side];
if (
extremity.root === bodyPart ||
Object.values(extremity.digits).some((parts) => parts.includes(bodyPart))
) {
return { tab, side };
}
}
}
return { tab: 'body', side: 'right' };
}
export function providePicker() {
const { l10n } = useLocalization();