mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-28 07:30:04 +00:00
fix(mobile): read the stop being moved as it is now, so a change by a collaborator is not lost
The move list keeps only the stop's id and looks up its current day on every tap, and closes once the stop is gone from the place.
This commit is contained in:
@@ -62,7 +62,8 @@ export default function MPlaceSheet({ planner, shell }: MTripSheetsProps) {
|
||||
} = usePlaceFileUpload(place && !isTourPlace ? place.id : null, fd => planner.tripActions.addFile(planner.tripId, fd), planner.toast)
|
||||
const [dayPickerOpen, setDayPickerOpen] = useState(false)
|
||||
// A day of this place picked to move from (#2583): the day list then moves it there instead of adding it.
|
||||
const [moving, setMoving] = useState<{ assignment: Assignment; fromDayId: number } | null>(null)
|
||||
// Only the ids are kept, so a stop a collaborator moved or removed meanwhile is read as it is now.
|
||||
const [movingIds, setMovingIds] = useState<{ placeId: number; assignmentId: number } | null>(null)
|
||||
const [participantPickerOpen, setParticipantPickerOpen] = useState(false)
|
||||
const [navOpen, setNavOpen] = useState(false)
|
||||
const navBtnRef = useRef<HTMLButtonElement>(null)
|
||||
@@ -72,7 +73,7 @@ export default function MPlaceSheet({ planner, shell }: MTripSheetsProps) {
|
||||
planner.setSelectedPlaceId(null)
|
||||
setFilesExpanded(false)
|
||||
setDayPickerOpen(false)
|
||||
setMoving(null)
|
||||
setMovingIds(null)
|
||||
setParticipantPickerOpen(false)
|
||||
setColorPickerOpen(false)
|
||||
}
|
||||
@@ -94,13 +95,18 @@ export default function MPlaceSheet({ planner, shell }: MTripSheetsProps) {
|
||||
return rows
|
||||
}, [place, planner.days, planner.assignments])
|
||||
|
||||
const moving = movingIds && movingIds.placeId === place?.id
|
||||
? placeAssignments.find(r => r.assignment.id === movingIds.assignmentId) ?? null
|
||||
: null
|
||||
if (movingIds && !moving) setMovingIds(null)
|
||||
|
||||
const unassignedDays = planner.days.filter(d => !placeAssignments.some(r => r.day.id === d.id))
|
||||
const dayLabel = (d: Day) => d.title || t('planner.dayN', { n: (d.day_number ?? planner.days.indexOf(d) + 1) || '?' })
|
||||
// Lands where its time belongs on the new day, as a move on the desktop does;
|
||||
// without a time it goes to the end.
|
||||
const moveToDay = ({ assignment, fromDayId }: { assignment: Assignment; fromDayId: number }, toDayId: number) => {
|
||||
const moveToDay = ({ assignment, day }: { assignment: Assignment; day: Day }, toDayId: number) => {
|
||||
const slot = timedSlot(planner.storedAssignments[String(toDayId)] || [], planner.tripAccommodations, assignment.place?.place_time) ?? undefined
|
||||
planner.handleMoveToDay(assignment.id, fromDayId, toDayId, slot)
|
||||
planner.handleMoveToDay(assignment.id, day.id, toDayId, slot)
|
||||
.catch((err: unknown) => planner.toast.error(err instanceof Error ? err.message : t('common.unknownError')))
|
||||
}
|
||||
|
||||
@@ -364,7 +370,7 @@ export default function MPlaceSheet({ planner, shell }: MTripSheetsProps) {
|
||||
// and notes, where removing and adding it again would lose them.
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => { setDayPickerOpen(false); setMoving(m => (m?.assignment.id === assignment.id ? null : { assignment, fromDayId: day.id })) }}
|
||||
onClick={() => { setDayPickerOpen(false); setMovingIds(moving?.assignment.id === assignment.id ? null : { placeId: place.id, assignmentId: assignment.id }) }}
|
||||
aria-label={t('mobileTrip.moveToDay')}
|
||||
aria-expanded={moving?.assignment.id === assignment.id}
|
||||
className="flex items-center gap-1"
|
||||
@@ -400,7 +406,7 @@ export default function MPlaceSheet({ planner, shell }: MTripSheetsProps) {
|
||||
{canEditDays && unassignedDays.length > 0 && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => { setMoving(null); setDayPickerOpen(v => !v) }}
|
||||
onClick={() => { setMovingIds(null); setDayPickerOpen(v => !v) }}
|
||||
aria-label={t('inspector.addToDay')}
|
||||
aria-expanded={dayPickerOpen}
|
||||
className="flex h-[26px] w-[26px] items-center justify-center rounded-full border-[1.5px] border-dashed border-[color:var(--m-faint)] text-m-muted"
|
||||
@@ -420,7 +426,7 @@ export default function MPlaceSheet({ planner, shell }: MTripSheetsProps) {
|
||||
if (moving) moveToDay(moving, d.id)
|
||||
else planner.handleAssignToDay(place.id, d.id)
|
||||
setDayPickerOpen(false)
|
||||
setMoving(null)
|
||||
setMovingIds(null)
|
||||
}}
|
||||
className="flex w-full items-center gap-2 rounded-[10px] px-[10px] py-[9px] text-start text-[0.78125rem] font-semibold"
|
||||
>
|
||||
|
||||
@@ -13,7 +13,7 @@ import type { Assignment, Category, Day, Place, TripFile, TripMember } from '../
|
||||
import { resetAllStores, seedStore } from '../../../helpers/store'
|
||||
import { act, fireEvent, render, screen, waitFor } from '../../../helpers/render'
|
||||
|
||||
// FE-MOB-PLSH-001 to FE-MOB-PLSH-036
|
||||
// FE-MOB-PLSH-001 to FE-MOB-PLSH-037
|
||||
|
||||
vi.mock('../../../../src/utils/fileDownload', () => ({ openFile: vi.fn() }))
|
||||
// The gallery says "no pictures" through the shared toast, the sheet's own writes through planner.toast.
|
||||
@@ -287,6 +287,24 @@ describe('MPlaceSheet', () => {
|
||||
expect(handleMoveToDay).toHaveBeenCalledWith(11, 2, 3, 2)
|
||||
})
|
||||
|
||||
it('FE-MOB-PLSH-037: the move list follows a stop a collaborator moved meanwhile, and closes when it is gone', () => {
|
||||
const handleMoveToDay = vi.fn().mockResolvedValue(undefined)
|
||||
const planner = makePlanner({ handleMoveToDay, tripAccommodations: [] })
|
||||
const { rerender } = renderSheet(planner)
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Move to another day' }))
|
||||
const moved = { ...planner, assignments: { '3': [dayAssignment(11, 3)] }, storedAssignments: { '3': [dayAssignment(11, 3)] } } as unknown as TripPlanner
|
||||
rerender(<MPlaceSheet planner={moved} shell={makeShell()} />)
|
||||
expect(screen.getByRole('button', { name: 'Move to another day' })).toHaveAttribute('aria-expanded', 'true')
|
||||
fireEvent.click(screen.getByText('Old Town'))
|
||||
expect(handleMoveToDay).toHaveBeenCalledWith(11, 3, 2, undefined)
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Move to another day' }))
|
||||
const removed = { ...moved, assignments: {}, storedAssignments: {} } as unknown as TripPlanner
|
||||
rerender(<MPlaceSheet planner={removed} shell={makeShell()} />)
|
||||
rerender(<MPlaceSheet planner={moved} shell={makeShell()} />)
|
||||
expect(screen.getByRole('button', { name: 'Move to another day' })).toHaveAttribute('aria-expanded', 'false')
|
||||
})
|
||||
|
||||
it('FE-MOB-PLSH-011: treats an assignment without participants as everyone joined', async () => {
|
||||
vi.spyOn(assignmentsApi, 'setParticipants').mockResolvedValue({ participants: [{ user_id: 2, username: 'bob' }] })
|
||||
renderSheet()
|
||||
|
||||
Reference in New Issue
Block a user