Skip to content

Allow vehicle walkaround in both directions#990

Open
gabrieltmonkai wants to merge 6 commits intomainfrom
feat/MN-834/compass-in-both-directions
Open

Allow vehicle walkaround in both directions#990
gabrieltmonkai wants to merge 6 commits intomainfrom
feat/MN-834/compass-in-both-directions

Conversation

@gabrieltmonkai
Copy link
Copy Markdown
Contributor

@gabrieltmonkai gabrieltmonkai commented Mar 27, 2026

Overview

Jira Ticket Reference : MN-834

Implemented vehicle walkaround support in both directions based on segments

Checklist before requesting a review

  • I have updated the unit tests based on the changes I made
  • I have updated the docs (TSDoc / README / global doc) to reflect my changes
  • I have updated the local app configs if needed
  • I have performed self-QA of my feature by testing the apps and packages and made sure that :
    • No regression or new bug has occurred
    • The acceptance criteria listed in the ticket are met
    • Self-QA was made on both desktop and mobile

Comment on lines +55 to +60
/**
* Array of covered segments to display on the indicator.
* If provided, multiple progress bars will be rendered for each segment.
* If not provided, falls back to showing a single progress bar from 0 to alpha.
*/
coveredSegments?: CoveredSegment[];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: What's the purpose of having multiple segments?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If not necessary, we probably could simplify this by: start?: number

const smoothedAlphaRef = useRef<number | null>(null);
const justStartedRef = useRef<boolean>(false);

const smoothedAlpha = useMemo(() => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can get rid of useMemo for low/medium computation (handled by react 19 compiler)

const [startingAlpha, setStartingAlpha] = useState<number | null>(null);
const [checkpoint, setCheckpoint] = useState(45);
const [nextCheckpoint, setNextCheckpoint] = useState(90);
const coveredSegmentsRef = useRef<Set<number>>(new Set());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why reference is needed in this component?

coveredSegments: CoveredSegment[];
}

const DEGREE_GRANULARITY = 5;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move this to the top of the file, right after the imports? By convention, constants should be declared at the beginning.

* - 180: POV is behind the back of the car
*/
alpha: number;
walkaroundPosition: number;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This prop rename could be a breaking change for our clients, so we should keep the current name.

Comment on lines 54 to +61
*/
showProgressBar?: boolean;
/**
* Boolean indicating if segment tracking is active.
* When true, the component will track and display covered segments.
*
* @default false
*/
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not sure about the isTracking prop. Could you use showProgressBar instead?

coveragePercentage: number;
}

const DEGREE_GRANULARITY = 5;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This value is declared twice in VideoCapture and VehicleWalkaroundIndicator. Could you share this value somewhere ? Is DEGREE_GRANULARITY really necessary?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I've left it in useVehicleWalkaroundIndicatorState and exported it.

It's necessary because useVehicleWalkaround displays the visual indicator of coverage and VehicleWalkaroundIndicator tracks the actual position and calculates which segments are covered.

If they use different granularity values, the visual display would be incorrect.

Comment on lines +38 to +40
function normalizeAngle(angle: number): number {
const normalized = angle % 360;
return normalized < 0 ? normalized + 360 : normalized;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is the same function in VehicleWalkaroundIndicator, could you move this function in the common package then import it here?

Comment on lines +65 to +66
const smoothedAlphaRef = useRef<number | null>(null);
const prevStartingAlphaRef = useRef<number | null>(null);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not sure about the purpose of all these refs. Why do we need a ref for alpha? We already have the startingAlpha state.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good question, I tried to get rid of them, but couldn't figure out another way to solve those 2 out of 10 cases when at the beginning of video recording, the alpha started offset or coveredSegments was 2 or 3 already.

We're using prevStartingAlphaRef to know whether or not we've had previous covered segments. It's the rare case when at resume or retaking the video after discard, we would have the alpha slightly offset, plus a couple of segments already covered.

Even though we reset the alpha, this is extra safety to do a "hard reset" if the user will fall in those 2 out of 10 cases when alpha starts offset.

For the other refs, this is just a non-rendering pattern when we want to do calculations that reflect in real-time, without triggering a render, but while the hook is heavy triggered by the nature of often the alpha updates once the phone is moving.

They are more specific to the beginning of the video tracking after resume or discard video, to prevent those 2 issues:

  • alpha starting offset
  • coveredSegments starting with a value between 2-4 by default

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I’m not a fan of using these four refs. It feels like an anti-pattern.

If the alpha is offset or segments are covered, it means something isn’t working properly in the code. This hook likely needs a full rework.

@@ -32,34 +61,94 @@ export function useVehicleWalkaround({
alpha,
}: UseVehicleWalkaroundParams): VehicleWalkaroundHandle {
const [startingAlpha, setStartingAlpha] = useState<number | null>(null);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about having this state updated if the alpha go through the startingalpha in the opposite side (walking back).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about the direction, do you point towards tracking the covered segments to the left/right based on startingAlpha?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this will be updated if alpha is going clockwise.

@@ -32,34 +61,94 @@ export function useVehicleWalkaround({
alpha,
}: UseVehicleWalkaroundParams): VehicleWalkaroundHandle {
const [startingAlpha, setStartingAlpha] = useState<number | null>(null);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about having this state updated if the alpha go through the startingalpha in the opposite side (walking back).

@gabrieltmonkai gabrieltmonkai force-pushed the feat/MN-834/compass-in-both-directions branch from 5206f08 to dc310f0 Compare April 30, 2026 08:34
* Granularity (in degrees) used for dividing the 360-degree circle into segments for vehicle walkaround tracking.
* This constant determines the precision of position tracking during vehicle inspections.
*/
export const DEGREE_GRANULARITY = 5;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This constant is defined in common-ui-web but imported in inspection-capture-web. This creates an inverted dependency, it should not depend on UI packages.

Is this const really necessary? The original implementation had not granularity.

If really needed, it should be passed as a prop to the component

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants