From 4b49b01c17fbcdd8644eaa09dcbd52e8e90e788e Mon Sep 17 00:00:00 2001 From: bedlam343 Date: Sat, 18 May 2024 17:22:28 -0700 Subject: [PATCH] add expiration interval to the map warning information element --- src/components/Widget/MapWarningWidget.tsx | 1 + src/prototype/monitor.ts | 81 +++++++++++++--------- 2 files changed, 51 insertions(+), 31 deletions(-) diff --git a/src/components/Widget/MapWarningWidget.tsx b/src/components/Widget/MapWarningWidget.tsx index 166ed46..9a5886f 100644 --- a/src/components/Widget/MapWarningWidget.tsx +++ b/src/components/Widget/MapWarningWidget.tsx @@ -48,6 +48,7 @@ const MapWarningWidget = ({ widget }: MapWarningWidgetProps) => { onExpiration: 'delete', // 3 seconds into the future expiration: new Date(Date.now() + 3000).toISOString(), + expirationInterval: 3000, } satisfies InformationElementType, ]), ); diff --git a/src/prototype/monitor.ts b/src/prototype/monitor.ts index 3b2a625..ecb2280 100644 --- a/src/prototype/monitor.ts +++ b/src/prototype/monitor.ts @@ -26,50 +26,69 @@ const monitor = ({ dispatch }: MonitorProps) => { const elementsInGaze = store.getState().gaze.elementsInGaze; const gazesAndKeys = store.getState().gaze.gazesAndKeys; - /* - * - *detect and handle interactions with elements - * - */ + * + *detect and handle interactions with elements + * + */ //detect interactions via gaze const timeSomeMsAgo = new Date(); - timeSomeMsAgo.setMilliseconds( - timeSomeMsAgo.getMilliseconds()-100, //<- 100 should be in constants file, but just testing now - );//set timeSomeMsAgo to the time it was 100 ms ago - elementsInGaze.forEach(function(elementInGaze: ElementInGaze, elementInGazeIndex:number){ - if(timeSomeMsAgo.toISOString() >= elementInGaze.timeEnteredGaze){ //has been in gaze for at least 100 ms - console.log('interacted with element '+elementInGaze.id+' using gaze'); - dispatch(updateElementExpiration(elementInGaze.widgetId, elementInGaze.id)); //update the time until expiration + // timeSomeMsAgo.setMilliseconds( + // timeSomeMsAgo.getMilliseconds() - 100, //<- 100 should be in constants file, but just testing now + // ); //set timeSomeMsAgo to the time it was 100 ms ago + elementsInGaze.forEach(function ( + elementInGaze: ElementInGaze, + elementInGazeIndex: number, + ) { + console.log('element in gaze'); + if (timeSomeMsAgo.toISOString() >= elementInGaze.timeEnteredGaze) { + //has been in gaze for at least 100 ms + console.log( + 'interacted with element ' + elementInGaze.id + ' using gaze', + ); + dispatch( + updateElementExpiration(elementInGaze.widgetId, elementInGaze.id), + ); //update the time until expiration } }); //detect interactions via key press - gazesAndKeys.forEach(function(gazeAndKey:GazeAndKey, gazeAndKeyIndex:number){ - gazeAndKey.elemsInGaze.forEach(function(elementInGaze, elementInGazeIndex){ - dispatch(updateElementExpiration(elementInGaze.widgetId, elementInGaze.id)); //update the time until expiration - console.log('interacted with element '+elementInGaze.id+' using '+gazeAndKey.keyPress); - }); + gazesAndKeys.forEach(function ( + gazeAndKey: GazeAndKey, + gazeAndKeyIndex: number, + ) { + gazeAndKey.elemsInGaze.forEach( + function (elementInGaze, elementInGazeIndex) { + dispatch( + updateElementExpiration(elementInGaze.widgetId, elementInGaze.id), + ); //update the time until expiration + console.log( + 'interacted with element ' + + elementInGaze.id + + ' using ' + + gazeAndKey.keyPress, + ); + }, + ); }); - - - - Object.keys(widgets).forEach((widgetId) => { //update widgets and elements that haven't been interacted with + Object.keys(widgets).forEach((widgetId) => { + //update widgets and elements that haven't been interacted with const widget = widgets[widgetId]; - widget.elements.forEach((element:BaseElement, elementIndex:number) => { + widget.elements.forEach((element: BaseElement, elementIndex: number) => { //go through each element - if (element.expiration && !element.interacted) {//if it has an expiration and has not been interacted with + if (element.expiration && !element.interacted) { + //if it has an expiration and has not been interacted with const time = new Date().toISOString(); if (element.expiration <= time) { - - switch(element.onExpiration){ + switch (element.onExpiration) { case 'delete': console.log('element ' + element.id + ' expired! deleting...'); - if (widget.elements.length === 1) { //if this is the last element, delete the whole widget + if (widget.elements.length === 1) { + //if this is the last element, delete the whole widget dispatch(removeWidget(widget.id)); } else { dispatch(deleteElementFromWidget(widgetId, element.id)); //delete the widget @@ -77,12 +96,12 @@ const monitor = ({ dispatch }: MonitorProps) => { break; case 'escalate': console.log('element ' + element.id + ' expired! escalating...'); - dispatch(escalateElement(widget.id, element.id)); + dispatch(escalateElement(widget.id, element.id)); + break; + case 'deescalate': + console.log('element ' + element.id + ' expired! escalating...'); + dispatch(deescalateElement(widget.id, element.id)); break; - case 'deescalate': - console.log('element ' + element.id + ' expired! escalating...'); - dispatch(deescalateElement(widget.id, element.id)); - break; } } }