From 598fce003affd5b6ae88b2b28bb4b37569e20944 Mon Sep 17 00:00:00 2001 From: Alexander Goryushkin Date: Mon, 10 Jun 2024 23:09:18 -0400 Subject: [PATCH 1/2] add newtitle event --- .../SceneEditTitle/SceneEditTitle.component.jsx | 10 ++++++++++ src/json-utils_1.1.js | 3 +++ 2 files changed, 13 insertions(+) diff --git a/src/editor/components/components/SceneEditTitle/SceneEditTitle.component.jsx b/src/editor/components/components/SceneEditTitle/SceneEditTitle.component.jsx index 0b23d1fd3..9ce85021d 100644 --- a/src/editor/components/components/SceneEditTitle/SceneEditTitle.component.jsx +++ b/src/editor/components/components/SceneEditTitle/SceneEditTitle.component.jsx @@ -1,6 +1,7 @@ import { useEffect, useState } from 'react'; import styles from './SceneEditTitle.module.scss'; import { updateSceneIdAndTitle } from '../../../api/scene'; +import Events from '../../../lib/Events'; const SceneEditTitle = ({ sceneData }) => { const [title, setTitle] = useState(sceneData?.sceneTitle); @@ -13,6 +14,15 @@ const SceneEditTitle = ({ sceneData }) => { } }, [sceneData?.sceneTitle, sceneData?.sceneId, sceneId]); + useEffect(() => { + const handleNewTitleEvent = (newTitle) => { + setTitle(newTitle); + saveNewTitle(newTitle); + }; + + Events.on('newtitle', handleNewTitleEvent); + }, []); + const handleEditClick = () => { const newTitle = prompt('Edit the title:', title); diff --git a/src/json-utils_1.1.js b/src/json-utils_1.1.js index b5a785dc7..303e2b8c3 100644 --- a/src/json-utils_1.1.js +++ b/src/json-utils_1.1.js @@ -1,5 +1,6 @@ /* global AFRAME, Node */ /* version: 1.0 */ +import Events from './editor/lib/Events'; window.STREET = {}; var assetsUrl; @@ -494,6 +495,8 @@ AFRAME.registerComponent('scene-title', { titleDiv.setAttribute('id', 'sceneTitle'); titleDiv.appendChild(newContent); document.body.append(titleDiv); + // update scene title in Editor mode + Events.emit('entityupdate', this.el); }, updateTitleText: function (titleText) { this.titleElement.textContent = titleText; From 56eedbba44a3634e974aefb67832803f07c5a8b4 Mon Sep 17 00:00:00 2001 From: Alexander Goryushkin Date: Tue, 11 Jun 2024 12:27:58 -0400 Subject: [PATCH 2/2] add listener for newTitle event --- .../SceneEditTitle/SceneEditTitle.component.jsx | 10 +++------- src/json-utils_1.1.js | 4 ---- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/editor/components/components/SceneEditTitle/SceneEditTitle.component.jsx b/src/editor/components/components/SceneEditTitle/SceneEditTitle.component.jsx index 9ce85021d..1814eff39 100644 --- a/src/editor/components/components/SceneEditTitle/SceneEditTitle.component.jsx +++ b/src/editor/components/components/SceneEditTitle/SceneEditTitle.component.jsx @@ -1,7 +1,6 @@ import { useEffect, useState } from 'react'; import styles from './SceneEditTitle.module.scss'; import { updateSceneIdAndTitle } from '../../../api/scene'; -import Events from '../../../lib/Events'; const SceneEditTitle = ({ sceneData }) => { const [title, setTitle] = useState(sceneData?.sceneTitle); @@ -15,12 +14,9 @@ const SceneEditTitle = ({ sceneData }) => { }, [sceneData?.sceneTitle, sceneData?.sceneId, sceneId]); useEffect(() => { - const handleNewTitleEvent = (newTitle) => { - setTitle(newTitle); - saveNewTitle(newTitle); - }; - - Events.on('newtitle', handleNewTitleEvent); + AFRAME.scenes[0].addEventListener('newTitle', (event) => { + setTitle(event.detail.sceneTitle ?? ''); + }); }, []); const handleEditClick = () => { diff --git a/src/json-utils_1.1.js b/src/json-utils_1.1.js index 303e2b8c3..215d79b59 100644 --- a/src/json-utils_1.1.js +++ b/src/json-utils_1.1.js @@ -1,7 +1,5 @@ /* global AFRAME, Node */ /* version: 1.0 */ -import Events from './editor/lib/Events'; - window.STREET = {}; var assetsUrl; STREET.utils = {}; @@ -495,8 +493,6 @@ AFRAME.registerComponent('scene-title', { titleDiv.setAttribute('id', 'sceneTitle'); titleDiv.appendChild(newContent); document.body.append(titleDiv); - // update scene title in Editor mode - Events.emit('entityupdate', this.el); }, updateTitleText: function (titleText) { this.titleElement.textContent = titleText;