From 0e3e9564eb6ffe04ed4cc5cf6791f7db59e7f13b Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Tue, 7 Sep 2021 21:31:54 +0200 Subject: interactions working --- frontend/site/projects/museum/views/petros.nav.js | 91 +++++++++++++++-------- 1 file changed, 60 insertions(+), 31 deletions(-) (limited to 'frontend/site/projects/museum/views/petros.nav.js') diff --git a/frontend/site/projects/museum/views/petros.nav.js b/frontend/site/projects/museum/views/petros.nav.js index 9ccfdff..232e1d0 100644 --- a/frontend/site/projects/museum/views/petros.nav.js +++ b/frontend/site/projects/museum/views/petros.nav.js @@ -12,9 +12,13 @@ import { preloadImage } from "app/utils" import actions from "site/actions" const RESET_STATE = { + ready: false, + hovering: null, textActive: false, textDone: false, - ready: false, + textOpacity: 0.0, + iconFade: false, + text: null, } const MOVEMENT = "movement" @@ -30,9 +34,13 @@ const INITIAL_VIEW = { 7: LOOP, } -const LOOP_TIMEOUT = 100 +const LOOP_TIMEOUT = 20 const MOVEMENT_TIMEOUT = 40000 const TEXT_LOAD_TIMEOUT = 15000 +const TEXT_SHOW_TIMEOUT = 20 +const TEXT_HIDE_TIMEOUT = 15000 + +const SUBTITLE_COUNT = 12 class PetrosNav extends Component { state = { @@ -70,6 +78,7 @@ class PetrosNav extends Component { if (!isPetros) { clearTimeout(this.readyTimeout) + clearTimeout(this.textTimeout) this.setState({ ...RESET_STATE, }) @@ -91,7 +100,7 @@ class PetrosNav extends Component { } handleEnter(event) { - const side = event.target.className.split('-') + const side = event.target.className.match(/-(\w+)/)[1] this.setState({ hovering: side }) } handleLeave(event) { @@ -100,21 +109,34 @@ class PetrosNav extends Component { /** Start text generation sequence */ handleClickText() { - if (this.state.textActive) return + if (this.state.textActive || this.state.text) return this.setState({ textActive: true, - hovering: false + hovering: false, + textOpacity: 0.0, + text: null }) // Turn on the glyph actions.site.setPopups({ ...this.props.popups, glyph: true, }) + // Fetch the subtitles + const subtitle_index = 1 + const subtitle_choice = randint(SUBTITLE_COUNT) + 1 + fetch(`/thelastmuseum/static/media/last-museum/petros-moris/texts/${subtitle_index}/${subtitle_choice}.txt`, { + method: 'GET', + }) + .then(res => res.text()) + .then(text => this.setState({ text: text.trim() })) + .catch(err => this.setState({ text: "Flowing into the atmosphere through the cracks,\nthe fluid rock creates mountains that look alike the skin of serpents" })) + this.textTimeout = setTimeout(() => { this.setState({ textActive: false, textDone: true, + textOpacity: 0.0, }) // Turn off the glyph @@ -122,6 +144,14 @@ class PetrosNav extends Component { ...this.props.popups, glyph: false, }) + + this.textTimeout = setTimeout(() => { + this.setState({ textOpacity: 1.0, iconFade: true }) + this.textTimeout = setTimeout(() => { + this.setState({ textOpacity: 0.0 }) + }, TEXT_HIDE_TIMEOUT) + }, TEXT_SHOW_TIMEOUT) + }, TEXT_LOAD_TIMEOUT) } @@ -131,7 +161,7 @@ class PetrosNav extends Component { const leftIndex = Math.max(1, index - 1) const rightIndex = Math.min(7, index + 1) if (textActive) return - const side = event.target.className.split('-') + const side = event.target.className.match(/-(\w+)/)[1] // if navigating to the left, just navigate. console.log(side, index) if (side === "left") { @@ -156,65 +186,64 @@ class PetrosNav extends Component { } render() { - const { index, ready, hovering, textActive, textDone } = this.state + const { index, ready, hovering, textActive, textDone, textOpacity, iconFade, text } = this.state if (!this.props.interactive || (!index)) return null const leftIndex = Math.max(1, index - 1) const rightIndex = Math.min(7, index + 1) return (
+ + {ready && ( - )} - {ready && textDone && ( - )} - {ready && textDone && ( + {ready && ( )} + {!textActive && text && ( +
+ {text} +
+ )}
) } } + +const randint = n => Math.floor(Math.random() * n) + const mapStateToProps = state => ({ interactive: state.site.interactive, popups: state.site.popups, }) + export default connect(mapStateToProps)(PetrosNav) -- cgit v1.2.3-70-g09d2