diff options
author | 2023-04-11 00:46:28 +0200 | |
---|---|---|
committer | 2023-04-11 00:57:47 +0200 | |
commit | 67c8fcea43e1be97f8f05f38846a55a288801729 (patch) | |
tree | 57834432daf1f5cb3e2fee607e49b6f75279583f /helpers/windowActions.js | |
parent | f8463676a40656893c2048655e8807099e3adb39 (diff) | |
download | my_apps-67c8fcea43e1be97f8f05f38846a55a288801729.tar.gz my_apps-67c8fcea43e1be97f8f05f38846a55a288801729.tar.bz2 my_apps-67c8fcea43e1be97f8f05f38846a55a288801729.zip |
open new windows with offset position
Diffstat (limited to 'helpers/windowActions.js')
-rw-r--r-- | helpers/windowActions.js | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/helpers/windowActions.js b/helpers/windowActions.js index be60986..bb83631 100644 --- a/helpers/windowActions.js +++ b/helpers/windowActions.js @@ -2,14 +2,30 @@ export const close = (appName, setApps) => { setApps(apps => apps.filter(a => a && a.name !== appName)) } +const findSmallestMissing = (arr = []) => { + let count = 1; + if(!arr?.length){ + return count; + }; + while(arr.indexOf(count) !== -1){ + count++; + }; + return count; +}; + export const open = ({ appName, buttons, height, width }, setApps, props = {}) => { - setApps(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 }] - )) + setApps(apps => { + const untouched = apps.filter(a => a.pos.length === 1).map(a => a.pos[0]) + const newPos = findSmallestMissing(untouched); + + return ( + apps && apps.length > 0 + ? !apps.some(a => a.name === appName) + ? [...apps, { name: appName, min: false, max: false, height, width, pos: [newPos], buttons, props }] + : apps + : [{ name: appName, min: false, max: false, height, width, pos: [newPos], buttons, props }] + ) + }) } export const focus = (appName, setApps) => { |