Skip to content

Commit

Permalink
Fixed save
Browse files Browse the repository at this point in the history
  • Loading branch information
robmoffat committed Apr 26, 2024
1 parent fe03fc1 commit e2b2d6c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
9 changes: 8 additions & 1 deletion packages/sail2/src/client/grid/grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@ class SimpleGrid extends Component<SimpleGridProps> {

this.props.gs.ensureGrid(
this.gridId,
(g) => this.props.cs.updatePanel(this.getPanel(g)),
(g) => {
const panel = this.getPanel(g)
panel.x = g.x
panel.y = g.y
panel.w = g.w
panel.h = g.h
this.props.cs.updatePanel(this.getPanel(g))
},
(g) => this.props.cs.removePanel(this.getPanel(g).id),
styles.grid
)
Expand Down
19 changes: 11 additions & 8 deletions packages/sail2/src/client/state/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { DirectoryApp } from "da-server"
import { GridStackPosition } from "gridstack"
import { v4 as uuid } from 'uuid'

const STORAGE_KEY = "sail-client-state"

export type AppPanel = GridStackPosition & {
title: string
url?: string,
Expand Down Expand Up @@ -39,9 +41,9 @@ export interface ClientState {

abstract class AbstractClientState implements ClientState {

private tabs: TabDetail[] = []
private panels: AppPanel[] = []
private activeTabId: string
protected tabs: TabDetail[] = []
protected panels: AppPanel[] = []
protected activeTabId: string
callbacks: (() => void)[] = []

constructor(tabs: TabDetail[], panels: AppPanel[], activeTabId: string) {
Expand Down Expand Up @@ -127,19 +129,20 @@ abstract class AbstractClientState implements ClientState {
class LocalStorageClientState extends AbstractClientState {

constructor() {
const theState = localStorage.getItem('sail-state')
const theState = localStorage.getItem(STORAGE_KEY)
if (theState) {
const { tabs, panels, activeTab } = JSON.parse(theState)
super(tabs, panels, activeTab)
const { tabs, panels, activeTabId } = JSON.parse(theState)
super(tabs, panels, activeTabId)
} else {
super(DEFAULT_TABS, DEFAULT_PANELS, DEFAULT_TABS[0].id)
}
}

saveState(): void {
localStorage.setItem('ui-state', JSON.stringify(this))
const data = JSON.stringify({ tabs: this.tabs, panels: this.panels, activeTabId: this.activeTabId })
localStorage.setItem(STORAGE_KEY, data)
this.callbacks.forEach(cb => cb())
console.log("State saved")
console.log("State saved" + data)
}

}
Expand Down

0 comments on commit e2b2d6c

Please sign in to comment.