1
1
import { produce } from 'solid-js/store' ;
2
2
import { defineStore } from 'solidjs-storex' ;
3
+ import windowPreferencesStore , { findWindowPreferences } from './windowPreferencesStore' ;
3
4
4
5
type WindowState = {
5
6
windows : WindowsObject ;
@@ -21,6 +22,8 @@ interface WindowAttrs {
21
22
key : string ;
22
23
}
23
24
25
+ const [ windowPreferencesState , { save : saveWindowPreferences } ] = windowPreferencesStore ( ) ;
26
+
24
27
export default defineStore ( {
25
28
state : {
26
29
windows : { } ,
@@ -53,6 +56,7 @@ export default defineStore({
53
56
} ,
54
57
moveWindow : ( key , pos ) => {
55
58
set ( 'windows' , key , 'attrs' , 'pos' , pos ) ;
59
+ saveWindowPreferences ( state . windows [ key ] . component , ( attrs ) => ( { ...attrs , pos : state . windows [ key ] . attrs . pos } ) ) ;
56
60
} ,
57
61
resizeWindow : ( key , size ) => {
58
62
const minWidth = 300 ;
@@ -61,6 +65,10 @@ export default defineStore({
61
65
let newSize = [ ...size ( currentSize ) ] ;
62
66
return [ newSize [ 0 ] < minWidth ? minWidth : newSize [ 0 ] , newSize [ 1 ] < minHeight ? minHeight : newSize [ 1 ] ] ;
63
67
} ) ;
68
+ saveWindowPreferences ( state . windows [ key ] . component , ( attrs ) => ( {
69
+ ...attrs ,
70
+ size : state . windows [ key ] . attrs . size ,
71
+ } ) ) ;
64
72
} ,
65
73
focusWindow : ( key ) => {
66
74
Object . keys ( state ?. windows || { } ) . forEach ( ( item ) => {
@@ -72,16 +80,24 @@ export default defineStore({
72
80
} ) ;
73
81
74
82
const getDefaultWindowsAttrs = ( props ) : WindowAttrs => {
75
- // TODO: get last window pos based on comp name
76
- return {
83
+ const defaultAttrs : WindowAttrs = {
77
84
minimized : false ,
85
+ // TODO: calculate center of window minus half window size
78
86
// pos: [window.innerWidth / 2 || 200, window.innerHeight / 2 || 200],
79
87
pos : [ 200 , 200 ] ,
80
88
size : [ 500 , 400 ] ,
81
89
zIndex : 1 ,
82
90
icon : null ,
83
91
key : '' ,
84
92
} ;
93
+ if ( props . component ) {
94
+ let preferences = findWindowPreferences ( windowPreferencesState , props . component ) ;
95
+ if ( preferences ) {
96
+ if ( preferences . pos ) defaultAttrs . pos = preferences . pos ;
97
+ if ( preferences . size ) defaultAttrs . size = preferences . size ;
98
+ }
99
+ }
100
+ return defaultAttrs ;
85
101
} ;
86
102
87
103
const generateWindowKey = ( props ) => {
0 commit comments