Small changes
This commit is contained in:
parent
9244a65235
commit
77f1787403
39
apps/ui/web/src/app/page/PersistentEventsPage.tsx
Normal file
39
apps/ui/web/src/app/page/PersistentEventsPage.tsx
Normal file
@ -0,0 +1,39 @@
|
||||
import { useEffect } from "react";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { useStompClient } from 'react-stomp-hooks';
|
||||
import { RootState } from "../store";
|
||||
import { useWsSubscription } from "../ws/subscriptions";
|
||||
import { set } from "../store/persistent-events-slice";
|
||||
import { EventsObjectListResponse } from "../../types";
|
||||
|
||||
export default function PersistentEventsPage() {
|
||||
const dispatch = useDispatch();
|
||||
const client = useStompClient();
|
||||
const cursor = useSelector((state: RootState) => state.persistentEvents)
|
||||
|
||||
useWsSubscription<EventsObjectListResponse>("/topic/persistent/events", (response) => {
|
||||
dispatch(set(response))
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
|
||||
// Kjør din funksjon her når komponenten lastes inn for første gang
|
||||
// Sjekk om cursor er null
|
||||
if (cursor.items === null && client !== null) {
|
||||
console.log(cursor)
|
||||
// Kjør din funksjon her når cursor er null og client ikke er null
|
||||
client?.publish({
|
||||
destination: "/app/persistent/events"
|
||||
});
|
||||
|
||||
// Alternativt, du kan dispatche en Redux handling her
|
||||
// dispatch(fetchDataAction()); // Eksempel på å dispatche en handling
|
||||
}
|
||||
}, [cursor, client, dispatch]);
|
||||
|
||||
|
||||
return (
|
||||
<></>
|
||||
)
|
||||
}
|
||||
26
apps/ui/web/src/app/store/persistent-events-slice.ts
Normal file
26
apps/ui/web/src/app/store/persistent-events-slice.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import { PayloadAction, createSlice } from "@reduxjs/toolkit"
|
||||
import { EventsObjectList, EventsObjectListResponse } from "../../types";
|
||||
|
||||
interface PersistentEventsState {
|
||||
items: Array<EventsObjectList>
|
||||
lastPull: string|null
|
||||
}
|
||||
|
||||
const initialState: PersistentEventsState = {
|
||||
items: [],
|
||||
lastPull: null
|
||||
}
|
||||
|
||||
const persistentEventSlice = createSlice({
|
||||
name: "PersistentEvents",
|
||||
initialState,
|
||||
reducers: {
|
||||
set(state, action: PayloadAction<EventsObjectListResponse>) {
|
||||
state.items = action.payload.items;
|
||||
state.lastPull = action.payload.lastPull;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export const { set } = persistentEventSlice.actions;
|
||||
export default persistentEventSlice.reducer;
|
||||
Loading…
Reference in New Issue
Block a user