users/ryan/modules/simple-bar/simple-bar-source/lib/components/missives/missives.jsx
2bead7efb473f0202dc6ef189fbc0e4a5401d41f
· 1.2 KB · 40 lines
raw
| 1 | import * as Uebersicht from "uebersicht"; |
| 2 | import { useSimpleBarContext } from "../simple-bar-context.jsx"; |
| 3 | import Missive from "./missive.jsx"; |
| 4 | import useServerSocket from "../../hooks/use-server-socket.js"; |
| 5 | |
| 6 | export { missivesStyles as styles } from "../../styles/components/missives"; |
| 7 | |
| 8 | const { React } = Uebersicht; |
| 9 | |
| 10 | /** |
| 11 | * Component to display a list of missives. |
| 12 | * It uses the simple-bar context to get settings and missives data. |
| 13 | * It also sets up a server socket to receive new missives. |
| 14 | * |
| 15 | * @returns {JSX.Element} The rendered component. |
| 16 | */ |
| 17 | export function Component() { |
| 18 | // Destructure settings, missives, and pushMissive function from the context |
| 19 | const { settings, missives, pushMissive } = useSimpleBarContext(); |
| 20 | const { enableServer } = settings.global; |
| 21 | |
| 22 | // Set up a server socket to listen for "missive" events and push new missives |
| 23 | useServerSocket("missive", enableServer, pushMissive); |
| 24 | |
| 25 | return ( |
| 26 | <div className="missives"> |
| 27 | {missives.map(({ id, side, content, timeout }) => { |
| 28 | return ( |
| 29 | <Missive |
| 30 | key={id} |
| 31 | id={id} |
| 32 | side={side} |
| 33 | content={content} |
| 34 | timeout={timeout} |
| 35 | /> |
| 36 | ); |
| 37 | })} |
| 38 | </div> |
| 39 | ); |
| 40 | } |