-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #957 from 3DStreet/auto-save
Auto save
- Loading branch information
Showing
21 changed files
with
574 additions
and
441 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
src/editor/components/components/Save/Save.component.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
import { useState, useEffect } from 'react'; | ||
import { saveSceneWithScreenshot } from '@/editor/lib/SceneUtils'; | ||
import useStore from '@/store'; | ||
import { Button } from '@/editor/components/components'; | ||
import { Cloud24Icon, Save24Icon } from '@/editor/icons'; | ||
import debounce from 'lodash-es/debounce'; | ||
import Events from '@/editor/lib/Events'; | ||
|
||
export const Save = ({ currentUser }) => { | ||
const [savedScene, setSavedScene] = useState(false); | ||
const [isSaveActionActive, setIsSaveActionActive] = useState(false); | ||
const { isSavingScene, doSaveAs, setModal, saveScene, postSaveScene } = | ||
useStore(); | ||
|
||
useEffect(() => { | ||
if (savedScene) { | ||
debounce(() => { | ||
setSavedScene(false); | ||
}, 1000); | ||
} | ||
}, [savedScene]); // eslint-disable-line react-hooks/exhaustive-deps | ||
|
||
useEffect(() => { | ||
const autoSaveScene = debounce((cmd) => { | ||
if (cmd) { | ||
if (currentUser && STREET.utils.getAuthorId() === currentUser.uid) { | ||
const streetGeo = document | ||
.getElementById('reference-layers') | ||
?.getAttribute('street-geo'); | ||
if ( | ||
!currentUser.isPro && | ||
streetGeo && | ||
streetGeo['latitude'] && | ||
streetGeo['longitude'] | ||
) { | ||
setModal('payment'); | ||
return; | ||
} | ||
saveScene(false); | ||
} | ||
} | ||
}, 1000); | ||
Events.on('historychanged', autoSaveScene); | ||
return () => { | ||
Events.off('historychanged', autoSaveScene); | ||
}; | ||
}, [currentUser]); // eslint-disable-line react-hooks/exhaustive-deps | ||
|
||
useEffect(() => { | ||
if (isSavingScene) { | ||
handleSave(doSaveAs); | ||
} | ||
}, [isSavingScene]); // eslint-disable-line react-hooks/exhaustive-deps | ||
// if (isSavingScene) { | ||
// // Events.on('historychanged', (cmd) => { | ||
// // if (cmd) { | ||
// // // Debounce the cloudSaveHandler call | ||
|
||
// // // this.debouncedCloudSaveHandler(); | ||
// // } | ||
// // }); | ||
|
||
const toggleSaveActionState = () => { | ||
setIsSaveActionActive(!isSaveActionActive); | ||
}; | ||
|
||
const isAuthor = () => { | ||
return currentUser?.uid === STREET.utils.getAuthorId(); | ||
}; | ||
|
||
const handleSave = async (saveAs) => { | ||
try { | ||
await saveSceneWithScreenshot(currentUser, saveAs); | ||
} catch (error) { | ||
STREET.notify.errorMessage( | ||
`Error trying to save 3DStreet scene to cloud. Error: ${error}` | ||
); | ||
console.error(error); | ||
} finally { | ||
postSaveScene(); | ||
setSavedScene(true); | ||
} | ||
}; | ||
|
||
const handleUnsignedSave = () => { | ||
setModal('signin'); | ||
}; | ||
|
||
return ( | ||
<div> | ||
{currentUser ? ( | ||
<div className="saveButtonWrapper relative w-24"> | ||
{isSavingScene ? ( | ||
<Button variant="filled"> | ||
<div>Saved</div> | ||
</Button> | ||
) : ( | ||
<Button | ||
leadingIcon={<Save24Icon />} | ||
onClick={toggleSaveActionState} | ||
disabled={isSavingScene} | ||
variant="toolbtn" | ||
> | ||
<div>Save</div> | ||
</Button> | ||
)} | ||
{isSaveActionActive && ( | ||
<div className="dropdownedButtons"> | ||
<Button | ||
leadingIcon={<Cloud24Icon />} | ||
variant="white" | ||
onClick={() => saveScene(false)} | ||
disabled={isSavingScene || !isAuthor()} | ||
> | ||
<div>Save</div> | ||
</Button> | ||
<Button | ||
leadingIcon={<Cloud24Icon />} | ||
variant="white" | ||
onClick={() => saveScene(true)} | ||
disabled={isSavingScene} | ||
> | ||
<div>Make a Copy</div> | ||
</Button> | ||
</div> | ||
)} | ||
</div> | ||
) : ( | ||
<Button | ||
leadingIcon={<Save24Icon />} | ||
onClick={handleUnsignedSave} | ||
disabled={isSavingScene} | ||
variant="toolbtn" | ||
> | ||
<div>Save</div> | ||
</Button> | ||
)} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { Save } from './Save.component.jsx'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/editor/components/modals/NewModal/NewModal.component.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import Modal from '../Modal.jsx'; | ||
import useStore from '@/store.js'; | ||
import styles from './NewModal.module.scss'; | ||
import ScenePlaceholder from '@/../ui_assets/ScenePlaceholder.svg'; | ||
import { inputStreetmix } from '@/editor/lib/SceneUtils.js'; | ||
import { Button } from '@/editor/components/components'; | ||
import { Upload24Icon } from '@/editor/icons'; | ||
|
||
export const NewModal = () => { | ||
const setModal = useStore((state) => state.setModal); | ||
const isOpen = useStore((state) => state.modal === 'new'); | ||
const saveScene = useStore((state) => state.saveScene); | ||
const onClose = () => { | ||
setModal(null); | ||
}; | ||
|
||
const onClickNew = () => { | ||
setModal(null); | ||
AFRAME.INSPECTOR.selectEntity(null); | ||
useStore.getState().newScene(); | ||
STREET.utils.newScene(); | ||
AFRAME.scenes[0].emit('newScene'); | ||
}; | ||
|
||
const scenesData = [ | ||
{ | ||
title: 'Create Blank Scene', | ||
imagePath: '/ui_assets/cards/new-blank.jpg', | ||
onClick: onClickNew | ||
}, | ||
{ | ||
title: 'Import From Streetmix', | ||
imagePath: '/ui_assets/cards/new-streetmix-import.jpg', | ||
onClick: inputStreetmix | ||
} | ||
]; | ||
|
||
return ( | ||
<Modal | ||
isOpen={isOpen} | ||
onClose={onClose} | ||
title="Create a New Scene" | ||
titleElement={ | ||
<div className="flex items-center justify-between pr-4 pt-4"> | ||
<div className="font-large text-center text-2xl"> | ||
Create a New Scene | ||
</div> | ||
<Button | ||
onClick={() => { | ||
setModal('scenes'); | ||
}} | ||
leadingIcon={<Upload24Icon />} | ||
> | ||
Open Scene | ||
</Button> | ||
</div> | ||
} | ||
> | ||
<div className={styles.wrapper}> | ||
{scenesData?.map((scene, index) => ( | ||
<div key={index} className={styles.card} title={scene.title}> | ||
<div | ||
className={styles.img} | ||
onClick={(event) => { | ||
scene.onClick(event); | ||
saveScene(true); | ||
onClose(); | ||
}} | ||
style={{ | ||
backgroundImage: `url(${scene.imagePath || ScenePlaceholder})`, | ||
backgroundSize: 'cover', | ||
backgroundPosition: 'center' | ||
}} | ||
/> | ||
<div> | ||
<p className={styles.title}>{scene.title}</p> | ||
</div> | ||
</div> | ||
))} | ||
</div> | ||
</Modal> | ||
); | ||
}; |
Oops, something went wrong.