-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…iew-settings-provider [READY_TO_REVIEW]feature/#453 Refactor canvas view settings provider
- Loading branch information
Showing
9 changed files
with
92 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 14 additions & 4 deletions
18
src/core/providers/canvas-view-settings/canvas-view-settings.model.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,47 @@ | ||
import { retrieveValueFromLocalStorage } from '@/common/local-storage'; | ||
import { Coords, Size } from '@/core/model'; | ||
|
||
export interface CanvasViewSettingsModel { | ||
canvasSize: Size; | ||
viewBoxSize: Size; | ||
zoomFactor: number; | ||
scrollPosition: Coords; | ||
filename: string; | ||
loadSample: boolean; | ||
autoSave: boolean; | ||
} | ||
|
||
// This canvas size is used to calc table sizes, etc... | ||
// on the Canvas itself we will use a huge canvas in order to avoid having issues when zooming (Canvas_Max_Width and height...) | ||
const CANVAS_SIZE = { width: 5000, height: 5000 }; | ||
|
||
export const USERSAVE_KEY = 'userSettings'; | ||
|
||
const savedSettingsObject = retrieveValueFromLocalStorage(USERSAVE_KEY); | ||
|
||
const initialAutoSaveValue = | ||
savedSettingsObject && savedSettingsObject.autoSave !== undefined | ||
? savedSettingsObject.autoSave | ||
: true; | ||
|
||
export const createInitialSettings = (DEFAULT_ZOOM_FACTOR: number) => ({ | ||
canvasSize: CANVAS_SIZE, | ||
viewBoxSize: { width: 0, height: 0 }, | ||
zoomFactor: DEFAULT_ZOOM_FACTOR, | ||
scrollPosition: { x: 0, y: 0 }, | ||
filename: '', | ||
loadSample: true, | ||
autoSave: initialAutoSaveValue, | ||
}); | ||
|
||
export interface CanvasViewSettingsContextModel { | ||
canvasViewSettings: CanvasViewSettingsModel; | ||
scrollPosition: Coords; | ||
filename: string; | ||
setScrollPosition: (scrollPosition: Coords) => void; | ||
setCanvasSize: (canvasSize: Size) => void; | ||
setFilename: (filename: string) => void; | ||
zoomIn: () => void; | ||
zoomOut: () => void; | ||
setLoadSample: (loadSample: boolean) => void; | ||
viewBoxSize: Size; | ||
setViewBoxSize: (viewBoxSize: Size) => void; | ||
autoSave: boolean; | ||
setAutoSave: (autoSave: boolean) => void; | ||
} |
Oops, something went wrong.