Skip to content

Commit c8c89d5

Browse files
whatsapp commit 3
1 parent eb84e63 commit c8c89d5

File tree

21 files changed

+988
-285
lines changed

21 files changed

+988
-285
lines changed
28.7 KB
Loading
663 KB
Binary file not shown.
44.2 KB
Loading
29.1 KB
Loading
10.7 KB
Loading
7.81 KB
Loading
69.1 KB
Loading

src/App.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ i[data-flip="true"] {
4747
transition: 400ms ease-in-out;
4848
}
4949

50-
.imageCont {
50+
.imageCont, .vidCont{
5151
position: relative;
5252
display: grid;
5353
place-items: center;

src/components/main.scss

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,59 @@ body{
144144
background: rgba(0, 0, 0, 0.25);
145145
}
146146
}
147+
148+
.vidCont {
149+
.react-video, video {
150+
height: 100%;
151+
}
152+
153+
.play-icon{
154+
position: absolute;
155+
width: 60px;
156+
height: 60px;
157+
background: rgba(0, 0, 0, 0.5);
158+
border-radius: 4em;
159+
color: var(--white);
160+
z-index: 1;
161+
opacity: 0;
162+
transition: all 200ms ease-in-out;
163+
}
164+
165+
&:hover .play-icon, .play-icon:hover{
166+
opacity: 1;
167+
}
168+
169+
.play-icon.opacity-100{
170+
opacity: 1;
171+
}
172+
}
173+
174+
.video-control-container{
175+
width: 100%;
176+
display: flex;
177+
align-items: center;
178+
179+
position: absolute;
180+
bottom: 0;
181+
182+
.video-progress{
183+
flex-grow: 1;
184+
margin: 0 0.8em;
185+
}
186+
187+
.MuiSlider-rail{
188+
background: var(--comp-txt);
189+
opacity: 0.8;
190+
}
191+
192+
.MuiSlider-track, .MuiSlider-thumb{
193+
opacity: 1;
194+
}
195+
196+
.prog-text{
197+
color: var(--comp-txt);
198+
font-size: 0.8em;
199+
font-weight: 500;
200+
padding: 0 0.5em;
201+
}
202+
}

src/components/utils.js

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import React, { useState, useEffect } from 'react';
22
import { useSelector, useDispatch } from 'react-redux';
33
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
4+
import ReactPlayer from 'react-player';
45

5-
import { dispatchAction } from 'store/actions';
6+
import Slider from '@mui/material/Slider';
67

8+
import { dispatchAction } from 'store/actions';
79
import * as FaIcons from '@fortawesome/free-solid-svg-icons';
810
import * as FaRegIcons from '@fortawesome/free-regular-svg-icons';
911
import * as MUIcons from '@mui/icons-material';
1012
import * as AllIcons from 'components/icons';
1113

14+
const {round, floor, random, min, max, abs} = Math;
15+
1216
export const MaterialIcon = (props) => {
1317
var icon = props.mui;
1418
if (props.out) icon += "Outlined";
@@ -113,7 +117,9 @@ export const Image = (props) => {
113117
src += ".png";
114118
}
115119

116-
if(props.ext) src = props.src
120+
if (props.ext || (props.src && props.src.includes("http"))) {
121+
src = props.src;
122+
}
117123

118124
const errorHandler = (e)=>{
119125
if(props.err) e.target.src = props.err
@@ -142,6 +148,77 @@ export const Image = (props) => {
142148
)
143149
}
144150

151+
const formatseconds = (sec)=>{
152+
if (!sec) return "00:00";
153+
var res = floor(sec / 60);
154+
res += ':';
155+
sec %= 60;
156+
if (sec < 10) res += "0";
157+
res += sec;
158+
159+
return res;
160+
}
161+
162+
export const Video = (props) => {
163+
const dispatch = useDispatch();
164+
const [play, setPlay] = useState(props.autoplay);
165+
const [prog, setProg] = useState(0); // time elapsed
166+
const [perProg, setPerProg] = useState(0); // time elapsed in %
167+
168+
var src = `/img/${(props.dir?props.dir+"/":"")+props.src}`;
169+
if (props.src && !props.src.includes(".")) src += ".mp4";
170+
171+
if (props.ext || (props.src && props.src.includes("http"))) {
172+
src = props.src;
173+
}
174+
175+
const className = `vidCont ${props.inactive?'prtclk':''} ${props.className||''}`.trim()
176+
var dataset = {}
177+
Object.entries(props).forEach(([key, value]) => {
178+
if(key.includes("data-")){
179+
dataset[key] = value
180+
}
181+
});
182+
183+
const handlePause = (e) => setPlay(false)
184+
const handlePlay = (e) => setPlay(true)
185+
186+
const handleProg = (e)=>{
187+
setProg(floor(e.playedSeconds))
188+
setPerProg(e.played)
189+
}
190+
191+
return (
192+
<div className={className} id={props.id}
193+
onClick={props.onClick || (props.action && dispatchAction)}
194+
data-action={props.action} data-payload={props.payload} {...dataset} tabIndex="1">
195+
{!props.playIcon && play &&
196+
<Icon className="play-icon" mui="Pause" round w={48} onClick={handlePause}/>}
197+
{!props.playIcon && !play &&
198+
<Icon className="play-icon opacity-100" mui="PlayArrow" round w={48} onClick={handlePlay}/>}
199+
{props.playIcon}
200+
<ReactPlayer className="react-video"
201+
url={src}
202+
width={props.w || "auto"}
203+
height={props.h || "auto"}
204+
controls={props.controls} playing={props.play || play}
205+
onPlay={props.onPlay || handlePlay} onPause={props.onPause || handlePause}
206+
onProgress={props.onProgress || handleProg} onEnded={props.onEnded || handlePause}/>
207+
{props.cstmctrl && (
208+
<div className="video-control-container">
209+
<span className="prog-text">{formatseconds(prog)}</span>
210+
<Slider size="small"
211+
className="video-progress"
212+
value={perProg*100}
213+
defaultValue={0}
214+
/>
215+
<span className="prog-text">{formatseconds(floor(prog/perProg))}</span>
216+
</div>
217+
)}
218+
</div>
219+
)
220+
}
221+
145222
export const LazyComponent = ({ show, children }) => {
146223
const [loaded, setLoad] = useState(false);
147224

0 commit comments

Comments
 (0)