Skip to content

Commit

Permalink
Merge pull request #90 from perimetre/feature/Submodule-button-is-not…
Browse files Browse the repository at this point in the history
…-enabled-the-first-time-a-module-is-placed_CU-269mqzc

feature/Submodule button is not enabled the first time a module is placed CU 269mqzc
  • Loading branch information
AssisrMatheus authored Mar 9, 2022
2 parents 7980e06 + c962c82 commit 31d024a
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/components/Providers/PlannerProvider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export const PlannerProvider: React.FC<PlannerProviderProps> = ({ children, proj

const createModule = useCallback(
(module: ModuleDataFragment, rulesJson: Record<string, unknown>) => {
// setIsPending(true);
setIsPending(true);

const parentNanoId = nanoid();
const moduleJson = {
Expand Down Expand Up @@ -300,12 +300,12 @@ export const PlannerProvider: React.FC<PlannerProviderProps> = ({ children, proj

unityInstance.current?.SendMessage(UNITY_GAME_OBJECT, 'CreateModule', json);
},
[unityInstance]
[unityInstance, setIsPending]
);

const createChildrenModule = useCallback(
(module: ModuleDataFragment, rulesJson: Record<string, unknown>) => {
// setIsPending(true);
setIsPending(true);

const moduleJson = {
nanoId: nanoid(),
Expand All @@ -320,7 +320,7 @@ export const PlannerProvider: React.FC<PlannerProviderProps> = ({ children, proj

unityInstance.current?.SendMessage(UNITY_GAME_OBJECT, 'CreateChildrenModule', json);
},
[unityInstance, projectModule]
[unityInstance, projectModule, setIsPending]
);

const setupDrawer = useCallback(
Expand Down Expand Up @@ -655,13 +655,14 @@ export const PlannerProvider: React.FC<PlannerProviderProps> = ({ children, proj

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

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

if (projectModule.module.isMat) {
await handleUpsertProjectModule(projectModule, []);
// Purposefully do not await as we don't need it as dependency of anything
handleUpsertProjectModule(projectModule, []);
}
},
selectedModule: (projectModuleJson: string, childrenJson?: string) => {
Expand All @@ -671,7 +672,7 @@ export const PlannerProvider: React.FC<PlannerProviderProps> = ({ children, proj

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

// setIsPending(false);
setIsPending(false);
setProjectModule((prevProjectModule) => updateProjectModuleState(projectModule, prevProjectModule));
setChildrenModules(childrenModules?.children);
setState('Selected');
Expand All @@ -697,7 +698,8 @@ export const PlannerProvider: React.FC<PlannerProviderProps> = ({ children, proj

// Using this because putting the variable on the dependencies make the entire code not run.
if (!projectModule.module.isMat && shouldCreateOrUpdate.current) {
await handleUpsertProjectModule(projectModule, childrenModules?.children || []);
// Purposefully do not await as we don't need it as dependency of anything
handleUpsertProjectModule(projectModule, childrenModules?.children || []);
setProjectModule(undefined);
setChildrenModules(undefined);
shouldCreateOrUpdate.current = false;
Expand All @@ -712,7 +714,7 @@ export const PlannerProvider: React.FC<PlannerProviderProps> = ({ children, proj

setProjectModule((currProjectModule) => {
// Only deselect if current project module is the same that it's deleting
if (projectModule.id === currProjectModule?.id) {
if (!projectModule.module.isEdge && projectModule.id === currProjectModule?.id) {
setState('Deleted');
return undefined;
} else {
Expand All @@ -724,7 +726,9 @@ export const PlannerProvider: React.FC<PlannerProviderProps> = ({ children, proj
(x) => x.id !== projectModule.id || (childrenModules?.children || []).some((y) => y.id === x.id)
)
);
await handleDeleteProjectModule(projectModule, childrenModules?.children);

// Purposefully do not await as we don't need it as dependency of anything
handleDeleteProjectModule(projectModule, childrenModules?.children);
},
recalculatedExtensions: async (projectModuleJson: string, childrenJson: string) => {
if (!finishedSetup) return;
Expand All @@ -733,7 +737,8 @@ export const PlannerProvider: React.FC<PlannerProviderProps> = ({ children, proj

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

await handleUpsertProjectModule(projectModule, childrenModules.children);
// Purposefully do not await as we don't need it as dependency of anything
handleUpsertProjectModule(projectModule, childrenModules.children);
},
unityReady: () => {
if (!finishedSetup) {
Expand Down

0 comments on commit 31d024a

Please sign in to comment.