aboutsummaryrefslogtreecommitdiffstats
path: root/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'helpers')
-rw-r--r--helpers/appList.js8
-rw-r--r--helpers/queue.js53
-rw-r--r--helpers/windowActions.js54
3 files changed, 101 insertions, 14 deletions
diff --git a/helpers/appList.js b/helpers/appList.js
new file mode 100644
index 0000000..a114a70
--- /dev/null
+++ b/helpers/appList.js
@@ -0,0 +1,8 @@
+import {Notes, Settings} from 'apps'
+
+const appList = {
+ Notes: {component: Notes, icon: true, buttons: ['min', 'max', 'close'], height: '64em', width: '64em'},
+ Settings: {component: Settings, icon: false, buttons: ['min'], height: '23em', width: '20em'},
+};
+
+export default appList
diff --git a/helpers/queue.js b/helpers/queue.js
new file mode 100644
index 0000000..69e708a
--- /dev/null
+++ b/helpers/queue.js
@@ -0,0 +1,53 @@
+class Queue {
+ static queue = [];
+ static pendingPromise = false;
+ static stop = false;
+
+ static enqueue(promise) {
+ return new Promise((resolve, reject) => {
+ this.queue.push({
+ promise,
+ resolve,
+ reject
+ });
+ this.dequeue();
+ });
+ }
+
+ static dequeue() {
+ if (this.workingOnPromise) {
+ return false;
+ }
+ if (this.stop) {
+ this.queue = [];
+ this.stop = false;
+ return;
+ }
+ const item = this.queue.shift();
+ if (!item) {
+ return false;
+ }
+ try {
+ this.workingOnPromise = true;
+ item
+ .promise()
+ .then((value) => {
+ this.workingOnPromise = false;
+ item.resolve(value);
+ this.dequeue();
+ })
+ .catch((err) => {
+ this.workingOnPromise = false;
+ item.reject(err);
+ this.dequeue();
+ });
+ } catch (err) {
+ this.workingOnPromise = false;
+ item.reject(err);
+ this.dequeue();
+ }
+ return true;
+ }
+}
+
+export default Queue
diff --git a/helpers/windowActions.js b/helpers/windowActions.js
index 60e697c..8ff361b 100644
--- a/helpers/windowActions.js
+++ b/helpers/windowActions.js
@@ -1,33 +1,59 @@
-export const toggleMin = (appName, apps, setApps) => setApps([
- ...apps.map(a => a.name === appName ? {...a, min: !a.min} : a )
-])
+export const close = (appName, setApps) => {setApps(apps => apps.filter(a => a.name !== appName))}
-export const toggleMax = (appName, apps, setApps) => setApps([
- ...apps.map(a => a.name === appName ? {...a, max: !a.max} : a )
-])
+export const open = ({appName, buttons, height, width}, setApps) => {
+ setApps(apps => (
+ !apps.some(a => a.name === appName)
+ ? [...apps, {name: appName, min: false, max: false, height, width, pos: [], buttons}]
+ : apps
+ ))
+}
-export const close = (appName, apps, setApps) => { setApps(apps.filter(a => a.name !== appName)) }
+export const focus = (appName, setApps) => {
+ setApps(apps => {
+ const i = apps.findIndex(a => a.name === appName)
+ return i !== apps.length - 1
+ ? [...apps.filter((_,n) => n !== i), apps[i]]
+ : apps
+ })
+}
+
+export const unfocus = (appName, setApps) => {
+ setApps(apps => {
+ const i = apps.findIndex(a => a.name === appName)
+ return i !== 0
+ ? [apps[i], ...apps.filter((_,n) => n !== i)]
+ : apps
+ })
+}
-export const open = (appName, apps, setApps) => {
- apps.some(app => app.name === appName)
- ? toggleMin(appName, apps, setApps)
- : setApps([...apps, {name: appName, min: false, max: false, pos: []}])
+export const toggleMin = (appName, setApps) => {
+ setApps(apps => ([
+ ...apps.map(a => a.name === appName ? {...a, min: !a.min} : a )
+ ]))
+ unfocus(appName, setApps)
}
-export const move = (appName, winRef, apps, setApps) => {
+export const toggleMax = (appName, setApps) => setApps(apps => ([
+ ...apps.map(a => a.name === appName ? {...a, max: !a.max} : a )
+]))
+
+
+export const move = (appName, winRef, setApps) => {
winRef.current.onmousedown = (event) => {
if (event.target.classList && event.target.classList.contains('window__title')) {
const shiftX = event.clientX - winRef.current.getBoundingClientRect().left
const shiftY = event.clientY - winRef.current.getBoundingClientRect().top
winRef.current.classList.add('moving')
+ focus(appName, setApps)
function moveAt(pageX, pageY) {
const x = pageX - shiftX
const y = pageY - shiftY - 32
- setApps([...apps.map(a => a.name === appName
+
+ setApps(apps => ([...apps.map(a => a.name === appName
? {...a, pos: [x + 'px', y < 0 ? 0 : y + 'px']}
: a
- )])
+ )]))
}
const onMouseMove = (event) => {