Skip to content

Commit

Permalink
Fix: update file metadata when saving cloud project triggers new comm…
Browse files Browse the repository at this point in the history
…it (#6074)
  • Loading branch information
AlexandreSi authored Dec 13, 2023
1 parent 2c92ae4 commit ac82be8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
10 changes: 7 additions & 3 deletions newIDE/app/src/MainFrame/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2638,17 +2638,21 @@ const MainFrame = (props: Props) => {
const onChangeProjectName = async (newName: string): Promise<void> => {
if (!currentProject || !currentFileMetadata) return;
const storageProviderOperations = getStorageProviderOperations();
let newFileMetadata = { ...currentFileMetadata, name: newName };
if (storageProviderOperations.onChangeProjectProperty) {
const wasSaved = await storageProviderOperations.onChangeProjectProperty(
const fileMetadataNewAttributes = await storageProviderOperations.onChangeProjectProperty(
currentProject,
currentFileMetadata,
{ name: newName }
);
if (wasSaved) unsavedChanges.sealUnsavedChanges();
if (fileMetadataNewAttributes) {
unsavedChanges.sealUnsavedChanges();
newFileMetadata = { ...newFileMetadata, ...fileMetadataNewAttributes };
}
}
await setState(state => ({
...state,
currentFileMetadata: { ...currentFileMetadata, name: newName },
currentFileMetadata: newFileMetadata,
}));
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ export const generateOnChangeProjectProperty = (
project: gdProject,
fileMetadata: FileMetadata,
properties: {| name?: string, gameId?: string |}
): Promise<boolean> => {
if (!authenticatedUser.authenticated) return false;
): Promise<null | {| version: string |}> => {
if (!authenticatedUser.authenticated) return null;
try {
await updateCloudProject(
authenticatedUser,
Expand All @@ -138,14 +138,14 @@ export const generateOnChangeProjectProperty = (
throw new Error("Couldn't save project following property update.");
}

return true;
return { version: newVersion };
} catch (error) {
// TODO: Determine if a feedback should be given to user so that they can try again if necessary.
console.warn(
'An error occurred while changing cloud project name. Ignoring.',
error
);
return false;
return null;
}
};

Expand Down
2 changes: 1 addition & 1 deletion newIDE/app/src/ProjectsStorage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export type StorageProviderOperations = {|
project: gdProject,
fileMetadata: FileMetadata,
properties: {| name?: string, gameId?: string |} // In order to synchronize project and cloud project names.
) => Promise<boolean>,
) => Promise<null | {| version: string |}>,

// Project auto saving:
onAutoSaveProject?: (
Expand Down

0 comments on commit ac82be8

Please sign in to comment.