diff options
Diffstat (limited to 'helpers')
-rw-r--r-- | helpers/windowActions.js | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/helpers/windowActions.js b/helpers/windowActions.js index 090e20a..ac86ea5 100644 --- a/helpers/windowActions.js +++ b/helpers/windowActions.js @@ -1,16 +1,20 @@ -export const close = (appName, setApps) => { setApps(apps => apps.filter(a => a && a.name !== appName)) } +export const close = (appName, setApps) => { + setApps(apps => apps.filter(a => a && a.name !== appName)) +} -export const open = ({ appName, buttons, height, width }, setApps) => { +export const open = ({ appName, buttons, height, width }, setApps, props = {}) => { setApps(apps => ( - !apps.some(a => a.name === appName) - ? [...apps, { name: appName, min: false, max: false, height, width, pos: [], buttons }] - : apps + apps && apps.length > 0 + ? !apps.some(a => a.name === appName) + ? [...apps, { name: appName, min: false, max: false, height, width, pos: [], buttons, props }] + : apps + : [{ name: appName, min: false, max: false, height, width, pos: [], buttons, props }] )) } export const focus = (appName, setApps) => { setApps(apps => { - const i = apps.findIndex(a => a.name === appName) + const i = apps.length > 0 && apps.findIndex(a => a.name === appName) return i !== apps.length - 1 ? [...apps.filter((_, n) => n !== i), apps[i]] : apps @@ -49,7 +53,7 @@ export const move = (app, winRef, setApps) => { const x = pageX - shiftX const y = pageY - shiftY - 32 - setApps(apps => ([...apps.map(a => a.name === app.name + setApps(apps => ([...apps.map(a => a && a.name === app.name ? { ...a, pos: [x + 'px', y < 0 ? 0 : y + 'px'] } : a )])) |