From 31e7aa24bcf9d5c2bb14a5e7543e27ad5be52dd4 Mon Sep 17 00:00:00 2001 From: Philipp Heckel Date: Fri, 18 Feb 2022 11:07:04 -0500 Subject: [PATCH] Subscription form --- web/src/App.js | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/web/src/App.js b/web/src/App.js index 0d0dfb45..7d52df94 100644 --- a/web/src/App.js +++ b/web/src/App.js @@ -4,6 +4,7 @@ import Typography from '@mui/material/Typography'; import Box from '@mui/material/Box'; import Link from '@mui/material/Link'; import ProTip from './ProTip'; +import {useState} from "react"; function Copyright() { return ( @@ -57,22 +58,53 @@ function NotificationItem(props) { ); } +function SubscriptionAddForm(props) { + const [topic, setTopic] = useState(""); + const handleSubmit = (ev) => { + ev.preventDefault(); + props.onSubmit({ + base_url: "https://ntfy.sh", + topic: topic, + }); + } + return ( +
+ setTopic(ev.target.value)} + placeholder="Topic name, e.g. phil_alerts" + required + /> +
+ ); +} + export default function App() { - const subscriptions = [ + const [state, setState] = useState({ + subscriptions: [], + }); + /*const subscriptions = [ {base_url: "https://ntfy.sh", topic: "mytopic"}, {base_url: "https://ntfy.sh", topic: "phils_alerts"}, - ]; + ];*/ const notifications = [ {id: "qGrfmhp3vK", times: 1645193395, message: "Message 1"}, {id: "m4YYjfxwyT", times: 1645193428, message: "Message 2"} ]; + const addSubscription = (newSubscription) => { + setState(prevState => ({ + subscriptions: [...prevState.subscriptions, newSubscription], + })); + } return ( ntfy - + +