Skip to content

Commit

Permalink
Merge pull request #86 from perimetre/feature/Area-submodule-KnifeSpi…
Browse files Browse the repository at this point in the history
…ce-does-not-show-up-when-page-is-reloaded_CU-22hkre5

fix: fixes an issue where submodules wouldn't get saved
  • Loading branch information
AssisrMatheus authored Feb 11, 2022
2 parents ed28814 + 2957178 commit 0f57d04
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
4 changes: 2 additions & 2 deletions public/unity/Build/unity.data
Git LFS file not shown
Binary file modified public/unity/Build/unity.wasm
Binary file not shown.
45 changes: 26 additions & 19 deletions src/components/Providers/PlannerProvider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,28 @@ export const PlannerProvider: React.FC<PlannerProviderProps> = ({ children, proj

useEffect(() => {
let finishedSetup = false;

const updateProjectModuleState = (
projectModule: UnityProjectModuleJson,
prevProjectModule?: UnityProjectModuleJson,
childrenModules?: UnityProjectModuleJsonChildren
) => {
const hasModuleMoved =
prevProjectModule?.posX !== projectModule.posX ||
prevProjectModule?.posY !== projectModule.posY ||
prevProjectModule?.posZ !== projectModule.posZ ||
prevProjectModule?.rotY !== projectModule.rotY;

const isSameModule = prevProjectModule?.nanoId === projectModule.nanoId;

// Only calls upsertModule if the selected module has been moved
if (!isSameModule || (isSameModule && hasModuleMoved) || childrenModules?.children.some((x) => x.module.isEdge)) {
shouldCreateOrUpdate.current = true;
}

return projectModule;
};

/*
* Unity -> React
* */
Expand All @@ -634,7 +656,7 @@ export const PlannerProvider: React.FC<PlannerProviderProps> = ({ children, proj
console.log('createModule: ', projectModule, childrenModules);

// setIsPending(false);
setProjectModule(projectModule);
setProjectModule((prevProjectModule) => updateProjectModuleState(projectModule, prevProjectModule));
setChildrenModules(childrenModules?.children);
setState('Created');

Expand All @@ -650,21 +672,7 @@ export const PlannerProvider: React.FC<PlannerProviderProps> = ({ children, proj
console.log('selectedModule: ', projectModule, childrenModules);

// setIsPending(false);
setProjectModule((prevProjectModule) => {
// Only calls upsertModule if the selected module has been moved
if (
(prevProjectModule &&
prevProjectModule.nanoId === projectModule.nanoId &&
(prevProjectModule?.posX !== projectModule.posX ||
prevProjectModule?.posY !== projectModule.posY ||
prevProjectModule?.posZ !== projectModule.posZ ||
prevProjectModule?.rotY !== projectModule.rotY)) ||
childrenModules?.children.some((x) => x.module.isEdge)
) {
shouldCreateOrUpdate.current = true;
}
return projectModule;
});
setProjectModule((prevProjectModule) => updateProjectModuleState(projectModule, prevProjectModule));
setChildrenModules(childrenModules?.children);
setState('Selected');
},
Expand All @@ -675,7 +683,7 @@ export const PlannerProvider: React.FC<PlannerProviderProps> = ({ children, proj

console.log('editedModule: ', projectModule, childrenModules);

setProjectModule(projectModule);
setProjectModule((prevProjectModule) => updateProjectModuleState(projectModule, prevProjectModule));
setChildrenModules(childrenModules?.children);
setState('Editing');
},
Expand All @@ -692,9 +700,8 @@ export const PlannerProvider: React.FC<PlannerProviderProps> = ({ children, proj
await handleUpsertProjectModule(projectModule, childrenModules?.children || []);
setProjectModule(undefined);
setChildrenModules(undefined);
shouldCreateOrUpdate.current = false;
}

shouldCreateOrUpdate.current = false;
},
deletedModule: async (projectModuleJson: string, childrenJson?: string) => {
if (!finishedSetup) return;
Expand Down

0 comments on commit 0f57d04

Please sign in to comment.