Allow vehicle walkaround in both directions#990
Conversation
| /** | ||
| * 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[]; |
There was a problem hiding this comment.
Question: What's the purpose of having multiple segments?
There was a problem hiding this comment.
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(() => { |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
Why reference is needed in this component?
| coveredSegments: CoveredSegment[]; | ||
| } | ||
|
|
||
| const DEGREE_GRANULARITY = 5; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
This prop rename could be a breaking change for our clients, so we should keep the current name.
| */ | ||
| showProgressBar?: boolean; | ||
| /** | ||
| * Boolean indicating if segment tracking is active. | ||
| * When true, the component will track and display covered segments. | ||
| * | ||
| * @default false | ||
| */ |
There was a problem hiding this comment.
I’m not sure about the isTracking prop. Could you use showProgressBar instead?
| coveragePercentage: number; | ||
| } | ||
|
|
||
| const DEGREE_GRANULARITY = 5; |
There was a problem hiding this comment.
This value is declared twice in VideoCapture and VehicleWalkaroundIndicator. Could you share this value somewhere ? Is DEGREE_GRANULARITY really necessary?
There was a problem hiding this comment.
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.
| function normalizeAngle(angle: number): number { | ||
| const normalized = angle % 360; | ||
| return normalized < 0 ? normalized + 360 : normalized; |
There was a problem hiding this comment.
There is the same function in VehicleWalkaroundIndicator, could you move this function in the common package then import it here?
| const smoothedAlphaRef = useRef<number | null>(null); | ||
| const prevStartingAlphaRef = useRef<number | null>(null); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
alphastarting offsetcoveredSegmentsstarting with a value between 2-4 by default
There was a problem hiding this comment.
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); | |||
There was a problem hiding this comment.
What do you think about having this state updated if the alpha go through the startingalpha in the opposite side (walking back).
There was a problem hiding this comment.
I'm not sure about the direction, do you point towards tracking the covered segments to the left/right based on startingAlpha?
There was a problem hiding this comment.
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); | |||
There was a problem hiding this comment.
What do you think about having this state updated if the alpha go through the startingalpha in the opposite side (walking back).
…ass before starting a video record
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
5206f08 to
dc310f0
Compare
| * 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; |
There was a problem hiding this comment.
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
Overview
Jira Ticket Reference : MN-834
Implemented vehicle walkaround support in both directions based on segments
Checklist before requesting a review