mirror of
https://github.com/bendtherules/piktochart-create-editor.git
synced 2026-08-18 13:52:56 +00:00
Add state saving to Container
This commit is contained in:
@@ -17,7 +17,7 @@ interface CreateEditorAppState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class CreateEditorApp extends React.Component<{}, CreateEditorAppState> {
|
export class CreateEditorApp extends React.Component<{}, CreateEditorAppState> {
|
||||||
localStorageKey: 'appData';
|
localStorageKey: string = 'appData';
|
||||||
|
|
||||||
constructor(props: {}) {
|
constructor(props: {}) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ interface DragContainerState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class DragContainer extends React.Component<DragContainerProps, DragContainerState> {
|
export class DragContainer extends React.Component<DragContainerProps, DragContainerState> {
|
||||||
|
localStorageKey: string = 'containerData';
|
||||||
|
|
||||||
constructor(props: DragContainerProps) {
|
constructor(props: DragContainerProps) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
@@ -42,6 +44,30 @@ export class DragContainer extends React.Component<DragContainerProps, DragConta
|
|||||||
this.handleDragStop = this.handleDragStop.bind(this);
|
this.handleDragStop = this.handleDragStop.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
this.loadFromLocalStorage();
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidUpdate() {
|
||||||
|
this.saveToLocalStorage();
|
||||||
|
}
|
||||||
|
|
||||||
|
saveToLocalStorage() {
|
||||||
|
const pastOffsetJSON = JSON.stringify(this.state.pastCumulativeOffsetMap);
|
||||||
|
localStorage.setItem(this.localStorageKey, pastOffsetJSON);
|
||||||
|
}
|
||||||
|
|
||||||
|
loadFromLocalStorage() {
|
||||||
|
const pastOffsetJSON = localStorage.getItem(this.localStorageKey);
|
||||||
|
|
||||||
|
if (pastOffsetJSON) {
|
||||||
|
const pastOffsetObject = JSON.parse(pastOffsetJSON);
|
||||||
|
this.setState({
|
||||||
|
pastCumulativeOffsetMap: pastOffsetObject
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
handleDragStartOnDraggableNode(draggableId: string, ev: React.MouseEvent<HTMLDivElement>): void {
|
handleDragStartOnDraggableNode(draggableId: string, ev: React.MouseEvent<HTMLDivElement>): void {
|
||||||
this.setState({
|
this.setState({
|
||||||
ongoing: {
|
ongoing: {
|
||||||
|
|||||||
Reference in New Issue
Block a user