modal window
This commit is contained in:
parent
a3740d5c8c
commit
5856be9b29
@ -20,6 +20,8 @@ class Main extends Component {
|
|||||||
results: [],
|
results: [],
|
||||||
page: window.location.hash,
|
page: window.location.hash,
|
||||||
photos: [],
|
photos: [],
|
||||||
|
photoIsOpen: false,
|
||||||
|
currentImage: 0,
|
||||||
};
|
};
|
||||||
fetch(addr_prefix + "/api/results").then(resp => resp.json()).then(json => {
|
fetch(addr_prefix + "/api/results").then(resp => resp.json()).then(json => {
|
||||||
this.setState({results: json})
|
this.setState({results: json})
|
||||||
@ -29,6 +31,15 @@ class Main extends Component {
|
|||||||
})
|
})
|
||||||
window.addEventListener("hashchange", (e) => {this.onHashChange(e)})
|
window.addEventListener("hashchange", (e) => {this.onHashChange(e)})
|
||||||
}
|
}
|
||||||
|
togglePhoto = () => {
|
||||||
|
this.setState(state => ({ photoIsOpen: !state.photoIsOpen }))
|
||||||
|
}
|
||||||
|
openPhoto = (event, {index}) => {
|
||||||
|
this.setState({
|
||||||
|
currentImage: index,
|
||||||
|
photoIsOpen: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
onHashChange(event){
|
onHashChange(event){
|
||||||
this.setState({page: window.location.hash})
|
this.setState({page: window.location.hash})
|
||||||
}
|
}
|
||||||
@ -60,6 +71,7 @@ class Main extends Component {
|
|||||||
let photos = [];
|
let photos = [];
|
||||||
for (const photo of this.state.photos){
|
for (const photo of this.state.photos){
|
||||||
photos.push({
|
photos.push({
|
||||||
|
source: photo.original,
|
||||||
src: photo.original,
|
src: photo.original,
|
||||||
width: photo.original_width,
|
width: photo.original_width,
|
||||||
height: photo.original_height,
|
height: photo.original_height,
|
||||||
@ -68,6 +80,13 @@ class Main extends Component {
|
|||||||
console.log(photos, this.state.photos)
|
console.log(photos, this.state.photos)
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
<ModalGateway>
|
||||||
|
{this.state.photoIsOpen ? (
|
||||||
|
<Modal onClose={this.togglePhoto}>
|
||||||
|
<Carousel views={photos} currentIndex={this.state.currentImage} />
|
||||||
|
</Modal>
|
||||||
|
) : null}
|
||||||
|
</ModalGateway>
|
||||||
<nav class="navbar navbar-expand-lg bg-body-tertiary">
|
<nav class="navbar navbar-expand-lg bg-body-tertiary">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<ul class="navbar-nav mb-0">
|
<ul class="navbar-nav mb-0">
|
||||||
@ -82,7 +101,7 @@ class Main extends Component {
|
|||||||
</nav>
|
</nav>
|
||||||
{this.state.page == "#gallery" &&
|
{this.state.page == "#gallery" &&
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<Gallery photos={photos} />
|
<Gallery photos={photos} onClick={this.openPhoto}/>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
{this.state.page == "" &&
|
{this.state.page == "" &&
|
||||||
|
Loading…
x
Reference in New Issue
Block a user