3DStreet / 3dstreet

🚲🚶🚌 Web-based 3D visualization of streets using A-Frame
https://3dstreet.app
Other
249 stars 30 forks source link

save new scene title in JSON file #573

Closed Algorush closed 3 weeks ago

Algorush commented 3 weeks ago

Issue: https://github.com/3DStreet/3dstreet/issues/553 Now the title is saved in JSON and also updated in Editor mode. But there is another error related to Firebase - https://github.com/3DStreet/3dstreet/issues/532. I will fix it in another branch.

vincentfretin commented 3 weeks ago

Is this fixing #577 too? That's really not a good idea to update a DOM element that is handled by React. Can't we use an effect in SceneEditTitle to listen to the newTitle event?

Algorush commented 3 weeks ago

Can't we use an effect in SceneEditTitle to listen to the newTitle event?

But we are loading json-utils.js before the Editor code which contains Events. I don't understand a little how this can be implemented. Now if I import 'editor/lib/Events' into SceneEditTitle.component, where I assign Events.on('newtitle' ()=> ...). And I also import Events into json-utils.js. But since json-utils is called earlier, Events is imported with an empty list of events. Also I noticed that now when loading a saved scene with title, initially title=Undefined. But after selecting any entity, its title appears, this is not clear to me. This happens even without calling the 'newtitle' event handler

vincentfretin commented 3 weeks ago

Events.js on and emit functions is used only for parts of editor between aframe world and React. The newTitle event emitted in the metadata aframe component is not using that but the emit function from aframe entity. That's not the same. To register a listener for that event you need to use AFRAME.scenes[0].addEventListener('newTitle', ...).

If you see at one point the title when you select an entity, probably the SceneEditTitle react component is rerendering, you can check what going on with the props and the effect there.

Algorush commented 3 weeks ago

Events.js on and emit functions is used only for parts of editor between aframe world and React. The newTitle event emitted in the metadata aframe component is not using that but the emit function from aframe entity. That's not the same. To register a listener for that event you need to use AFRAME.scenes[0].addEventListener('newTitle', ...).

Thanks for this tip. I didn’t realize at first that I could use an existing event