Skip to content

Commit 91d714d

Browse files
authored
MN-427 : Created PhotoCaptureHUDAddDamagePreview component (#664)
* PhotoCaptureHUDAddDamagePreview component * fixing PR
1 parent 97914b2 commit 91d714d

File tree

29 files changed

+660
-77
lines changed

29 files changed

+660
-77
lines changed

apps/monk-test-app/src/views/App.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import { i18nCamera } from '@monkvision/camera-web';
22
import { useI18nLink } from '@monkvision/common';
33
import React from 'react';
44
import { useTranslation } from 'react-i18next';
5-
import { CameraView } from './CameraView';
6-
// import { TestView } from './TestView';
5+
// import { CameraView } from './CameraView';
6+
import { TestView } from './TestView';
77

88
export function App() {
99
const { i18n } = useTranslation();
1010
useI18nLink(i18n, [i18nCamera]);
1111

12-
return <CameraView />;
12+
return <TestView />;
1313
}
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import React from 'react';
22
import './TestView.css';
3-
import { CaptureHUDButtons } from '@monkvision/inspection-capture-web';
3+
import { PhotoCapture } from '@monkvision/inspection-capture-web';
4+
import { sights } from '@monkvision/sights';
45

6+
const sightsArray = Object.values(sights)
7+
.filter((value) => value.category === 'exterior')
8+
.slice(0, 5);
59
export function TestView() {
610
return (
711
<div className='test-view-container'>
8-
<CaptureHUDButtons />
12+
<PhotoCapture sights={sightsArray} />
913
</div>
1014
);
1115
}

packages/public/inspection-capture-web/src/PhotoCapture/PhotoCapture.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ export const PhotoCapture = i18nWrap(({ sights }: PhotoCaptureProps) => {
2626
});
2727
const hud = (props: CameraHUDProps) => <PhotoCaptureHUD sights={sights} {...props} />;
2828

29+
const handleTakePicture = (picture: MonkPicture) => {
30+
console.log('Picture Taken :', picture);
31+
};
32+
2933
return (
3034
<div style={styles['container']}>
3135
<Camera
@@ -34,7 +38,7 @@ export const PhotoCapture = i18nWrap(({ sights }: PhotoCaptureProps) => {
3438
resolution={cameraState.resolution}
3539
format={cameraState.compressionFormat}
3640
quality={Number(cameraState.quality)}
37-
onPictureTaken={(picture: MonkPicture) => console.log('Picture Taken :', picture)}
41+
onPictureTaken={handleTakePicture}
3842
/>
3943
</div>
4044
);

packages/public/inspection-capture-web/src/PhotoCapture/PhotoCaptureHUD.tsx

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,61 @@
1-
import { useMemo, useState } from 'react';
1+
import { useMemo } from 'react';
22
import { Sight } from '@monkvision/types';
33
import { CameraHUDProps } from '@monkvision/camera-web/lib/Camera/CameraHUD.types';
44
import { PhotoCaptureHUDButtons } from './PhotoCaptureHUDButtons';
55
import { PhotoCaptureHUDAddDamagePreview } from './PhotoCaptureHUDAddDamagePreview';
66
import { PhotoCaptureHUDSightPreview } from './PhotoCaptureHUDSightPreview';
77
import { HUDMode, usePhotoCaptureHUDStyle } from './hook';
8-
import { useSightState } from './hooks';
8+
import { AddDamagePreviewMode, useSightState } from './hooks';
99

1010
export interface PhotoCaptureHUDProps extends CameraHUDProps {
1111
sights: Sight[];
1212
}
1313

14+
/**
15+
* Displays the camera preview and HUD components for capturing photos with sights.
16+
*
17+
* @component
18+
*
19+
* @param {Sight[]} sights - The array of sights available for selection.
20+
*
21+
* @example
22+
* // Example usage of PhotoCaptureHUD component in Camera Component:
23+
* import { Camera } from '@monkvision/camera-web';
24+
* import { PhotoCaptureHUD } from '@monkvision/inspection-camera-web';
25+
*
26+
* export Function MyComponent () {
27+
* const [sights, setSights] = useState<sights[]>([]);
28+
* const hud = (props: CameraHUDProps) => <PhotoCaptureHUD sights={sights} {...props} />;
29+
*
30+
* return (
31+
* <Camera HUDComponent={hud} ...props />
32+
* );
33+
*/
1434
export function PhotoCaptureHUD({ sights, cameraPreview, handle }: PhotoCaptureHUDProps) {
15-
const [mode, setMode] = useState<HUDMode>(HUDMode.DEFAULT);
16-
const { selectedSight, setSelectedSight, sightsTaken, handleSightTaken } = useSightState(sights);
35+
const {
36+
selectedSight,
37+
setSelectedSight,
38+
sightsTaken,
39+
handleSightTaken,
40+
mode,
41+
setMode,
42+
addDamagePreviewMode,
43+
setAddDamagePreviewMode,
44+
} = useSightState(sights);
1745
const style = usePhotoCaptureHUDStyle();
1846

1947
const hudPreview = useMemo(
2048
() =>
2149
mode === HUDMode.ADD_DAMAGE ? (
22-
<PhotoCaptureHUDAddDamagePreview onCancel={() => setMode(HUDMode.DEFAULT)} />
50+
<PhotoCaptureHUDAddDamagePreview
51+
onCancel={() => {
52+
setMode(HUDMode.DEFAULT);
53+
setAddDamagePreviewMode(AddDamagePreviewMode.DEFAULT);
54+
}}
55+
sight={selectedSight}
56+
addDamagePreviewMode={addDamagePreviewMode}
57+
streamDimensions={handle?.dimensions}
58+
/>
2359
) : (
2460
<PhotoCaptureHUDSightPreview
2561
sights={sights}
@@ -30,7 +66,7 @@ export function PhotoCaptureHUD({ sights, cameraPreview, handle }: PhotoCaptureH
3066
streamDimensions={handle?.dimensions}
3167
/>
3268
),
33-
[mode, selectedSight, sightsTaken, handle?.dimensions],
69+
[mode, selectedSight, sightsTaken, handle?.dimensions, addDamagePreviewMode],
3470
);
3571
return (
3672
<div style={style.container}>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Button } from '@monkvision/common-ui-web';
2+
import { useTranslation } from 'react-i18next';
3+
import { usePhotoHUDButtonBackground } from '../../hooks';
4+
5+
export interface CancelButtonProps {
6+
onCancel: () => void;
7+
}
8+
9+
export function CancelButton({ onCancel }: CancelButtonProps) {
10+
const { t } = useTranslation();
11+
const { bgColor } = usePhotoHUDButtonBackground();
12+
13+
return (
14+
<Button onClick={onCancel} style={{ backgroundColor: bgColor }}>
15+
{t('photo.hud.addDamage.cancelBtn')}
16+
</Button>
17+
);
18+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './CancelButton';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { Styles } from '@monkvision/types';
2+
3+
export const styles: Styles = {
4+
container: {
5+
position: 'absolute',
6+
display: 'flex',
7+
justifyContent: 'center',
8+
alignItems: 'center',
9+
flexDirection: 'column',
10+
top: '0',
11+
right: '0',
12+
left: '0',
13+
bottom: '0',
14+
},
15+
top: {
16+
position: 'absolute',
17+
display: 'flex',
18+
alignSelf: 'stretch',
19+
flexDirection: 'row',
20+
justifyContent: 'space-between',
21+
margin: '10px',
22+
zIndex: '9',
23+
top: '0',
24+
right: '0',
25+
left: '0',
26+
},
27+
frameContainer: {
28+
position: 'absolute',
29+
width: '100%',
30+
},
31+
frame: {
32+
position: 'absolute',
33+
top: '25%',
34+
left: '32%',
35+
width: '36%',
36+
height: '50%',
37+
border: '2px solid #FFC000',
38+
borderRadius: '10px',
39+
boxShadow: '0px 0px 0px 100pc rgba(0, 0, 0, 0.5)',
40+
},
41+
label: {
42+
position: 'absolute',
43+
top: '0',
44+
color: 'white',
45+
margin: '20px',
46+
padding: '10px 24px',
47+
},
48+
labelPortrait: {
49+
__media: { portrait: true },
50+
top: '10%',
51+
},
52+
infoCloseup: {
53+
position: 'absolute',
54+
bottom: '0',
55+
color: 'white',
56+
margin: '20px',
57+
padding: '10px 24px',
58+
textAlign: 'center',
59+
},
60+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { PixelDimensions, Sight } from '@monkvision/types';
2+
import { useTranslation } from 'react-i18next';
3+
import { useSightLabel } from '@monkvision/common';
4+
import { labels } from '@monkvision/sights';
5+
import { styles } from './CloseupPreview.styles';
6+
import { CancelButton } from '../CancelButton';
7+
import { DamageCounter } from '../DamageCounter';
8+
import { useCloseupPreviewStyle } from './hook';
9+
import { AddDamagePreviewMode } from '../../hooks';
10+
11+
export interface CloseupPreviewProps {
12+
sight?: Sight | undefined;
13+
onCancel: () => void;
14+
streamDimensions?: PixelDimensions | null;
15+
}
16+
17+
export function CloseupPreview({ sight, onCancel, streamDimensions }: CloseupPreviewProps) {
18+
const { t } = useTranslation();
19+
const { label } = useSightLabel({ labels });
20+
const style = useCloseupPreviewStyle();
21+
22+
const sightLabel = sight && label(sight);
23+
const aspectRatio = streamDimensions
24+
? `${streamDimensions?.width}/${streamDimensions?.height}`
25+
: '16/9';
26+
27+
return (
28+
<div style={styles['container']}>
29+
<div style={{ ...styles['frameContainer'], aspectRatio }} data-testid='frame-container'>
30+
<div style={styles['frame']} />
31+
</div>
32+
<div style={styles['top']}>
33+
<DamageCounter addDamagePreviewMode={AddDamagePreviewMode.CLOSEUP_PREVIEW} />
34+
<CancelButton onCancel={onCancel} />
35+
</div>
36+
<div style={style.label} data-testid='sight-label'>
37+
{sightLabel}
38+
</div>
39+
<div style={styles['infoCloseup']}>{t('photo.hud.addDamage.infoCloseup')}</div>
40+
</div>
41+
);
42+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { useResponsiveStyle } from '@monkvision/common';
2+
import { styles } from './CloseupPreview.styles';
3+
4+
export function useCloseupPreviewStyle() {
5+
const { responsive } = useResponsiveStyle();
6+
return {
7+
label: {
8+
...styles['label'],
9+
...responsive(styles['labelPortrait']),
10+
},
11+
};
12+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './CloseupPreview';

0 commit comments

Comments
 (0)