-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContent.js
More file actions
143 lines (126 loc) · 4.19 KB
/
Content.js
File metadata and controls
143 lines (126 loc) · 4.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import React, { useState, useRef, useEffect } from 'react'
import ControlCameraIcon from '@material-ui/icons/ControlCamera';
import { JEELIZVTOWIDGET } from 'jeelizvtowidget'
import Button from '@material-ui/core/Button';
import searchImage from '../../Images/avatar.png'
import MuiAlert from '@material-ui/lab/Alert';
import LinearProgress from '@material-ui/core/LinearProgress';
import ExitToAppIcon from '@material-ui/icons/ExitToApp';
function init_VTOWidget(placeHolder, canvas, toggleLoading, onLoad){
JEELIZVTOWIDGET.start({
placeHolder,
canvas,
callbacks: {
ADJUST_START: null,
ADJUST_END: null,
LOADING_START: toggleLoading.bind(null, true),
LOADING_END: toggleLoading.bind(null, false)
},
sku: 'empty',
searchImageMask: searchImage, //',
searchImageColor: 0xeeeeee, // color of loading (face not found) animation
searchImageRotationSpeed: -0.001, // negative -> clockwise
callbackReady: function(){
onLoad();
},
onError: function(errorLabel){ // this function catches errors, so you can display custom integrated messages
alert('An error happened. errorLabel =' + errorLabel)
switch(errorLabel) {
case 'WEBCAM_UNAVAILABLE':
// the user has no camera, or does not want to share it.
break;
case 'INVALID_SKU':
// the provided SKU does not match with a glasses model
break;
case 'PLACEHOLDER_NULL_WIDTH':
case 'PLACEHOLDER_NULL_HEIGHT':
// Something is wrong with the placeholder
// (element whose id='JeelizVTOWidget')
break;
case 'FATAL':
default:
// a bit error happens:(
break;
} // end switch
} // end onError()
}) // end JEELIZVTOWIDGET.start call
}
function Content(props){
const { selectedSunglasses } = props;
const refPlaceHolder = useRef();
const refCanvas = useRef();
const [adjustMode, setAdjustMode] = useState(false);
const [isLoading, setIsLoading] = useState(true);
const toggleLoading = () => {
console.log('Ready for trying sunglasses')
}
const onLoad = () => {
setIsLoading(false);
}
const enter_adjustMode = () => {
setAdjustMode(true);
JEELIZVTOWIDGET.enter_adjustMode();
}
const exit_adjustMode = () => {
JEELIZVTOWIDGET.exit_adjustMode();
setAdjustMode(false);
}
const set_glassesModel = (sku) => {
JEELIZVTOWIDGET.load(sku);
}
useEffect(() => {
const placeHolder = refPlaceHolder.current;
const canvas = refCanvas.current;
init_VTOWidget(placeHolder, canvas, toggleLoading, onLoad);
return () => {
JEELIZVTOWIDGET.destroy();
}
}, []);
useEffect(() => {
if(!selectedSunglasses || isLoading)
return;
set_glassesModel(selectedSunglasses);
},[selectedSunglasses, isLoading]);
return (
<div>
{adjustMode && <div style={{marginTop: '70px', width: '60vw', marginLeft: '460px'}}>
<MuiAlert elevation={6} variant="filled" severity="info">
Move the glasses to adjust them.
</MuiAlert>
</div>}
<div ref={refPlaceHolder} className='JeelizVTOWidget' style={adjustMode?({ marginTop: '3vh'}):({marginTop: '20vh'})}>
<canvas ref={refCanvas} className='JeelizVTOWidgetCanvas'></canvas>
{ isLoading && <LinearProgress />}
</div>
{selectedSunglasses && !adjustMode && <div style={{textAlign: 'center'}}>
<br/>
<Button
variant="contained"
color="primary"
startIcon={<ControlCameraIcon />}
onClick={()=>{
enter_adjustMode();
}}
style={{marginLeft: '140px'}}
>
Adjust glasses
</Button>
</div>}
{selectedSunglasses && adjustMode && <div style={{textAlign: 'center'}}>
<br/>
<Button
variant="contained"
color="primary"
startIcon={<ExitToAppIcon />}
onClick={()=>{
exit_adjustMode();
}}
style={{marginLeft: '140px'}}
>
Exit adjust mode
</Button>
</div>}
</div>
)
}
export default Content