forked from reactplay/react-play
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gallery.js
77 lines (68 loc) · 2.54 KB
/
Gallery.js
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
import React from 'react'
import { useState, useEffect } from 'react'
import GalleryAPI from './GalleryAPI'
export default function Gallery() {
const [data, setData] = useState(GalleryAPI)
const [ourText, setOurText] = useState("Welcome to the Image Gallery, Click on the Images and get to know about it.")
const [midText, setMidText] = useState("Sorry for interrupting. I think you like our Gallery. Don't forget to give it a thumbs up.")
const msg = new SpeechSynthesisUtterance()
var voiceName = "Zira"
const filterResult = (catItem) => {
const result = GalleryAPI.filter((currentData) => {
speechHandler(msg)
return currentData.type === catItem;
});
}
const speechHandler = (msg) => {
msg.text = ourText
//This for loop help us to give the female voice
for (let i = 0; i < window.speechSynthesis.getVoices().length; i++) {
if (window.speechSynthesis.getVoices()[i].voiceURI.search(voiceName) !== -1) {
msg.voice = window.speechSynthesis.getVoices()[i];
}
}
window.speechSynthesis.cancel();
window.speechSynthesis.speak(msg)
}
function sayAboutImage() {
speechHandler(msg)
}
useEffect(() => {
setTimeout(() => {
setOurText(midText)
}, 40000);
}, [])
setTimeout(() => {
speechHandler(msg)
}, 6);
return (
<>
{/* Final Grid */}
<div className='know-image-heading-gallery'>Do You Know the Image?</div>
<div class="know-image-gallery-image" >
{data.map((values) => {
const { url, type, discription, title, videoUrl } = values
return (
<>
<div class="know-image-gallery-img-box" onMouseUp={() => setOurText(discription)}>
<img src={url} alt="galleryImage" className='know-image-gallery-grid-image' onClick={() => filterResult(type)} />
<video autoPlay loop className='know-image-gallery-video'>
<source src={videoUrl} />
</video>
<div class="know-image-transparent-box">
<div class="know-image-caption">
<p>{title}</p>
<button class="know-image-opacity-low" onClick={sayAboutImage}>Know Me</button>
</div>
</div>
</div>
</>
)
})}
</div>
<div>
<button class="know-image-custom-btn know-image-gallery-btn" onClick={() => setOurText("More images will add soon, and till then, explore the rest of them.")}><span>More...</span></button>
</div>
</>
)
}