Skip to content

Commit

Permalink
Display organisations as table
Browse files Browse the repository at this point in the history
  • Loading branch information
Grzegorz Kupczyk committed Dec 22, 2023
1 parent 7c6441a commit c081156
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
6 changes: 3 additions & 3 deletions frontend/features/EventsSteam/EventListener.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from "react";

interface EventListenerContextData {
data: unknown;
data: any;
listener: EventSource;
}

Expand All @@ -22,13 +22,13 @@ export const EventListenerProvider = ({
url,
children,
}: EventListenerProps) => {
const [data, setData] = useState<unknown>(null);
const [data, setData] = useState<any>(null);
const [listener, setListener] = useState<EventSource | null>(null);

useEffect(() => {
const list = new EventSource(url);
list.onmessage = ({ data }) => {
setData(data);
setData(JSON.parse(data));
};
setListener(list);
}, []);
Expand Down
24 changes: 19 additions & 5 deletions frontend/pages/organisations.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Box, List, ListItem, ListItemButton, ListItemText } from "@mui/material";
import { AuthorizedLayout } from "../components/Layout";
import {
EventListenerContext,
Expand All @@ -13,11 +14,24 @@ const Organisation = () => {
<AuthorizedLayout>
<EventListenerProvider url={streamURL}>
<EventListenerContext.Consumer>
{(organizationsContext) => (
<>
Organizancje są takie o:
<pre>{JSON.stringify(organizationsContext)}</pre>
</>
{(ctx) => (
<Box
sx={{ width: "100%", maxWidth: 360, bgcolor: "#eee" }}
>
{ctx.data ? (
<List>
{(ctx.data.organisations as Array<any>).map((org) => (
<ListItem disablePadding>
<ListItemButton>
<ListItemText primary={org.organisationName} />
</ListItemButton>
</ListItem>
))}
</List>
) : (
<p>Loading</p>
)}
</Box>
)}
</EventListenerContext.Consumer>
</EventListenerProvider>
Expand Down

0 comments on commit c081156

Please sign in to comment.