subscribe topics

main
alex 2023-09-02 18:40:21 +02:00
parent d432da1ee1
commit b4b0c69284
5 changed files with 24 additions and 21 deletions

View File

@ -239,12 +239,14 @@ export default function SideMenu({
useEffect(() => {
console.log("useeffect side menu 2");
setSelectedKeys(location.pathname);
const pathname = location.pathname;
lastSubscribedTopic.current = location.pathname;
setSelectedKeys(pathname);
lastSubscribedTopic.current = pathname;
webSocketContext.SendSocketMessage(SentMessagesCommands.SubscribeToTopic, {
topic: location.pathname,
topic: pathname,
});
}, [location.pathname]);

View File

@ -1,7 +1,4 @@
import {
Constants,
GroupTasksStepsLockedAndUserUpdateInputValueRememberId,
} from "../utils";
import { Constants, GetUuid } from "../utils";
// commands received from the backend server
export const ReceivedMessagesCommands = {
@ -73,6 +70,12 @@ export const SentMessagesCommands = {
SubscribeToTopic: 23,
};
/*
This ID is needed because the message is sent to all clients connected to the backend server when a task is locked and unlocked.
With this ID the client checks if the respective browser tab of the user is the initiator of the lock.
*/
export const GroupTasksStepsLockedAndUserUpdateInputValueRememberId = GetUuid();
export function handleWebSocketMessage(
event,
navigate,
@ -100,7 +103,9 @@ export function handleWebSocketMessage(
body.RememberId ===
groupTasksContext.startGroupTasksOpenModalRememberIdRef.current
) {
navigate(`${Constants.ROUTE_PATHS.GROUP_TASKS}/${body.Id}`);
navigate(
`${Constants.ROUTE_PATHS.GROUP_TASKS}${body.Category}/view/${body.Id}`
);
}
break;
case ReceivedMessagesCommands.NewGroupTaskStep:
@ -144,7 +149,7 @@ export function handleWebSocketMessage(
break;
case ReceivedMessagesCommands.GroupTasksReloaded:
if (body.RemovedCategory !== undefined) {
groupTasksContext.setCategoryGroups((arr) =>
groupTasksContext.setCategoryGroup((arr) =>
arr.filter((arr1) => arr1.category !== body.RemovedCategory)
);
@ -183,7 +188,7 @@ export function handleWebSocketMessage(
break;
}
groupTasksContext.setCategoryGroups((arr) => {
groupTasksContext.setCategoryGroup((arr) => {
const newArr = [...arr];
const categoryIndex = arr.findIndex(
@ -313,11 +318,11 @@ export function handleWebSocketMessage(
const stepIndex = arr.findIndex(
(arr1) =>
arr1.GroupTasksId === body.GroupTaskId && arr1.Step === body.Step
arr1.GroupTasksId === body.groupTaskId && arr1.Step === body.step
);
if (stepIndex !== -1) {
newArr[stepIndex].LockedByUserId = body.LockedByUserId;
newArr[stepIndex].LockedByUserId = body.lockedByUserId;
}
return newArr;

View File

@ -47,7 +47,7 @@ export default function ViewEquipmentDocumentations({
useState(false);
const [paginationPage, setPaginationPage] = useState(1);
const fetchDocumentation = (page) => {
const fetchDocumentation = (page = 1) => {
setIsEquipmentDocumentationLoading(true);
myFetch(

View File

@ -17,7 +17,6 @@ import {
FormatDatetime,
GetDuration,
getUserId,
GroupTasksStepsLockedAndUserUpdateInputValueRememberId,
hasXYPermission,
myFetch,
} from "../../../utils";
@ -37,7 +36,10 @@ import MyAttachments from "../../../Components/MyAttachments";
import { useWebSocketContext } from "../../../Contexts/WebSocketContext";
import { useGroupTasksContext } from "../../../Contexts/GroupTasksContext";
import { useAppContext } from "../../../Contexts/AppContext";
import { SentMessagesCommands } from "../../../Handlers/WebSocketMessageHandler";
import {
GroupTasksStepsLockedAndUserUpdateInputValueRememberId,
SentMessagesCommands,
} from "../../../Handlers/WebSocketMessageHandler";
export default function GroupTasksViewModal({ isOpen }) {
const webSocketContext = useWebSocketContext();

View File

@ -155,12 +155,6 @@ export const AppStyle = {
},
};
/*
This ID is needed because the message is sent to all clients connected to the backend server when a task is locked and unlocked.
With this ID the client checks if the respective browser tab of the user is the initiator of the lock.
*/
export const GroupTasksStepsLockedAndUserUpdateInputValueRememberId = GetUuid();
export function GetUuid() {
return uuidv4();
}