From 8c0f3b230491c7f783a67afc16eebf9c1d507ddf Mon Sep 17 00:00:00 2001 From: Philipp Heckel Date: Sat, 19 Feb 2022 22:26:58 -0500 Subject: [PATCH] Add dialog --- web/src/AddDialog.js | 55 ++++++++++++++++++++++++ web/src/App.js | 100 +++++++++++++------------------------------ web/src/Title.js | 17 -------- web/src/theme.js | 2 +- 4 files changed, 86 insertions(+), 88 deletions(-) create mode 100644 web/src/AddDialog.js delete mode 100644 web/src/Title.js diff --git a/web/src/AddDialog.js b/web/src/AddDialog.js new file mode 100644 index 0000000..b8ebe61 --- /dev/null +++ b/web/src/AddDialog.js @@ -0,0 +1,55 @@ +import * as React from 'react'; +import Button from '@mui/material/Button'; +import TextField from '@mui/material/TextField'; +import Dialog from '@mui/material/Dialog'; +import DialogActions from '@mui/material/DialogActions'; +import DialogContent from '@mui/material/DialogContent'; +import DialogContentText from '@mui/material/DialogContentText'; +import DialogTitle from '@mui/material/DialogTitle'; +import {useState} from "react"; +import Subscription from "./Subscription"; + +const defaultBaseUrl = "https://ntfy.sh" + +const AddDialog = (props) => { + const [topic, setTopic] = useState(""); + const handleCancel = () => { + setTopic(''); + props.onCancel(); + } + const handleSubmit = () => { + const subscription = new Subscription(defaultBaseUrl, topic); + props.onSubmit(subscription); + setTopic(''); + } + return ( + <> + + Subscribe to topic + + + Topics may not be password-protected, so choose a name that's not easy to guess. + Once subscribed, you can PUT/POST notifications. + + setTopic(ev.target.value)} + type="text" + fullWidth + variant="standard" + /> + + + + + + + + ); +}; + +export default AddDialog; diff --git a/web/src/App.js b/web/src/App.js index 76f0594..dfadb1c 100644 --- a/web/src/App.js +++ b/web/src/App.js @@ -4,9 +4,8 @@ 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 Subscription from './Subscription'; import WsConnection from './WsConnection'; -import {createTheme, styled, ThemeProvider} from '@mui/material/styles'; +import {styled, ThemeProvider} from '@mui/material/styles'; import CssBaseline from '@mui/material/CssBaseline'; import MuiDrawer from '@mui/material/Drawer'; import MuiAppBar from '@mui/material/AppBar'; @@ -17,7 +16,6 @@ import Divider from '@mui/material/Divider'; import IconButton from '@mui/material/IconButton'; import Badge from '@mui/material/Badge'; import Grid from '@mui/material/Grid'; -import Paper from '@mui/material/Paper'; import MenuIcon from '@mui/icons-material/Menu'; import ChevronLeftIcon from '@mui/icons-material/ChevronLeft'; import NotificationsIcon from '@mui/icons-material/Notifications'; @@ -28,19 +26,8 @@ import SettingsIcon from "@mui/icons-material/Settings"; import AddIcon from "@mui/icons-material/Add"; import Card from "@mui/material/Card"; import {Button, CardActions, CardContent, Stack} from "@mui/material"; - -function Copyright(props) { - return ( - - {'Copyright © '} - - Your Website - {' '} - {new Date().getFullYear()} - {'.'} - - ); -} +import AddDialog from "./AddDialog"; +import theme from "./theme"; const drawerWidth = 240; @@ -88,32 +75,29 @@ const Drawer = styled(MuiDrawer, { shouldForwardProp: (prop) => prop !== 'open' }), ); -const mdTheme = createTheme(); const SubscriptionNav = (props) => { const subscriptions = props.subscriptions; return ( -
+ <> {Object.keys(subscriptions).map(id => - props.handleSubscriptionClick(id)} />) } -
+ ); } -const SubscriptionItem = (props) => { +const SubscriptionNavItem = (props) => { const subscription = props.subscription; return ( - - - - - + + + ); } @@ -136,68 +120,48 @@ const NotificationItem = (props) => { {notification.time} {notification.title && - title: {notification.title} + {notification.title} } - msg: {notification.message} + {notification.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 [open, setOpen] = React.useState(true); + const [drawerOpen, setDrawerOpen] = useState(true); const [subscriptions, setSubscriptions] = useState({}); const [selectedSubscription, setSelectedSubscription] = useState(null); const [connections, setConnections] = useState({}); + const [addDialogOpen, setAddDialogOpen] = useState(false); const subscriptionChanged = (subscription) => { setSubscriptions(prev => ({...prev, [subscription.id]: subscription})); // Fake-replace }; - const addSubscription = (subscription) => { + const handleAddSubmit = (subscription) => { + setAddDialogOpen(false); const connection = new WsConnection(subscription, subscriptionChanged); setSubscriptions(prev => ({...prev, [subscription.id]: subscription})); setConnections(prev => ({...prev, [connection.id]: connection})); connection.start(); }; + const handleAddCancel = () => { + setAddDialogOpen(false); + } const handleSubscriptionClick = (subscriptionId) => { console.log(`handleSubscriptionClick ${subscriptionId}`) setSelectedSubscription(subscriptions[subscriptionId]); }; const notifications = (selectedSubscription !== null) ? selectedSubscription.notifications : []; const toggleDrawer = () => { - setOpen(!open); + setDrawerOpen(!drawerOpen); }; return ( - + - + { onClick={toggleDrawer} sx={{ marginRight: '36px', - ...(open && { display: 'none' }), + ...(drawerOpen && { display: 'none' }), }} > @@ -232,7 +196,7 @@ const App = () => { - + {
- + setAddDialogOpen(true)}> @@ -281,21 +245,17 @@ const App = () => { > - - - {/* Recent Orders */} - - - - - - + ); } diff --git a/web/src/Title.js b/web/src/Title.js deleted file mode 100644 index d686a1a..0000000 --- a/web/src/Title.js +++ /dev/null @@ -1,17 +0,0 @@ -import * as React from 'react'; -import PropTypes from 'prop-types'; -import Typography from '@mui/material/Typography'; - -function Title(props) { - return ( - - {props.children} - - ); -} - -Title.propTypes = { - children: PropTypes.node, -}; - -export default Title; diff --git a/web/src/theme.js b/web/src/theme.js index 4b65d13..d856531 100644 --- a/web/src/theme.js +++ b/web/src/theme.js @@ -8,7 +8,7 @@ const theme = createTheme({ main: '#338574', }, secondary: { - main: '#338574', + main: '#6cead0', }, error: { main: red.A400,