Skip to content

Commit

Permalink
Reset root node coordinates directly from file load etc instead of in…
Browse files Browse the repository at this point in the history
…directly by passing prop to DisplayedDocument
  • Loading branch information
glenreesor committed Mar 12, 2023
1 parent 30973d6 commit 4686b0b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 21 deletions.
7 changes: 2 additions & 5 deletions src/components/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function App(): m.Component {
onFileContentsRead: (fileContents) => {
importFile(fileContents);
state.ui.setCurrentModal('none');
state.ui.setResetDueToNewDoc(true);
state.canvasState.resetRootNodeCoords();

// This state change was triggered by an async fileReader
// operation, not a DOM event, thus we need to trigger
Expand All @@ -182,7 +182,7 @@ function App(): m.Component {
documentAsJson,
);
state.ui.setCurrentModal('none');
state.ui.setResetDueToNewDoc(true);
state.canvasState.resetRootNodeCoords();
}
},
},
Expand Down Expand Up @@ -254,8 +254,6 @@ function App(): m.Component {
view: (): m.Vnode => {
const documentName = state.doc.getDocName();
const hasUnsavedChanges = state.doc.hasUnsavedChanges();
const resetCanvasTranslation = state.ui.getResetDueToNewDoc();
state.ui.setResetDueToNewDoc(false);

return m(
'div',
Expand All @@ -267,7 +265,6 @@ function App(): m.Component {
DisplayedDocument,
{
documentDimensions: getDocumentDimensions(),
resetCanvasTranslation,
},
),
m(Menu),
Expand Down
5 changes: 0 additions & 5 deletions src/components/DisplayedDocument/DisplayedDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ interface Attrs {
height: number,
width: number,
},
resetCanvasTranslation: boolean,
}

/**
Expand Down Expand Up @@ -117,10 +116,6 @@ function DisplayedDocument(): m.Component<Attrs> {
},

onupdate: (vnode) => {
if (vnode.attrs.resetCanvasTranslation) {
canvasState.resetRootNodeCoords();
}

// Canvas elements reset their scale and translation when their
// dimensions change, so reset when that happens
if (
Expand Down
6 changes: 3 additions & 3 deletions src/components/menus/FileMenu.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022 Glen Reesor
// Copyright 2023 Glen Reesor
//
// This file is part of m3 Mind Mapper.
//
Expand Down Expand Up @@ -175,13 +175,13 @@ function onFileNewButtonClick() {
onYesButtonClick: () => {
state.doc.replaceCurrentDocWithNewEmptyDoc();
state.ui.setCurrentModal('none');
state.ui.setResetDueToNewDoc(true);
state.canvasState.resetRootNodeCoords();
},
onNoButtonClick: () => state.ui.setCurrentModal('none'),
});
} else {
state.doc.replaceCurrentDocWithNewEmptyDoc();
state.ui.setResetDueToNewDoc(true);
state.canvasState.resetRootNodeCoords();
}
}

Expand Down
9 changes: 1 addition & 8 deletions src/state/uiState.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022 Glen Reesor
// Copyright 2023 Glen Reesor
//
// This file is part of m3 Mind Mapper.
//
Expand Down Expand Up @@ -50,7 +50,6 @@ export default (() => {
currentMenu: MenuType,
currentModal: ModalType,
fontSize: number,
resetDueToNewDoc: boolean,
sidebarIsVisible: boolean,
}

Expand All @@ -59,7 +58,6 @@ export default (() => {
currentMenu: 'edit',
currentModal: 'none',
fontSize: 14,
resetDueToNewDoc: false,
sidebarIsVisible: false,
};

Expand All @@ -84,10 +82,5 @@ export default (() => {
setSidebarVisibility: (visible: boolean) => {
state.sidebarIsVisible = visible;
},

getResetDueToNewDoc: () => state.resetDueToNewDoc,
setResetDueToNewDoc: (value: boolean) => {
state.resetDueToNewDoc = value;
},
};
})();

0 comments on commit 4686b0b

Please sign in to comment.