From 5856be9b29954fa2f7c68ba390eabdf5137782f4 Mon Sep 17 00:00:00 2001 From: Martin Quarda Date: Wed, 8 May 2024 06:40:04 +0200 Subject: [PATCH] modal window --- frontend/src/scripts/index.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/frontend/src/scripts/index.js b/frontend/src/scripts/index.js index 1841413..35af3d1 100644 --- a/frontend/src/scripts/index.js +++ b/frontend/src/scripts/index.js @@ -20,6 +20,8 @@ class Main extends Component { results: [], page: window.location.hash, photos: [], + photoIsOpen: false, + currentImage: 0, }; fetch(addr_prefix + "/api/results").then(resp => resp.json()).then(json => { this.setState({results: json}) @@ -29,6 +31,15 @@ class Main extends Component { }) 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){ this.setState({page: window.location.hash}) } @@ -60,6 +71,7 @@ class Main extends Component { let photos = []; for (const photo of this.state.photos){ photos.push({ + source: photo.original, src: photo.original, width: photo.original_width, height: photo.original_height, @@ -68,6 +80,13 @@ class Main extends Component { console.log(photos, this.state.photos) return (
+ + {this.state.photoIsOpen ? ( + + + + ) : null} + {this.state.page == "#gallery" &&
- +
} {this.state.page == "" &&