import * as React from 'react'; import Container from '@mui/material/Container'; import Typography from '@mui/material/Typography'; import Box from '@mui/material/Box'; import Link from '@mui/material/Link'; import {useState} from "react"; import Subscription from './Subscription'; import WsConnection from './WsConnection'; function SubscriptionList(props) { return (
{props.subscriptions.map(subscription => )}
); } function SubscriptionItem(props) { const subscription = props.subscription; return (
{subscription.shortUrl()}
); } function NotificationList(props) { return (
{props.notifications.map(notification => )}
{props.timestamp}
{props.message}
); } const NotificationItem = (props) => { return (
{props.time}
{props.message}
); } const defaultBaseUrl = "https://ntfy.sh" const SubscriptionAddForm = (props) => { const [topic, setTopic] = useState(""); const handleSubmit = (ev) => { ev.preventDefault(); props.onSubmit(new Subscription(defaultBaseUrl, topic)); setTopic(''); } return (
setTopic(ev.target.value)} placeholder="Topic name, e.g. phil_alerts" required />
); } const App = () => { const [state, setState] = useState({ subscriptions: [], }); const notifications = [ {id: "qGrfmhp3vK", times: 1645193395, message: "Message 1"}, {id: "m4YYjfxwyT", times: 1645193428, message: "Message 2"} ]; const addSubscription = (newSubscription) => { const connection = new WsConnection(newSubscription.wsUrl()); connection.start(); setState(prevState => ({ subscriptions: [...prevState.subscriptions, newSubscription], })); } return ( ntfy ); } export default App;