Skip to content

Commit

Permalink
more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Rahul Gupta authored and Rahul Gupta committed Nov 19, 2024
1 parent f6e3dec commit 38b41ad
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
createElementsForScenesFromJSON,
fileJSON,
inputStreetmix
} from '../../../lib/toolbar';
} from '@/editor/lib/SceneUtils.js';
import { getCommunityScenes, getUserScenes } from '../../../api/scene';
import { Load24Icon, Loader, Upload24Icon } from '../../../icons';
import { signIn } from '../../../api';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { signIn } from '../../../api';
import { useAuthContext } from '../../../contexts';
import { Copy32Icon, Save24Icon } from '../../../icons';
import { Button, Dropdown, Input } from '../../components';
import Toolbar from '../../scenegraph/Toolbar';
import Modal from '../Modal.jsx';
import posthog from 'posthog-js';
import { saveBlob } from '../../../lib/utils';
import { uploadThumbnailImage, saveScreenshot } from '../../../api/scene';
import useStore from '@/store';
import { convertToObject } from '@/editor/lib/SceneUtils';

const filterHelpers = (scene, visible) => {
scene.traverse((o) => {
Expand Down Expand Up @@ -80,7 +80,12 @@ function ScreenshotModal() {
{
value: '.3dstreet.json',
label: '.3dstreet.json',
onClick: Toolbar.convertToObject
onClick: () => {
posthog.capture('convert_to_json_clicked', {
scene_id: STREET.utils.getCurrentSceneId()
});
convertToObject();
}
}
];

Expand Down
32 changes: 2 additions & 30 deletions src/editor/components/scenegraph/Toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,34 +87,6 @@ export default class Toolbar extends Component {
}
};

static convertToObject = () => {
try {
posthog.capture('convert_to_json_clicked', {
scene_id: STREET.utils.getCurrentSceneId()
});
const entity = document.getElementById('street-container');

const data = STREET.utils.convertDOMElToObject(entity);

const jsonString = `data:text/json;chatset=utf-8,${encodeURIComponent(
STREET.utils.filterJSONstreet(data)
)}`;

const link = document.createElement('a');
link.href = jsonString;
link.download = 'data.json';

link.click();
link.remove();
STREET.notify.successMessage('3DStreet JSON file saved successfully.');
} catch (error) {
STREET.notify.errorMessage(
`Error trying to save 3DStreet JSON file. Error: ${error}`
);
console.error(error);
}
};

cloudSaveHandlerWithImageUpload = async (doSaveAs) => {
this.makeScreenshot();
const currentSceneId = await this.cloudSaveHandler({ doSaveAs });
Expand All @@ -127,6 +99,7 @@ export default class Toolbar extends Component {
newHandler = () => {
posthog.capture('new_scene_clicked');
AFRAME.INSPECTOR.selectEntity(null);
useStore.getState().newScene();
STREET.utils.newScene();
AFRAME.scenes[0].emit('newScene');
};
Expand All @@ -136,7 +109,6 @@ export default class Toolbar extends Component {
// if there is no current user, show sign in modal
let currentSceneId = STREET.utils.getCurrentSceneId();
let currentSceneTitle = useStore.getState().sceneTitle;
console.log(currentSceneTitle);

posthog.capture('save_scene_clicked', {
save_as: doSaveAs,
Expand Down Expand Up @@ -181,7 +153,7 @@ export default class Toolbar extends Component {
// we want to save, so if we *still* have no sceneID at this point, then create a new one
if (!currentSceneId || !!doSaveAs) {
// ask user for scene title here currentSceneTitle
let newSceneTitle = prompt('Scene Title:', currentSceneTitle);
let newSceneTitle = prompt('Scene Title:', currentSceneTitle || '');

if (newSceneTitle) {
currentSceneTitle = newSceneTitle;
Expand Down
25 changes: 25 additions & 0 deletions src/editor/lib/toolbar.js → src/editor/lib/SceneUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,28 @@ export function fileJSON(event) {

reader.readAsText(event.target.files[0]);
}

export function convertToObject() {
try {
const entity = document.getElementById('street-container');

const data = STREET.utils.convertDOMElToObject(entity);

const jsonString = `data:text/json;chatset=utf-8,${encodeURIComponent(
STREET.utils.filterJSONstreet(data)
)}`;

const link = document.createElement('a');
link.href = jsonString;
link.download = 'data.json';

link.click();
link.remove();
STREET.notify.successMessage('3DStreet JSON file saved successfully.');
} catch (error) {
STREET.notify.errorMessage(
`Error trying to save 3DStreet JSON file. Error: ${error}`
);
console.error(error);
}
}
4 changes: 3 additions & 1 deletion src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ const useStore = create(
(set) => ({
sceneId: null,
setSceneId: (newSceneId) => set({ sceneId: newSceneId }),
sceneTitle: '',
sceneTitle: null,
setSceneTitle: (newSceneTitle) => set({ sceneTitle: newSceneTitle }),
newScene: () =>
set({ sceneId: null, sceneTitle: null, authorId: null }),
authorId: null,
setAuthorId: (newAuthorId) => set({ authorId: newAuthorId }),
modal: firstModal(),
Expand Down

0 comments on commit 38b41ad

Please sign in to comment.