@@ -11,6 +11,10 @@ import {
1111 FloorCheckpointsGraph ,
1212 IndoorNavigationPath ,
1313} from "@/types/mapTypes" ;
14+ import {
15+ createFloorNavigationCommandSet ,
16+ createStepNavigationCommandSet ,
17+ } from "@/utils/indoorNavigationCommands" ;
1418import { findIndoorPath } from "@/utils/indoorNavigation" ;
1519import { describeIndoorStep } from "@/utils/indoorStepInstructions" ;
1620import {
@@ -215,52 +219,105 @@ export default function IndoorMap() {
215219 } , [ endRoom , startRoom , validEndRoom , validStartRoom ] ) ;
216220
217221 type NavigationDirection = "next" | "prev" ;
218- const handleFloorNavigation = ( direction : NavigationDirection ) => {
219- if ( currentFloorIndex < 0 ) {
220- return ;
221- }
222- const delta = direction === "next" ? 1 : - 1 ;
223- const newFloorIndex = Math . min (
224- Math . max ( currentFloorIndex + delta , 0 ) ,
225- availableFloors . length - 1 ,
226- ) ;
227- setFloor ( availableFloors [ newFloorIndex ] ) ;
228- } ;
229- const handleStepNavigation = ( direction : NavigationDirection ) => {
230- if ( ! hasStepNavigation || ! navigationPath || ! floorInfo ) {
231- return ;
232- }
222+ const handleFloorNavigation = useCallback (
223+ ( direction : NavigationDirection ) => {
224+ if ( currentFloorIndex < 0 ) {
225+ return ;
226+ }
227+ const delta = direction === "next" ? 1 : - 1 ;
228+ const newFloorIndex = Math . min (
229+ Math . max ( currentFloorIndex + delta , 0 ) ,
230+ availableFloors . length - 1 ,
231+ ) ;
232+ setFloor ( availableFloors [ newFloorIndex ] ) ;
233+ } ,
234+ [ availableFloors , currentFloorIndex ] ,
235+ ) ;
236+ const handleStepNavigation = useCallback (
237+ ( direction : NavigationDirection ) => {
238+ if ( ! hasStepNavigation || ! navigationPath || ! floorInfo ) {
239+ return ;
240+ }
233241
234- if ( direction === "next" && isOnLastIndoorStep ) {
235- if ( outdoorStepResume ) {
236- OutdoorStepResume . setPendingStep ( outdoorStepResume ) ;
237- if ( autoResumeContinuationId ) {
238- OutdoorStepResume . clearContinuation ( autoResumeContinuationId ) ;
242+ if ( direction === "next" && isOnLastIndoorStep ) {
243+ if ( outdoorStepResume ) {
244+ OutdoorStepResume . setPendingStep ( outdoorStepResume ) ;
245+ if ( autoResumeContinuationId ) {
246+ OutdoorStepResume . clearContinuation ( autoResumeContinuationId ) ;
247+ }
248+ router . back ( ) ;
239249 }
240- router . back ( ) ;
250+ return ;
241251 }
242- return ;
243- }
244252
245- const delta = direction === "next" ? 1 : - 1 ;
246- const nextStepPointer = Math . min (
247- Math . max ( boundedStepPointer + delta , 0 ) ,
248- totalPathSteps - 1 ,
249- ) ;
250- if ( nextStepPointer === boundedStepPointer ) {
251- return ;
252- }
253+ const delta = direction === "next" ? 1 : - 1 ;
254+ const nextStepPointer = Math . min (
255+ Math . max ( boundedStepPointer + delta , 0 ) ,
256+ totalPathSteps - 1 ,
257+ ) ;
258+ if ( nextStepPointer === boundedStepPointer ) {
259+ return ;
260+ }
253261
254- const nextPathIndex = stepStopIndices [ nextStepPointer ] ;
255- const nextStepCheckpoint =
256- floorInfo . graphData . checkpoints [ navigationPath [ nextPathIndex ] ] ;
257- if ( ! nextStepCheckpoint ) {
258- return ;
262+ const nextPathIndex = stepStopIndices [ nextStepPointer ] ;
263+ const nextStepCheckpoint =
264+ floorInfo . graphData . checkpoints [ navigationPath [ nextPathIndex ] ] ;
265+ if ( ! nextStepCheckpoint ) {
266+ return ;
267+ }
268+
269+ setCurrentPathStepIndex ( nextStepPointer ) ;
270+ setFloor ( nextStepCheckpoint . floor ) ;
271+ } ,
272+ [
273+ autoResumeContinuationId ,
274+ boundedStepPointer ,
275+ floorInfo ,
276+ hasStepNavigation ,
277+ isOnLastIndoorStep ,
278+ navigationPath ,
279+ outdoorStepResume ,
280+ stepStopIndices ,
281+ totalPathSteps ,
282+ ] ,
283+ ) ;
284+ const navigationControls = useMemo ( ( ) => {
285+ const currentFloor = defaultFloor ?? firstFloor ?? 0 ;
286+
287+ if ( hasStepNavigation ) {
288+ return createStepNavigationCommandSet ( {
289+ currentFloor,
290+ currentStep : boundedStepPointer + 1 ,
291+ totalSteps : Math . max ( totalPathSteps , 1 ) ,
292+ stepInstruction : currentStepInstruction ,
293+ canGoNext : canGoNextStep ,
294+ canGoPrevious : canGoPreviousStep ,
295+ onNext : ( ) => handleStepNavigation ( "next" ) ,
296+ onPrevious : ( ) => handleStepNavigation ( "prev" ) ,
297+ } ) ;
259298 }
260299
261- setCurrentPathStepIndex ( nextStepPointer ) ;
262- setFloor ( nextStepCheckpoint . floor ) ;
263- } ;
300+ return createFloorNavigationCommandSet ( {
301+ currentFloor,
302+ canGoNext : canGoNextFloor ,
303+ canGoPrevious : canGoPreviousFloor ,
304+ onNext : ( ) => handleFloorNavigation ( "next" ) ,
305+ onPrevious : ( ) => handleFloorNavigation ( "prev" ) ,
306+ } ) ;
307+ } , [
308+ boundedStepPointer ,
309+ canGoNextFloor ,
310+ canGoNextStep ,
311+ canGoPreviousFloor ,
312+ canGoPreviousStep ,
313+ currentStepInstruction ,
314+ defaultFloor ,
315+ firstFloor ,
316+ handleFloorNavigation ,
317+ handleStepNavigation ,
318+ hasStepNavigation ,
319+ totalPathSteps ,
320+ ] ) ;
264321
265322 const createPathFromRooms = useCallback ( ( ) => {
266323 setHasCheckpointDrivenRoute ( false ) ;
@@ -648,29 +705,7 @@ export default function IndoorMap() {
648705 poiFilters = { poiFilters }
649706 setPoiFilters = { setPoiFilters }
650707 />
651- < IndoorNavigationControls
652- onNext = { ( ) => {
653- if ( hasStepNavigation ) {
654- handleStepNavigation ( "next" ) ;
655- return ;
656- }
657- handleFloorNavigation ( "next" ) ;
658- } }
659- onPrevious = { ( ) => {
660- if ( hasStepNavigation ) {
661- handleStepNavigation ( "prev" ) ;
662- return ;
663- }
664- handleFloorNavigation ( "prev" ) ;
665- } }
666- currentFloor = { defaultFloor }
667- canGoNext = { hasStepNavigation ? canGoNextStep : canGoNextFloor }
668- canGoPrevious = { hasStepNavigation ? canGoPreviousStep : canGoPreviousFloor }
669- mode = { hasStepNavigation ? "step" : "floor" }
670- currentStep = { boundedStepPointer + 1 }
671- totalSteps = { Math . max ( totalPathSteps , 1 ) }
672- stepInstruction = { currentStepInstruction }
673- />
708+ < IndoorNavigationControls { ...navigationControls } />
674709 < BuildingFloor
675710 info = { floorInfo }
676711 poiFilters = { poiFilters }
0 commit comments