Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

save changes #900

Merged
merged 10 commits into from
Oct 28, 2024
Merged

save changes #900

merged 10 commits into from
Oct 28, 2024

Conversation

rahulkgupta
Copy link
Collaborator

@rahulkgupta rahulkgupta commented Oct 24, 2024

one interesting thing here is that screenshots are only set on the first time a scene is saved. won't this cause drift with the screenshot and what the user has created?

EDIT: actually, this relates to "set scene thumbnail". I dont think we need to ask the user to do this and instead we should just do this for the users ourselves.

Copy link
Collaborator Author

@rahulkgupta rahulkgupta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is more cleanup but this is a good enough start. should deal w/ the save as issue

@@ -31,6 +31,7 @@
</head>

<body>
<img id="screenshot-img" src="ui_assets/3DStreet-Viewer-Start-Editor.svg" alt="Invisible Image" style="display:none;">
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

created an invisible image so that the screentock functions can be synchronous

@@ -21,7 +21,7 @@ AFRAME.registerComponent('screentock', {
type: { type: 'string', default: 'jpg' }, // png, jpg, img
imgElementSelector: { type: 'selector' }
},
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed all the async code from here

@@ -189,6 +191,102 @@ const checkIfImagePathIsEmpty = async (sceneId) => {
}
};

const saveScreenshot = async (value) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved screenshot functionality to the scene api file so that the toolbar component didn't call functions from the screenshotmodalcomponent


const uploadThumbnailImage = async () => {
try {
// saveScreenshot('img');
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note, i commented this out, since in every call makeScreenshot is called prior

@@ -30,7 +30,6 @@ export default class Toolbar extends Component {
this.state = {
// isPlaying: false,
isSaveActionActive: false,
isCapturingScreen: false,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed all state related functionality for this

// AFRAME.INSPECTOR.close();
// }
makeScreenshot = () => {
const imgHTML = '<img id="screentock-destination">';
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the invisible imgHTML

@@ -343,8 +323,8 @@ export default class Toolbar extends Component {
};

toggleSaveActionState = () => {
this.makeScreenshot();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explicitly call makescreenshot rather than state management

...prevState,
isCapturingScreen: true
}));
this.makeScreenshot();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call makescreenshot instead of using state

@rahulkgupta rahulkgupta changed the title screenshot changes save changes Oct 25, 2024
@@ -44,24 +62,16 @@ const deleteScene = async (sceneId) => {
}
};

const updateScene = async (sceneId, userUID, sceneData, title, version) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to pass user id in updating a scene

@@ -34,6 +36,22 @@ const generateSceneId = async (authorId) => {
return newSceneId;
};

const createScene = async (authorId, sceneData, title, version) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a createScene

@@ -88,28 +96,6 @@ const updateSceneIdAndTitle = async (sceneId, title) => {
}
};

const isSceneAuthor = async ({ sceneId, authorId }) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no longer needed

AFRAME.scenes[0].setAttribute('metadata', 'sceneId', sceneId);
AFRAME.scenes[0].setAttribute('metadata', 'sceneTitle', sceneTitle);

AFRAME.scenes[0].setAttribute('metadata', 'authorId', sceneData.author);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when a new scene is loaded, set the authorId

// import { loginHandler } from '../SignInModal';

export const uploadThumbnailImage = async (uploadedFirstTime) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this to a shared location so that Toolbar isn't calling this component

@@ -218,48 +183,42 @@ export default class Toolbar extends Component {
console.log(
'no urlSceneId or doSaveAs is true, therefore generate new one'
);
currentSceneId = await generateSceneId(this.props.currentUser.uid);
currentSceneId = await createScene(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of generating a scene id and then updating a scene, we are simply creating a scene w/ all the relevant info

console.log('newly generated currentSceneId', currentSceneId);
window.location.hash = `#/scenes/${currentSceneId}.json`;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are doing this later anyways, so this is duplicative

await uploadThumbnailImage(true);
}
AFRAME.scenes[0].setAttribute('metadata', 'sceneId' + currentSceneId);
AFRAME.scenes[0].setAttribute(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also updating the authorid now

// make sure to update sceneId with new one in metadata component!
AFRAME.scenes[0].setAttribute('metadata', 'sceneId: ' + currentSceneId);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note, i change sceneId: to sceneId

}, [currentUser, currentSceneId]);

return <Toolbar currentUser={currentUser} isAuthor={isAuthor} />;
return <Toolbar currentUser={currentUser} />;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cleaned this up. no longer passing stuff that doesnt make sense

@kfarr
Copy link
Collaborator

kfarr commented Oct 28, 2024

meta comments:

  • Before this PR, the state was duplicated across both React and A-Frame components with with Kieran and Alex's "spaghetti code." After this PR state is still duplicated, but there is a lot less spaghetti code and some things are much simpler such as handling of author. Active scene ID, title, author, etc. is probably a candidate for zustand or similar state management system when the time is right.

testing results:

I have a hard time testing the core issue of the "race conditions" of async preview generation not compatible

Instead, I have tested the following to see what is the outcome for preview image generation and uploading:

  • ⭐ press save button when not logged in (then logging in with either google or msft) -- results in uploading black box for thumbnail (if no prior screenshots taken) OR uploading the previously captured image (if successfully saved a capture earlier in the same session) [1] this is confusing as it could be a thumbnail from a scene that is not currently loaded. (ie a black box would be better than the incorrect thumbnail).
  • when logged in, open another user's scene, then press "save as" from another user's scene -- WORKS as expected
  • ⭐ when logged in, open another user's scene, then move an item, then change the title in the title popup from another user's scene -- RESULT in no thumbnail [2] (different than black, this is not uploading any thumbnail)
  • when logged in, open my own scene, then press "save as" from my own scene -- WORKS as expected
  • ⭐ when logged in, open my own scene, then click share, then click "Set as scene thumbnail" Now I no longer see a success message after uploading (unless I look at console log) and I may think that something has gone wrong. I do see an unauthorized error if it is raised, which is expected behavior (if I attempt to change the thumbnail of a scene that is not my own)

screenshots:
[1] see left thumbnail
image
[2] see left thumbnail
image

@kfarr
Copy link
Collaborator

kfarr commented Oct 28, 2024

all looks great!

change noted as discussed: opening another user's scene, and moving an object, it no longer asks for save as

@kfarr kfarr merged commit 6fbafdb into main Oct 28, 2024
1 check passed
@kfarr kfarr deleted the cleanup-image-upload branch October 28, 2024 23:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants