Skip to content

Commit 97914b2

Browse files
authored
MN-430: PhotoHUDPreview with SightsSlider + Counter (#648)
* Added ObjectTranlation type * Added useObjectTranslation hook * Renamed CaptureCaptureHUDButtons to PhotoCaptureHUDButtons * Added PhotoCaptureHUDSightsSlider component: display a scrolling sights label * Added PhotoCaptureHUDCounter component * Added PhotoCaptureHUDPreview component that render SightsSlider and Counter * Added PhotoCaptureHUD that render the HUDPreview and HUDButtons * Fix: lint * fix: applying feedback review, Sights liftup in PhotoCaptureHUD * rename Slider to SightsSlider * useObjectTranslation/CaptureHUDPreviewtests added + fix * directory structure changed by PreviewSight and PreviewAddDamage view directory structure changed to be more clear with PreviewSight and PreviewAddDamage view * TSDoc added to i18n language types * fix on tests and import * useSightLabel's hook moved to @monkvision/common + SightSlider component styles sight.id: string instead of sight:Sight * SightsSlider tests done * sight overlay now take all preview screen space * sight centered in slider when selected * responsive style added when portrait view * when the picture is taken, the sight button(in the slider) changed to a light color and have a check icon * TSDoc useSightLabel * keep sight button selected in the center when switching back to main preview * TSDoc useObjectTranslation & useSightLabel hooks * fixing PR review comments * PhotoCapture logic and component plug to camera. refacto + rename funct/var * renaming component for more readability + callback mode (avoiding rerender camera) + button in AddDamagePreview traduction in sync * tests + i18nAddDamage instance moved to separate file * SightOverlay stays in CameraPreview frame in both landscape and portrait mode. * SightOverlay equals CameraPreview in aspect ratio * fixing PR (check comments) * fixing PR (check comments) * Created SwitchButton component (#656) * import changeAlpha function in usePhotoHUDButtonBackground hook
1 parent 67fd360 commit 97914b2

File tree

59 files changed

+1176
-47
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1176
-47
lines changed

packages/private/test-utils/src/__mocks__/@monkvision/common.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,6 @@ export = {
7373
})),
7474
useResponsiveStyle: jest.fn(() => ({ responsive: jest.fn(() => null) })),
7575
useWindowDimensions: jest.fn(() => ({ width: 0, height: 0, isPortrait: false })),
76+
useObjectTranslation: jest.fn(() => ({ tObj: jest.fn(() => {}) })),
77+
useSightLabel: jest.fn(() => ({ label: jest.fn(() => {}) })),
7678
};

packages/private/test-utils/src/__mocks__/@monkvision/inspection-capture-web.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export = {
2+
/* Actual exports */
3+
/* Mocks */
4+
PhotoCaptureHUDButtons: jest.fn(() => <></>),
5+
PhotoCaptureHUDAddDamagePreview: jest.fn(() => <></>),
6+
PhotoCaptureHUDSightPreview: jest.fn(() => <></>),
7+
SightsCounter: jest.fn(() => <></>),
8+
AddDamageButton: jest.fn(() => <></>),
9+
SightsSlider: jest.fn(() => <></>),
10+
PhotoCaptureHUD: jest.fn(() => <></>),
11+
PhotoCapture: jest.fn(() => <></>),
12+
};

packages/private/test-utils/src/__mocks__/react-i18next.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ export = {
44
/* Mocks */
55
initReactI18next: {},
66
I18nextProvider: jest.fn(({ children }) => <>{children}</>),
7-
useTranslation: jest.fn(() => ({ t: jest.fn((str) => str) })),
7+
useTranslation: jest.fn(() => ({ t: jest.fn((str) => str), i18n: { language: 'en' } })),
88
};

packages/public/camera-web/src/Camera/Camera.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ export function Camera({
8787
);
8888

8989
return HUDComponent ? (
90-
<HUDComponent handle={{ takePicture, error, retry, isLoading }} cameraPreview={cameraPreview} />
90+
<HUDComponent
91+
handle={{ takePicture, error, retry, isLoading, dimensions }}
92+
cameraPreview={cameraPreview}
93+
/>
9194
) : (
9295
<>{cameraPreview}</>
9396
);

packages/public/camera-web/src/Camera/CameraHUD.types.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ComponentType, ReactElement } from 'react';
2+
import { PixelDimensions } from '@monkvision/types';
23
import { MonkPicture, UserMediaError } from './hooks';
34

45
/**
@@ -21,6 +22,11 @@ export interface CameraHandle {
2122
* A function to retry the camera stream fetching in case of error.
2223
*/
2324
retry: () => void;
25+
/**
26+
* The dimensions of the resulting camera stream. Note that these dimensions can differ from the ones given in the
27+
* stream constraints if they are not supported or available on the current device.
28+
*/
29+
dimensions: PixelDimensions | null;
2430
}
2531

2632
/**
@@ -40,7 +46,7 @@ export interface CameraEventHandlers {
4046
*/
4147
export interface CameraHUDProps {
4248
/**
43-
* The camera preview element. The HUD component is exepcted to take this element as a prop and display it however it
49+
* The camera preview element. The HUD component is expected to take this element as a prop and display it however it
4450
* wants to.
4551
*/
4652
cameraPreview: ReactElement;

packages/public/camera-web/test/Camera/Camera.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ describe('Camera component', () => {
201201
error: useCameraPreviewResultMock.error,
202202
retry: useCameraPreviewResultMock.retry,
203203
isLoading: useCameraPreviewResultMock.isLoading || useTakePictureResultMock.isLoading,
204+
dimensions: useCameraPreviewResultMock.dimensions,
204205
},
205206
cameraPreview: expect.anything(),
206207
});

packages/public/common/src/hooks/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ export * from './useWindowDimensions';
22
export * from './useResponsiveStyle';
33
export * from './useInteractiveStatus';
44
export * from './useQueue';
5+
export * from './useObjectTranslation';
6+
export * from './useSightLabel';
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { MonkLanguage, TranslationObject } from '@monkvision/types';
2+
import { useTranslation } from 'react-i18next';
3+
4+
/**
5+
* The result of the useObjectTranslation. It contains a function which takes a LabelTranslation object and return the
6+
* translated label sync with the actual selected language.
7+
*/
8+
export interface UseObjectTranslationResult {
9+
/**
10+
* Function translating a LabelTranslation object into a translated label sync with the actual selected language.
11+
*/
12+
tObj: (obj: TranslationObject) => string;
13+
}
14+
15+
/**
16+
* Custom hook used to get a translate function tObj that translates TranslationObjects.
17+
*/
18+
export function useObjectTranslation(): UseObjectTranslationResult {
19+
const { i18n } = useTranslation();
20+
const tObj = (obj: TranslationObject) => {
21+
const lang = i18n.language.slice(0, 2) as MonkLanguage;
22+
return obj[lang] ?? 'translation-not-found';
23+
};
24+
return { tObj };
25+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { LabelDictionary, Sight } from '@monkvision/types';
2+
import { useObjectTranslation } from './useObjectTranslation';
3+
4+
/**
5+
* The result of the useSightLabel. It contains a function which takes a Sight object and return the
6+
* translated label sync with the actual selected language.
7+
*/
8+
export interface UseSightLabelResult {
9+
label: (sight: Sight) => string;
10+
}
11+
12+
/**
13+
* Parameters given to the useSightLabel hook.
14+
*/
15+
export interface UseSightLabelParams {
16+
/**
17+
* A dictionary of label translations objects.
18+
*/
19+
labels: LabelDictionary;
20+
}
21+
22+
/**
23+
* Custom hook used to get the label of a sight with the actual selected language.
24+
*/
25+
export function useSightLabel({ labels }: UseSightLabelParams): UseSightLabelResult {
26+
const { tObj } = useObjectTranslation();
27+
return {
28+
label: (sight) => {
29+
const translationObject = labels[sight.label];
30+
return translationObject ? tObj(translationObject) : `translation-not-found[${sight.label}]`;
31+
},
32+
};
33+
}

0 commit comments

Comments
 (0)