group task typing message
parent
9aeff64a8b
commit
0e8344faaa
|
@ -588,9 +588,25 @@ function InputRequiredHandler({
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
let lastChanges = useRef([]);
|
let lastChange = useRef();
|
||||||
let typingTimer = useRef();
|
let typingTimer = useRef();
|
||||||
|
|
||||||
|
const sendTypingMessage = (
|
||||||
|
currentGroupTaskId,
|
||||||
|
groupTaskParameterName,
|
||||||
|
inputValue
|
||||||
|
) => {
|
||||||
|
webSocketContext.SendSocketMessage(SentMessagesCommands.TaskLocking, {
|
||||||
|
element: `${currentGroupTaskId}-${step}-${groupTaskParameterName}`,
|
||||||
|
lockedByUserId: getUserId(),
|
||||||
|
groupTaskId: currentGroupTaskId,
|
||||||
|
parameterName: groupTaskParameterName,
|
||||||
|
value: inputValue,
|
||||||
|
step: step,
|
||||||
|
rememberId: GroupTasksStepsLockedAndUserUpdateInputValueRememberId,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const onInputChange = (
|
const onInputChange = (
|
||||||
inputValue,
|
inputValue,
|
||||||
currentGroupTaskId,
|
currentGroupTaskId,
|
||||||
|
@ -603,43 +619,23 @@ function InputRequiredHandler({
|
||||||
|
|
||||||
if (taskLockedByUserId !== "") return;
|
if (taskLockedByUserId !== "") return;
|
||||||
|
|
||||||
lastChanges.current = lastChanges.current.filter(
|
if (Date.now() >= lastChange.current || lastChange.current === undefined) {
|
||||||
(lc) =>
|
lastChange.current = Date.now() + 1000;
|
||||||
Date.now() - new Date(lc.changeTime) < Constants.GROUP_TASK_LOCKED_TIME
|
|
||||||
);
|
|
||||||
|
|
||||||
const lastChange = lastChanges.current.find((lC) => lC.step === step);
|
sendTypingMessage(currentGroupTaskId, groupTaskParameterName, inputValue);
|
||||||
|
} else {
|
||||||
if (lastChange === undefined) {
|
|
||||||
lastChanges.current.push({
|
|
||||||
step: step,
|
|
||||||
changeTime: Date.now(),
|
|
||||||
});
|
|
||||||
|
|
||||||
webSocketContext.SendSocketMessage(SentMessagesCommands.TaskLocking, {
|
|
||||||
lockedByUserId: getUserId(),
|
|
||||||
groupTaskId: currentGroupTaskId,
|
|
||||||
step: step,
|
|
||||||
rememberId: GroupTasksStepsLockedAndUserUpdateInputValueRememberId,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// sync input value with other web clients
|
|
||||||
clearTimeout(typingTimer.current);
|
clearTimeout(typingTimer.current);
|
||||||
|
|
||||||
typingTimer.current = setTimeout(() => {
|
|
||||||
webSocketContext.SendSocketMessage(
|
|
||||||
SentMessagesCommands.UpdateGroupTaskStepUserInputValue,
|
|
||||||
{
|
|
||||||
element: `${currentGroupTaskId}-${step}-${groupTaskParameterName}`,
|
|
||||||
groupTaskId: currentGroupTaskId,
|
|
||||||
parameterName: groupTaskParameterName,
|
|
||||||
value: inputValue,
|
|
||||||
step: step,
|
|
||||||
rememberId: GroupTasksStepsLockedAndUserUpdateInputValueRememberId,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typingTimer.current = setTimeout(
|
||||||
|
() =>
|
||||||
|
sendTypingMessage(
|
||||||
|
currentGroupTaskId,
|
||||||
|
groupTaskParameterName,
|
||||||
|
inputValue
|
||||||
|
),
|
||||||
|
1000
|
||||||
);
|
);
|
||||||
}, 500);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
62
src/utils.js
62
src/utils.js
|
@ -118,7 +118,6 @@ const ReceivedMessagesCommands = {
|
||||||
UpdateScannerLastUsed: 15,
|
UpdateScannerLastUsed: 15,
|
||||||
TaskLocked: 16,
|
TaskLocked: 16,
|
||||||
TaskUnlocked: 17,
|
TaskUnlocked: 17,
|
||||||
UpdateGroupTaskStepUserInputValue: 18,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// commands sent to the backend server
|
// commands sent to the backend server
|
||||||
|
@ -128,7 +127,6 @@ export const SentMessagesCommands = {
|
||||||
TaskContinueTaskStep: 3,
|
TaskContinueTaskStep: 3,
|
||||||
ReloadGroupTasks: 4,
|
ReloadGroupTasks: 4,
|
||||||
TaskLocking: 5,
|
TaskLocking: 5,
|
||||||
UpdateGroupTaskStepUserInputValue: 6,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export function WebSocketProvider({
|
export function WebSocketProvider({
|
||||||
|
@ -324,6 +322,8 @@ export function WebSocketProvider({
|
||||||
)
|
)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
console.log("body task locked", body);
|
||||||
|
|
||||||
setGroupTasksSteps((arr) => {
|
setGroupTasksSteps((arr) => {
|
||||||
const newArr = [...arr];
|
const newArr = [...arr];
|
||||||
|
|
||||||
|
@ -337,6 +337,60 @@ export function WebSocketProvider({
|
||||||
|
|
||||||
return newArr;
|
return newArr;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// update input value
|
||||||
|
// html based DOM manipulation
|
||||||
|
const foundInput = document.getElementById(body.element);
|
||||||
|
|
||||||
|
console.log("here", foundInput);
|
||||||
|
|
||||||
|
if (foundInput) {
|
||||||
|
// this timeout is needed because the previous useState for the lockedByUserId takes some milliseconds to complete
|
||||||
|
setTimeout(() => setNativeValue(foundInput, body.value), 50);
|
||||||
|
}
|
||||||
|
|
||||||
|
// update group task step as html based DOM manipulation only works if user has no other modal open
|
||||||
|
setGroupTasksSteps((arr) => {
|
||||||
|
const newArr = [...arr];
|
||||||
|
|
||||||
|
const stepIndex = arr.findIndex(
|
||||||
|
(arr1) =>
|
||||||
|
arr1.GroupTasksId === body.groupTaskId &&
|
||||||
|
arr1.Step === body.step
|
||||||
|
);
|
||||||
|
|
||||||
|
if (stepIndex === -1) return newArr;
|
||||||
|
|
||||||
|
let inputs = [];
|
||||||
|
|
||||||
|
if (newArr[stepIndex].Inputs !== "") {
|
||||||
|
inputs = JSON.parse(newArr[stepIndex].Inputs);
|
||||||
|
}
|
||||||
|
|
||||||
|
let parameterFound = false;
|
||||||
|
|
||||||
|
for (let i = 0; i < inputs.length; i++) {
|
||||||
|
if (inputs[i].parameterName === body.parameterName) {
|
||||||
|
inputs[i].value = body.value;
|
||||||
|
parameterFound = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!parameterFound) {
|
||||||
|
let obj = {};
|
||||||
|
|
||||||
|
obj["parameterName"] = body.parameterName;
|
||||||
|
obj["value"] = body.value;
|
||||||
|
|
||||||
|
inputs.push(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
newArr[stepIndex].Inputs = JSON.stringify(inputs);
|
||||||
|
|
||||||
|
return newArr;
|
||||||
|
});
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case ReceivedMessagesCommands.TaskUnlocked:
|
case ReceivedMessagesCommands.TaskUnlocked:
|
||||||
if (
|
if (
|
||||||
|
@ -359,7 +413,7 @@ export function WebSocketProvider({
|
||||||
return newArr;
|
return newArr;
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case ReceivedMessagesCommands.UpdateGroupTaskStepUserInputValue:
|
/*case ReceivedMessagesCommands.UpdateGroupTaskStepUserInputValue:
|
||||||
if (
|
if (
|
||||||
body.rememberId ===
|
body.rememberId ===
|
||||||
GroupTasksStepsLockedAndUserUpdateInputValueRememberId
|
GroupTasksStepsLockedAndUserUpdateInputValueRememberId
|
||||||
|
@ -414,7 +468,7 @@ export function WebSocketProvider({
|
||||||
|
|
||||||
return newArr;
|
return newArr;
|
||||||
});
|
});
|
||||||
break;
|
break;*/
|
||||||
|
|
||||||
default:
|
default:
|
||||||
console.error("unknown command", cmd);
|
console.error("unknown command", cmd);
|
||||||
|
|
Loading…
Reference in New Issue