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(() => { useEffect(() => {
console.log("useeffect side menu 2"); 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, { webSocketContext.SendSocketMessage(SentMessagesCommands.SubscribeToTopic, {
topic: location.pathname, topic: pathname,
}); });
}, [location.pathname]); }, [location.pathname]);

View File

@ -1,7 +1,4 @@
import { import { Constants, GetUuid } from "../utils";
Constants,
GroupTasksStepsLockedAndUserUpdateInputValueRememberId,
} from "../utils";
// commands received from the backend server // commands received from the backend server
export const ReceivedMessagesCommands = { export const ReceivedMessagesCommands = {
@ -73,6 +70,12 @@ export const SentMessagesCommands = {
SubscribeToTopic: 23, 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( export function handleWebSocketMessage(
event, event,
navigate, navigate,
@ -100,7 +103,9 @@ export function handleWebSocketMessage(
body.RememberId === body.RememberId ===
groupTasksContext.startGroupTasksOpenModalRememberIdRef.current groupTasksContext.startGroupTasksOpenModalRememberIdRef.current
) { ) {
navigate(`${Constants.ROUTE_PATHS.GROUP_TASKS}/${body.Id}`); navigate(
`${Constants.ROUTE_PATHS.GROUP_TASKS}${body.Category}/view/${body.Id}`
);
} }
break; break;
case ReceivedMessagesCommands.NewGroupTaskStep: case ReceivedMessagesCommands.NewGroupTaskStep:
@ -144,7 +149,7 @@ export function handleWebSocketMessage(
break; break;
case ReceivedMessagesCommands.GroupTasksReloaded: case ReceivedMessagesCommands.GroupTasksReloaded:
if (body.RemovedCategory !== undefined) { if (body.RemovedCategory !== undefined) {
groupTasksContext.setCategoryGroups((arr) => groupTasksContext.setCategoryGroup((arr) =>
arr.filter((arr1) => arr1.category !== body.RemovedCategory) arr.filter((arr1) => arr1.category !== body.RemovedCategory)
); );
@ -183,7 +188,7 @@ export function handleWebSocketMessage(
break; break;
} }
groupTasksContext.setCategoryGroups((arr) => { groupTasksContext.setCategoryGroup((arr) => {
const newArr = [...arr]; const newArr = [...arr];
const categoryIndex = arr.findIndex( const categoryIndex = arr.findIndex(
@ -313,11 +318,11 @@ export function handleWebSocketMessage(
const stepIndex = arr.findIndex( const stepIndex = arr.findIndex(
(arr1) => (arr1) =>
arr1.GroupTasksId === body.GroupTaskId && arr1.Step === body.Step arr1.GroupTasksId === body.groupTaskId && arr1.Step === body.step
); );
if (stepIndex !== -1) { if (stepIndex !== -1) {
newArr[stepIndex].LockedByUserId = body.LockedByUserId; newArr[stepIndex].LockedByUserId = body.lockedByUserId;
} }
return newArr; return newArr;

View File

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

View File

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