From 603dc8d8393804a7258812d6773eda8437e86660 Mon Sep 17 00:00:00 2001 From: Guido Doumen Date: Tue, 17 Nov 2026 08:55:32 +0100 Subject: [PATCH 1/6] Add WorkoutImportDialogView and extract shared WorkoutCategorySelect Pure import dialog view (landing/importing/result/error) with stories and tests. The category select of the workout details dialog is extracted into WorkoutCategorySelect, behaviour unchanged. --- .../WorkoutImport/WorkoutImportDialogView.jsx | 177 ++++++++++++++++++ .../WorkoutImportDialogView.stories.jsx | 36 ++++ .../WorkoutImportDialogView.unit.test.jsx | 167 +++++++++++++++++ .../WorkoutCategorySelect.jsx | 42 +++++ .../WorkoutCategorySelect.stories.jsx | 16 ++ .../WorkoutCategorySelect.unit.test.jsx | 54 ++++++ .../selection/WorkoutCategorySelect/index.jsx | 1 + .../WorkoutDetailsDialogView.jsx | 29 +-- .../modules/workout/selection/index.jsx | 1 + 9 files changed, 498 insertions(+), 25 deletions(-) create mode 100644 src/components/modules/workout/WorkoutImport/WorkoutImportDialogView.jsx create mode 100644 src/components/modules/workout/WorkoutImport/WorkoutImportDialogView.stories.jsx create mode 100644 src/components/modules/workout/WorkoutImport/WorkoutImportDialogView.unit.test.jsx create mode 100644 src/components/modules/workout/selection/WorkoutCategorySelect/WorkoutCategorySelect.jsx create mode 100644 src/components/modules/workout/selection/WorkoutCategorySelect/WorkoutCategorySelect.stories.jsx create mode 100644 src/components/modules/workout/selection/WorkoutCategorySelect/WorkoutCategorySelect.unit.test.jsx create mode 100644 src/components/modules/workout/selection/WorkoutCategorySelect/index.jsx diff --git a/src/components/modules/workout/WorkoutImport/WorkoutImportDialogView.jsx b/src/components/modules/workout/WorkoutImport/WorkoutImportDialogView.jsx new file mode 100644 index 0000000..19989f5 --- /dev/null +++ b/src/components/modules/workout/WorkoutImport/WorkoutImportDialogView.jsx @@ -0,0 +1,177 @@ +import React, { useCallback } from 'react' +import styled from 'styled-components' +import { Button, ButtonBar, ErrorText } from '../../../atoms' +import { Dialog, Dropzone } from '../../../molecules' +import { WorkoutCategorySelect } from '../selection/WorkoutCategorySelect' + +// Same fixed box as the Import Routes dialog: one box for every phase, only the content changes +export const WORKOUT_IMPORT_DIALOG_WIDTH = 'min(980px, 70vw)' +export const WORKOUT_IMPORT_DIALOG_HEIGHT = 'min(660px, 75vh)' + +export const WORKOUT_IMPORT_FILTERS = [ + { name: 'Workouts', extensions: ['zwo', 'json'] }, + { name: 'Zwift Workout', extensions: ['zwo'] }, + { name: 'Incyclist Workout', extensions: ['json'] }, +] + +const TITLES = { + landing: 'Import Workout', + importing: 'Importing...', + result: 'Import Result', + error: 'Import Failed', +} + +const TileArea = styled.div` + display: flex; + align-items: stretch; + justify-content: center; + width: 100%; + height: calc(100% - 5vh); + padding: 3vh 2vw 0 2vw; + box-sizing: border-box; +` + +const TileTitle = styled.div` + font-size: 2.2vh; + font-weight: bold; + color: white; +` + +const TileSubline = styled.div` + font-size: 1.5vh; + color: white; + opacity: 0.8; +` + +const TileContent = styled.div` + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + gap: 1vh; + padding: 2vh; + text-align: center; +` + +const Body = styled.div` + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + height: calc(100% - 7.7vh); + text-align: center; + padding: 2vh; + box-sizing: border-box; + gap: 2vh; + font-size: 2vh; +` + +const SelectWrapper = styled.div` + width: 40ch; + max-width: 100%; + text-align: left; +` + +const Landing = ({ onFiles }) => { + const onDrop = useCallback((dropInfo) => { + const files = (Array.isArray(dropInfo) ? dropInfo : [dropInfo]).filter(Boolean) + if (files.length > 0) + onFiles?.(files) + }, [onFiles]) + + return ( + + + Choose Workout File + ZWO or JSON + + } + /> + + ) +} + +const Importing = ({ fileName, onCancel }) => ( + <> + {fileName} + + + + + + + + ), +})) + +const emit = (evt) => act(() => { (observer.listeners[evt] ?? []).forEach(l => l()) }) + +describe('WorkoutImportDialog', () => { + + beforeEach(() => { + vi.clearAllMocks() + observer.listeners['import-update'] = [] + state.props = { phase: 'landing', knownGroups: ['Sweet', 'VO2'] } + service.getImportDisplayProps.mockImplementation(() => state.props) + service.getPageObserver.mockReturnValue(observer) + }) + + test('renders the initial phase from the service', () => { + render() + expect(screen.getByText('phase:landing')).toBeTruthy() + }) + + test('renders the phase the service is already in (drop)', () => { + state.props = { phase: 'importing', knownGroups: [] } + render() + expect(screen.getByText('phase:importing')).toBeTruthy() + }) + + test('re-reads the display props on import-update', () => { + render() + state.props = { phase: 'result', result: { id: 'w1' }, knownGroups: ['Sweet'] } + emit('import-update') + expect(screen.getByText('phase:result')).toBeTruthy() + }) + + test('onFiles and onPickAnother go to the service', () => { + render() + fireEvent.click(screen.getByText('files')) + expect(service.onImportFiles).toHaveBeenCalledWith(['f'], 'dialog') + fireEvent.click(screen.getByText('another')) + expect(service.onImportOpen).toHaveBeenCalledTimes(1) + }) + + test('onSetGroup passes the result id and the group', () => { + state.props = { phase: 'result', result: { id: 'w1', group: 'VO2' }, knownGroups: ['Sweet', 'VO2'] } + render() + fireEvent.click(screen.getByText('group')) + expect(service.onImportSetGroup).toHaveBeenCalledWith('w1', 'Sweet') + }) + + test('close ends the import, then reports onClose; unmount does not close again', () => { + const onClose = vi.fn() + const order = [] + service.onImportClose.mockImplementation(() => order.push('service')) + onClose.mockImplementation(() => order.push('parent')) + + const { unmount } = render() + fireEvent.click(screen.getByText('done')) + expect(order).toEqual(['service', 'parent']) + + unmount() + expect(service.onImportClose).toHaveBeenCalledTimes(1) + }) + + test('unmount without a close action closes the import once and does not call onClose', () => { + const onClose = vi.fn() + const { unmount } = render() + unmount() + expect(service.onImportClose).toHaveBeenCalledTimes(1) + expect(onClose).not.toHaveBeenCalled() + }) + + test('removes the import-update listener on unmount', () => { + const { unmount } = render() + const cb = observer.on.mock.calls.find(c => c[0] === 'import-update')[1] + unmount() + expect(observer.off).toHaveBeenCalledWith('import-update', cb) + }) +}) diff --git a/src/components/modules/workout/WorkoutImport/index.jsx b/src/components/modules/workout/WorkoutImport/index.jsx new file mode 100644 index 0000000..c7e6cd3 --- /dev/null +++ b/src/components/modules/workout/WorkoutImport/index.jsx @@ -0,0 +1 @@ +export * from './WorkoutImportDialog' diff --git a/src/components/modules/workout/index.jsx b/src/components/modules/workout/index.jsx index 984671b..701012c 100644 --- a/src/components/modules/workout/index.jsx +++ b/src/components/modules/workout/index.jsx @@ -1,4 +1,5 @@ export * from './control' export * from './dashboard' export * from './selection' -export * from './ScheduledWorkoutPrompt' \ No newline at end of file +export * from './ScheduledWorkoutPrompt' +export * from './WorkoutImport' From 0f00ba4ff6979e9da285eb7465f5561f6a24aed5 Mon Sep 17 00:00:00 2001 From: Guido Doumen Date: Tue, 17 Nov 2026 09:00:07 +0100 Subject: [PATCH 3/6] Workouts page: Import Workout button, page-wide drop overlay, remove import cards The import flow now runs in WorkoutImportDialog, opened from a header button or by dropping a file anywhere on the page. The carousel upload/active-import cards and the retry wiring are removed, and the create-info text points at the new button. --- .../workout/selection/UploadCard/index.jsx | 7 - .../workout/selection/UploadCard/stories.jsx | 24 ---- .../workout/selection/UploadCard/summary.jsx | 59 --------- .../modules/workout/selection/index.jsx | 1 - src/pages/workouts/page.jsx | 30 ++++- src/pages/workouts/page.unit.test.jsx | 51 +++++++- src/pages/workouts/screen.jsx | 121 ++++++++++++++++-- src/pages/workouts/screen.stories.jsx | 4 +- src/pages/workouts/screen.unit.test.jsx | 48 ++++++- 9 files changed, 229 insertions(+), 116 deletions(-) delete mode 100644 src/components/modules/workout/selection/UploadCard/index.jsx delete mode 100644 src/components/modules/workout/selection/UploadCard/stories.jsx delete mode 100644 src/components/modules/workout/selection/UploadCard/summary.jsx diff --git a/src/components/modules/workout/selection/UploadCard/index.jsx b/src/components/modules/workout/selection/UploadCard/index.jsx deleted file mode 100644 index b4d5825..0000000 --- a/src/components/modules/workout/selection/UploadCard/index.jsx +++ /dev/null @@ -1,7 +0,0 @@ -import React from 'react' -import { UploadSummary } from './summary' -import { Card } from '../base/Card' - -export const UploadCard = (props) => { - return -} diff --git a/src/components/modules/workout/selection/UploadCard/stories.jsx b/src/components/modules/workout/selection/UploadCard/stories.jsx deleted file mode 100644 index dfb24e0..0000000 --- a/src/components/modules/workout/selection/UploadCard/stories.jsx +++ /dev/null @@ -1,24 +0,0 @@ -import React from 'react'; - -import {UploadCard} from './index'; - - -//const routeData = route.decoded - -export default { - component: UploadCard, - title: 'Modules/WorkoutSelection/Upload', - argTypes: { onClick: { action: 'clicked' } }, -}; - -const Template = args => ; - -export const Default = Template.bind({}); -Default.args = { - height: 500, - loaded:true, - visible:true, - ready:true -}; - - diff --git a/src/components/modules/workout/selection/UploadCard/summary.jsx b/src/components/modules/workout/selection/UploadCard/summary.jsx deleted file mode 100644 index dfbdbcd..0000000 --- a/src/components/modules/workout/selection/UploadCard/summary.jsx +++ /dev/null @@ -1,59 +0,0 @@ -import React from 'react'; -import { Container, ImageContainer, ButtonContainer, DataContainer, Title } from '../base/atoms'; -import { Button,Column,Row} from '../../../../atoms'; -import styled from 'styled-components'; -import { Dropzone } from '../../../../molecules'; - -const DEFAULT_TITLE = 'Import Workout' -const DEFAULT_FILTERS = [ - { name: 'Workouts', extensions: ['zwo'] } -] - - -const FileDrop = styled(Dropzone)` - color: white; - margin:10px; -` - -export const UploadSummary = ( { id, title=DEFAULT_TITLE, filters=DEFAULT_FILTERS, ready,visible, - width='20vw',height='30vh',onMoreInfo,onOK }) => { - - - const onDrop = async (...args)=>{ - if (onOK) { - await onOK(...args) - return null; - } - return null; - } - - - - return ( - - - - - - - - - - - - - {title} - - - - - - , +})) + vi.mock('../../hooks', async (importOriginal) => { const actual = await importOriginal() return { ...actual, useWindowDimensions: () => ({ width: 1000, height: 800 }) } @@ -96,14 +101,13 @@ describe('WorkoutsPage', () => { test('card actions and carousel callbacks are forwarded by id', () => { renderPage() const p = screenCalls.at(-1) - p.onOK('w1', ['f']) + p.onOK('w1') p.onDelete('w1') - p.onRetry('imp') p.onInitialized('myWorkouts', { item: 1, itemsInSlide: 4 }) p.onSlideChanged('myWorkouts', { item: 2, itemsInSlide: 4 }) - expect(service.onCardOK).toHaveBeenCalledWith('w1', ['f']) + expect(service.onCardOK).toHaveBeenCalledWith('w1') expect(service.onDelete).toHaveBeenCalledWith('w1') - expect(service.onRetry).toHaveBeenCalledWith('imp') + expect(screenCalls.at(-1).onRetry).toBeUndefined() expect(service.onCarouselInitialized).toHaveBeenCalledWith('myWorkouts', 1, 4) expect(service.onCarouselUpdated).toHaveBeenCalledWith('myWorkouts', 2, 4) }) @@ -152,4 +156,39 @@ describe('WorkoutsPage', () => { renderPage() expect(screen.queryByText(/steps to create a workout/)).toBeNull() }) + + test('import button opens the import flow and mounts the dialog', () => { + renderPage() + expect(screen.queryByText(/import-dialog/)).toBeNull() + act(() => { screenCalls.at(-1).onImportWorkout() }) + expect(service.onImportOpen).toHaveBeenCalledTimes(1) + expect(screen.getByText('import-dialog:button')).toBeTruthy() + expect(screenCalls.at(-1).dropEnabled).toBe(false) + }) + + test('a page drop hands the files to the service before the dialog mounts', () => { + renderPage() + expect(screenCalls.at(-1).dropEnabled).toBe(true) + service.onImportFiles.mockImplementation(() => { + expect(screen.queryByText(/import-dialog/)).toBeNull() + }) + const files = [{ type: 'url', url: 'file:///a.zwo' }] + act(() => { screenCalls.at(-1).onDropFiles(files) }) + expect(service.onImportFiles).toHaveBeenCalledWith(files, 'page-drop') + expect(screen.getByText('import-dialog:page-drop')).toBeTruthy() + }) + + test('closing the dialog unmounts it and re-enables the drop overlay', () => { + renderPage() + act(() => { screenCalls.at(-1).onImportWorkout() }) + fireEvent.click(screen.getByText('close-import')) + expect(screen.queryByText(/import-dialog/)).toBeNull() + expect(screenCalls.at(-1).dropEnabled).toBe(true) + }) + + test('create-info step 4 points at the Import Workout button', () => { + service.getPageDisplayProperties.mockReturnValue(props({ createInfo: { markAsSeenDefault: true } })) + renderPage() + expect(screen.getByText(/Import Workout button/)).toBeTruthy() + }) }) diff --git a/src/pages/workouts/screen.jsx b/src/pages/workouts/screen.jsx index 32e06c7..2a5428f 100644 --- a/src/pages/workouts/screen.jsx +++ b/src/pages/workouts/screen.jsx @@ -1,6 +1,9 @@ import React, {useEffect, useMemo, useRef, useState } from "react" import MainPage from "../../components/molecules/MainPage" -import { PageTitle,GroupTitle, Loader, Center } from "../../components/atoms" +import { PageTitle,GroupTitle, Loader, Center, Button } from "../../components/atoms" +import { ImportIcon } from "../../components/atoms/Icons/ImportIcon" +import { Dropzone } from "../../components/molecules" +import { WORKOUT_IMPORT_FILTERS } from "../../components/modules/workout/WorkoutImport/WorkoutImportDialogView" import styled from "styled-components" import { Column, Row } from "../../components/atoms/layout/View" import { useKey } from "../../hooks/ui/useKey" @@ -8,8 +11,6 @@ import { useMouseSwipe } from "../../hooks/ui/useMouseSwipe" import { Carousel } from "../../components/atoms/Carousel" import { NavigationBar } from "../../components/molecules/NavigationBar" import { AppThemeProvider } from "../../theme" -import { ActiveImportCard } from "../../components/modules/routeSelection/ActiveImportCard" -import {UploadCard} from '../../components/modules/workout/selection/UploadCard' import {WorkoutCard} from '../../components/modules/workout/selection/WorkoutCard' import { WorkoutCreateCard } from "../../components/modules/workout/selection/CreateCard" import { ScheduledWorkoutCard } from "../../components/modules/workout/selection/ScheduledWorkoutCard" @@ -34,9 +35,67 @@ const ContentArea = styled(Column)` padding-left:40px; padding-right: 40px; overflow-y: hidden; + position: relative; + box-sizing: border-box; ` +// page-level drop overlay, only rendered while a file is dragged over the page +const DropOverlay = styled(Dropzone)` + position: absolute; + top: 0; + left: 0; + right: 0; + bottom: 0; + box-sizing: border-box; + margin: 0; + z-index: 20; + background-color: rgba(0,0,0,0.6); + border-width: 3px; + border-color: #dd9933; + border-radius: 8px; + color: white; +` + +const DropOverlayTitle = styled.div` + font-size: 2.4vh; + font-weight: bold; +` + +// title stays centred, the Import button sits on the right +const HeaderLayout = styled.div` + display: grid; + grid-template-columns: 1fr auto 1fr; + align-items: center; + width: 100%; +` + +const TitleCell = styled.div` + grid-column: 2; + white-space: nowrap; +` + +const ImportSlot = styled.div` + grid-column: 3; + justify-self: end; + display: flex; +` + +const HeaderButtonContent = styled.span` + display: inline-flex; + align-items: center; + gap: 0.4em; + flex-shrink: 0; +` + +export const WORKOUT_DROP_OVERLAY_TITLE = 'Drop a workout file (ZWO or JSON)' + +const ImportWorkoutButton = ({ onClick }) => ( + +) + const CardView= styled(Row)` justify-content:center; user-select:none; @@ -76,8 +135,6 @@ export const ListContainer = styled(View)` ` const CARD_COMPONENTS = { - WorkoutImport: UploadCard, - ActiveWorkoutImport: ActiveImportCard, WorkoutCreate: WorkoutCreateCard, Workout: WorkoutCard, ScheduledWorkout: ScheduledWorkoutCard @@ -89,7 +146,7 @@ const callback = (fn, listId, e) => { fn(listId, e) } -const WorkoutList = ({ list, cardSize, itemsFit, responsive, onOK, onDelete, onRetry, +const WorkoutList = ({ list, cardSize, itemsFit, responsive, onOK, onDelete, onInitialized, onUpdated, onSlideChange, onSlideChanged, setScrolling }) => { const [cardData, setCardData] = useState(list.cards) @@ -122,10 +179,9 @@ const WorkoutList = ({ list, cardSize, itemsFit, responsive, onOK, onDelete, onR hidden={!content.visible} onOK={onOK ? (...args) => { onOK(card.id, ...args) } : undefined} onDelete={onDelete ? () => { onDelete(card.id) } : undefined} - onRetry={onRetry ? () => { onRetry(card.id) } : undefined} /> - }).filter(Boolean), [cardData, cardSize, onOK, onDelete, onRetry]) + }).filter(Boolean), [cardData, cardSize, onOK, onDelete]) const header = list.title @@ -160,7 +216,7 @@ export const WorkoutsScreen = ({ loading, cardSize, offset = 0, responsive, itemsFit, width, height, lists, upcoming = null, // eslint-disable-next-line no-unused-vars displayType = 'tiles', - onInitialized, onUpdated, onSlideChange, onSlideChanged, onOK, closePage, onDelete, onRetry }) => { + onInitialized, onUpdated, onSlideChange, onSlideChanged, onOK, closePage, onDelete, onImportWorkout, onDropFiles, dropEnabled = true }) => { const swipeDisabled = useRef(false); // upcoming (scheduled) workouts come first; keyed by list id so the section mounts/unmounts @@ -168,6 +224,36 @@ export const WorkoutsScreen = const allLists = useMemo(() => [...(upcoming ? [upcoming] : []), ...(lists ?? [])], [upcoming, lists]) const refDiv = useRef(null); + // --- page-level drop overlay (same mechanism as the Routes page) --- + const dragDepth = useRef(0) + const [dragActive, setDragActive] = useState(false) + + const onContentDragEnterCapture = (e) => { + e.preventDefault() + dragDepth.current += 1 + if (dragDepth.current === 1) + setDragActive(true) + } + const onContentDragOverCapture = (e) => { e.preventDefault() } + const onContentDragLeaveCapture = () => { + dragDepth.current = Math.max(0, dragDepth.current - 1) + if (dragDepth.current === 0) + setDragActive(false) + } + const onContentDropCapture = (e) => { + // an unhandled drop would navigate the window to the file. Hide the overlay only after the + // event is fully dispatched, otherwise it unmounts before its own drop handler runs. + e.preventDefault() + setTimeout(() => { + dragDepth.current = 0 + setDragActive(false) + }, 0) + } + const onOverlayDrop = (dropInfo) => { + if (typeof onDropFiles === 'function') + onDropFiles(Array.isArray(dropInfo) ? dropInfo : [dropInfo]) + } + const onScrollUp = (pixels)=> { if (swipeDisabled.current===true) @@ -259,14 +345,19 @@ export const WorkoutsScreen = - - Workouts + + + Workouts + + { !loading && cardSize && lists ? allLists.map( list => ) : @@ -276,6 +367,12 @@ export const WorkoutsScreen = { (loading || !cardSize ) ?
:null } + {dragActive && dropEnabled ? + {WORKOUT_DROP_OVERLAY_TITLE}} /> + : null} +
diff --git a/src/pages/workouts/screen.stories.jsx b/src/pages/workouts/screen.stories.jsx index 0db6dc4..5f89751 100644 --- a/src/pages/workouts/screen.stories.jsx +++ b/src/pages/workouts/screen.stories.jsx @@ -7,7 +7,8 @@ export default { argTypes: { onOK: { action: 'OK' }, onDelete: { action: 'delete' }, - onRetry: { action: 'retry' }, + onImportWorkout: { action: 'import workout' }, + onDropFiles: { action: 'drop files' }, }, } @@ -30,7 +31,6 @@ const workout = (id, title, extra = {}) => ({ const myWorkouts = { id: 'myWorkouts', title: 'My Workouts', observer: noObserver, cards: [ - { id: 'Import', cardType: 'WorkoutImport', props: { title: 'Import Workout', filters: [], visible: true } }, { id: 'Create', cardType: 'WorkoutCreate', props: { title: 'Create Workout', visible: true } }, workout('w1', 'Sweet Spot'), ] diff --git a/src/pages/workouts/screen.unit.test.jsx b/src/pages/workouts/screen.unit.test.jsx index 7ded5e6..d9411b3 100644 --- a/src/pages/workouts/screen.unit.test.jsx +++ b/src/pages/workouts/screen.unit.test.jsx @@ -1,6 +1,6 @@ import React from 'react' import { describe, test, expect, vi } from 'vitest' -import { render } from '@testing-library/react' +import { render, screen, fireEvent } from '@testing-library/react' import { WorkoutsScreen } from './screen' vi.mock('../../components/molecules/MainPage', () => ({ default: ({ children }) =>
{children}
})) @@ -9,6 +9,18 @@ vi.mock('../../hooks/ui/useKey', () => ({ useKey: () => {} })) vi.mock('../../hooks/ui/useMouseSwipe', () => ({ useMouseSwipe: () => {} })) vi.mock('../../components/atoms/Carousel', () => ({ Carousel: () =>
})) +// Dropzone relies on native drag/drop internals that jsdom lacks - stubbed so a test can hand over a drop +vi.mock('../../components/molecules', async (importOriginal) => { + const actual = await importOriginal() + return { + ...actual, + Dropzone: (props) => ( +
props.onDrop?.([{ type: 'url', url: 'file:///w/a.zwo' }])}>{props.text}
+ ), + } +}) + const cardSize = { width: 200, height: 300, padding: 0 } const list = (id, title, observer) => ({ id, title, observer, cards: [] }) const renderScreen = (props) => render() @@ -41,4 +53,38 @@ describe('WorkoutsScreen', () => { rerender() expect(observer.on).toHaveBeenCalledTimes(2) }) + + test('renders the Import Workout button and reports clicks', () => { + const onImportWorkout = vi.fn() + renderScreen({ lists: [], onImportWorkout }) + fireEvent.click(screen.getByText('Import Workout')) + expect(onImportWorkout).toHaveBeenCalledTimes(1) + }) + + test('dragging a file over the page shows the drop overlay', () => { + const { container } = renderScreen({ lists: [], dropEnabled: true }) + expect(screen.queryByText('Drop a workout file (ZWO or JSON)')).toBeNull() + fireEvent.dragEnter(container.querySelector('.workouts-page')) + expect(screen.getByText('Drop a workout file (ZWO or JSON)')).toBeTruthy() + }) + + test('the overlay is not shown when drops are disabled', () => { + const { container } = renderScreen({ lists: [], dropEnabled: false }) + fireEvent.dragEnter(container.querySelector('.workouts-page')) + expect(screen.queryByText('Drop a workout file (ZWO or JSON)')).toBeNull() + }) + + test('dropping on the overlay reports the files', () => { + const onDropFiles = vi.fn() + const { container } = renderScreen({ lists: [], dropEnabled: true, onDropFiles }) + fireEvent.dragEnter(container.querySelector('.workouts-page')) + fireEvent.drop(container.querySelector('.workout-drop-overlay')) + expect(onDropFiles).toHaveBeenCalledWith([{ type: 'url', url: 'file:///w/a.zwo' }]) + }) + + test('no Import card is rendered even if the service passes one', () => { + const l = { id: 'myWorkouts', title: 'My Workouts', cards: [{ id: 'Import', cardType: 'WorkoutImport', props: { title: 'Import Workout', visible: true } }] } + const { container } = renderScreen({ lists: [l] }) + expect(container.querySelectorAll('.item').length).toBe(0) + }) }) From 8c03a6081411e24c455796a219723a8a7988ea03 Mon Sep 17 00:00:00 2001 From: Guido Doumen Date: Tue, 17 Nov 2026 10:44:54 +0100 Subject: [PATCH 4/6] Rebuild workout import result phase: success header, category, workout graph, Import another Result phase shows a success header, a left-aligned category select that always has a value, and the imported workout graph (centred fallback panel when no workout is provided). Title is now Import Successful, an Import another button returns to the landing phase. Importing shows a loader, error shows an error icon above the message. --- .../WorkoutImport/WorkoutImportDialogView.jsx | 146 +++++++++++++++--- .../WorkoutImportDialogView.stories.jsx | 36 +++++ .../WorkoutImportDialogView.unit.test.jsx | 70 ++++++++- 3 files changed, 227 insertions(+), 25 deletions(-) diff --git a/src/components/modules/workout/WorkoutImport/WorkoutImportDialogView.jsx b/src/components/modules/workout/WorkoutImport/WorkoutImportDialogView.jsx index 19989f5..f31c448 100644 --- a/src/components/modules/workout/WorkoutImport/WorkoutImportDialogView.jsx +++ b/src/components/modules/workout/WorkoutImport/WorkoutImportDialogView.jsx @@ -1,7 +1,7 @@ import React, { useCallback } from 'react' import styled from 'styled-components' -import { Button, ButtonBar, ErrorText } from '../../../atoms' -import { Dialog, Dropzone } from '../../../molecules' +import { Button, ButtonBar, ErrorText, ImportIcon, Loader } from '../../../atoms' +import { Dialog, Dropzone, WorkoutGraph } from '../../../molecules' import { WorkoutCategorySelect } from '../selection/WorkoutCategorySelect' // Same fixed box as the Import Routes dialog: one box for every phase, only the content changes @@ -17,7 +17,7 @@ export const WORKOUT_IMPORT_FILTERS = [ const TITLES = { landing: 'Import Workout', importing: 'Importing...', - result: 'Import Result', + result: 'Import Successful', error: 'Import Failed', } @@ -53,6 +53,11 @@ const TileContent = styled.div` text-align: center; ` +const SUCCESS_COLOR = '#4CAF50' +const ERROR_COLOR = '#D32F2F' +const DEFAULT_GROUP = 'My Workouts' + +// centred panel (importing, error, result without graph) const Body = styled.div` display: flex; flex-direction: column; @@ -60,18 +65,81 @@ const Body = styled.div` justify-content: center; height: calc(100% - 7.7vh); text-align: center; - padding: 2vh; + padding: 2vh 2vw; box-sizing: border-box; gap: 2vh; font-size: 2vh; ` -const SelectWrapper = styled.div` - width: 40ch; - max-width: 100%; +// result with graph: header, category, graph +const ResultBody = styled.div` + display: flex; + flex-direction: column; + height: calc(100% - 7.7vh); + padding: 2vh 2vw; + box-sizing: border-box; + font-size: 2vh; +` + +const HeaderRow = styled.div` + display: flex; + flex-direction: row; + align-items: center; + gap: 1.5vw; + margin-bottom: 1.5vh; + font-size: 2vh; + color: white; +` + +const CategoryRow = styled.div` + align-self: ${props => props.$center ? 'center' : 'flex-start'}; + margin-bottom: 1vh; text-align: left; + + /* keep the selected value readable regardless of the colour inherited from the dialog */ + select, option { + color: #000; + background-color: #fff; + } +` + +const GraphArea = styled.div` + flex: 1; + width: 100%; + min-height: 20vh; ` +const StatusCircle = styled.div` + flex: none; + display: flex; + align-items: center; + justify-content: center; + box-sizing: border-box; + width: ${props => props.$large ? '12vh' : '6vh'}; + height: ${props => props.$large ? '12vh' : '6vh'}; + border: ${props => props.$large ? '0.6vh' : '0.4vh'} solid ${props => props.$color}; + border-radius: 50%; + color: ${props => props.$color}; + font-weight: bold; + font-size: ${props => props.$large ? '7vh' : '3.5vh'}; + line-height: 1; +` + +const StatusText = styled.div` + font-size: 2vh; + color: white; +` + +const SuccessCircle = ({ large }) => ( + + + +) + +const ErrorCircle = () => ( + ! +) + const Landing = ({ onFiles }) => { const onDrop = useCallback((dropInfo) => { const files = (Array.isArray(dropInfo) ? dropInfo : [dropInfo]).filter(Boolean) @@ -101,30 +169,70 @@ const Landing = ({ onFiles }) => { const Importing = ({ fileName, onCancel }) => ( <> - {fileName} + + + {`Importing ${fileName ?? ''}…`} +