Skip to content

Commit

Permalink
'New Scene' default title & simplify title editing
Browse files Browse the repository at this point in the history
  • Loading branch information
kfarr committed Jun 3, 2024
1 parent 663eed2 commit 690a5db
Showing 1 changed file with 3 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { useEffect, useState } from 'react';
import styles from './SceneEditTitle.module.scss';
import { CheckMark32Icon, Cross32Icon } from '../../../icons';
import { updateSceneIdAndTitle } from '../../../api/scene';

const SceneEditTitle = ({ sceneData }) => {
const [editMode, setEditMode] = useState(false);
const [title, setTitle] = useState(sceneData?.sceneTitle);

const sceneId = STREET.utils.getCurrentSceneId();
Expand All @@ -27,7 +25,6 @@ const SceneEditTitle = ({ sceneData }) => {
};

const saveNewTitle = async (newTitle) => {
setEditMode(false);
try {
await updateSceneIdAndTitle(sceneData?.sceneId, newTitle);
AFRAME.scenes[0].setAttribute('metadata', 'sceneTitle', newTitle);
Expand All @@ -39,46 +36,15 @@ const SceneEditTitle = ({ sceneData }) => {
}
};

const handleCancelClick = () => {
if (sceneData && sceneData.sceneTitle !== undefined) {
setTitle(sceneData.sceneTitle);
}
setEditMode(false);
};

const handleKeyDown = (event) => {
if (event.key === 'Enter') {
saveNewTitle();
} else if (event.key === 'Escape') {
handleCancelClick();
}
};
return (
<div className={styles.wrapper}>
{editMode ? (
<div className={styles.edit}>
<input
className={styles.title}
value={title}
// onChange={handleChange}
onKeyDown={handleKeyDown}
/>
<div className={styles.buttons}>
<div onClick={() => saveNewTitle(title)} className={styles.check}>
<CheckMark32Icon />
</div>
<div onClick={handleCancelClick} className={styles.cross}>
<Cross32Icon />
</div>
</div>
</div>
) : (
{
<div className={styles.readOnly}>
<p className={styles.title} onClick={handleEditClick}>
{title}
{title || 'New Scene'}
</p>
</div>
)}
}
</div>
);
};
Expand Down

0 comments on commit 690a5db

Please sign in to comment.