add expiration interval to the map warning information element
This commit is contained in:
parent
5b83294eaf
commit
4b49b01c17
@ -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,
|
||||
]),
|
||||
);
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user