aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--components/App.js6
-rw-r--r--helpers/windowActions.js30
2 files changed, 26 insertions, 10 deletions
diff --git a/components/App.js b/components/App.js
index f6a297b..75bbe77 100644
--- a/components/App.js
+++ b/components/App.js
@@ -26,11 +26,11 @@ const App = ({ children, app }) => {
style={{
height: app.height,
width: app.width,
- ...app.pos.length
+ ...app.pos.length > 1
? { top: app.pos[1], left: app.pos[0] }
: {
- top: `calc((( 100vh - ${app.height} ) / 2) + 2em)`,
- left: `calc(( 100vw - ${app.width} ) / 2)`
+ top: `calc((( 100vh - ${app.height} ) / 2) + (2 * ${app.pos}rem))`,
+ left: `calc((( 100vw - ${app.width} ) / 2) + (2 * ${app.pos}rem) - 2rem)`
}
}}
>
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) => {