Switch everything to Dexie.js
This commit is contained in:
parent
39f4613719
commit
349872bdb3
16 changed files with 243 additions and 316 deletions
|
@ -7,10 +7,11 @@ import Typography from "@mui/material/Typography";
|
|||
import IconSubscribeSettings from "./IconSubscribeSettings";
|
||||
import * as React from "react";
|
||||
import Box from "@mui/material/Box";
|
||||
import {topicShortUrl} from "../app/utils";
|
||||
|
||||
const ActionBar = (props) => {
|
||||
const title = (props.selectedSubscription !== null)
|
||||
? props.selectedSubscription.shortUrl()
|
||||
const title = (props.selectedSubscription)
|
||||
? topicShortUrl(props.selectedSubscription.baseUrl, props.selectedSubscription.topic)
|
||||
: "ntfy";
|
||||
return (
|
||||
<AppBar position="fixed" sx={{
|
||||
|
@ -37,7 +38,6 @@ const ActionBar = (props) => {
|
|||
</Typography>
|
||||
{props.selectedSubscription !== null && <IconSubscribeSettings
|
||||
subscription={props.selectedSubscription}
|
||||
onClearAll={props.onClearAll}
|
||||
onUnsubscribe={props.onUnsubscribe}
|
||||
/>}
|
||||
</Toolbar>
|
||||
|
@ -45,17 +45,4 @@ const ActionBar = (props) => {
|
|||
);
|
||||
};
|
||||
|
||||
/*
|
||||
To add a top left corner logo box:
|
||||
<Typography variant="h5" noWrap component="div" sx={{
|
||||
display: { xs: 'none', sm: 'block' },
|
||||
width: { sm: `${Navigation.width}px` }
|
||||
}}>
|
||||
ntfy
|
||||
</Typography>
|
||||
|
||||
To make the size of the top bar dynamic based on the drawer:
|
||||
width: { sm: `calc(100% - ${Navigation.width}px)` }
|
||||
*/
|
||||
|
||||
export default ActionBar;
|
||||
|
|
|
@ -6,10 +6,8 @@ import CssBaseline from '@mui/material/CssBaseline';
|
|||
import Toolbar from '@mui/material/Toolbar';
|
||||
import Notifications from "./Notifications";
|
||||
import theme from "./theme";
|
||||
import api from "../app/Api";
|
||||
import repository from "../app/Repository";
|
||||
import prefs from "../app/Prefs";
|
||||
import connectionManager from "../app/ConnectionManager";
|
||||
import Subscriptions from "../app/Subscriptions";
|
||||
import Navigation from "./Navigation";
|
||||
import ActionBar from "./ActionBar";
|
||||
import notificationManager from "../app/NotificationManager";
|
||||
|
@ -17,52 +15,52 @@ import NoTopics from "./NoTopics";
|
|||
import Preferences from "./Preferences";
|
||||
import db from "../app/db";
|
||||
import {useLiveQuery} from "dexie-react-hooks";
|
||||
import {topicUrl} from "../app/utils";
|
||||
import poller from "../app/Poller";
|
||||
import pruner from "../app/Pruner";
|
||||
|
||||
// TODO subscribe dialog:
|
||||
// - check/use existing user
|
||||
// - add baseUrl
|
||||
// TODO embed into ntfy server
|
||||
// TODO make default server functional
|
||||
// TODO indexeddb for notifications + subscriptions
|
||||
// TODO business logic with callbacks
|
||||
// TODO connection indicator in subscription list
|
||||
// TODO connectionmanager should react on users changes
|
||||
// TODO attachments
|
||||
|
||||
const App = () => {
|
||||
console.log(`[App] Rendering main view`);
|
||||
|
||||
const [mobileDrawerOpen, setMobileDrawerOpen] = useState(false);
|
||||
const [prefsOpen, setPrefsOpen] = useState(false);
|
||||
const [subscriptions, setSubscriptions] = useState(new Subscriptions());
|
||||
const [selectedSubscription, setSelectedSubscription] = useState(null);
|
||||
const [notificationsGranted, setNotificationsGranted] = useState(notificationManager.granted());
|
||||
const subscriptions = useLiveQuery(() => db.subscriptions.toArray());
|
||||
const users = useLiveQuery(() => db.users.toArray());
|
||||
const handleSubscriptionClick = (subscriptionId) => {
|
||||
setSelectedSubscription(subscriptions.get(subscriptionId));
|
||||
const handleSubscriptionClick = async (subscriptionId) => {
|
||||
const subscription = await db.subscriptions.get(subscriptionId); // FIXME
|
||||
setSelectedSubscription(subscription);
|
||||
setPrefsOpen(false);
|
||||
}
|
||||
const handleSubscribeSubmit = (subscription) => {
|
||||
console.log(`[App] New subscription: ${subscription.id}`);
|
||||
setSubscriptions(prev => prev.add(subscription).clone());
|
||||
const handleSubscribeSubmit = async (subscription) => {
|
||||
console.log(`[App] New subscription: ${subscription.id}`, subscription);
|
||||
await db.subscriptions.put(subscription); // FIXME
|
||||
setSelectedSubscription(subscription);
|
||||
poll(subscription);
|
||||
handleRequestPermission();
|
||||
try {
|
||||
await poller.poll(subscription);
|
||||
} catch (e) {
|
||||
console.error(`[App] Error polling newly added subscription ${subscription.id}`, e);
|
||||
}
|
||||
};
|
||||
const handleDeleteNotification = (subscriptionId, notificationId) => {
|
||||
console.log(`[App] Deleting notification ${notificationId} from ${subscriptionId}`);
|
||||
db.notifications.delete(notificationId); // FIXME
|
||||
};
|
||||
const handleDeleteAllNotifications = (subscriptionId) => {
|
||||
console.log(`[App] Deleting all notifications from ${subscriptionId}`);
|
||||
db.notifications.where({subscriptionId}).delete(); // FIXME
|
||||
};
|
||||
const handleUnsubscribe = (subscriptionId) => {
|
||||
const handleUnsubscribe = async (subscriptionId) => {
|
||||
console.log(`[App] Unsubscribing from ${subscriptionId}`);
|
||||
setSubscriptions(prev => {
|
||||
const newSubscriptions = prev.remove(subscriptionId).clone();
|
||||
setSelectedSubscription(newSubscriptions.firstOrNull());
|
||||
return newSubscriptions;
|
||||
});
|
||||
await db.subscriptions.delete(subscriptionId); // FIXME
|
||||
await db.notifications
|
||||
.where({subscriptionId: subscriptionId})
|
||||
.delete(); // FIXME
|
||||
const newSelected = await db.subscriptions.toCollection().first(); // FIXME May be undefined
|
||||
setSelectedSubscription(newSelected);
|
||||
};
|
||||
const handleRequestPermission = () => {
|
||||
notificationManager.maybeRequestPermission((granted) => {
|
||||
|
@ -73,61 +71,41 @@ const App = () => {
|
|||
setPrefsOpen(true);
|
||||
setSelectedSubscription(null);
|
||||
};
|
||||
const poll = (subscription) => {
|
||||
const since = subscription.last;
|
||||
api.poll(subscription.baseUrl, subscription.topic, since)
|
||||
.then(notifications => {
|
||||
setSubscriptions(prev => {
|
||||
subscription.addNotifications(notifications);
|
||||
const subscriptionId = topicUrl(subscription.baseUrl, subscription.topic);
|
||||
const notificationsWithSubscriptionId = notifications
|
||||
.map(notification => ({ ...notification, subscriptionId }));
|
||||
db.notifications.bulkPut(notificationsWithSubscriptionId); // FIXME
|
||||
return prev.update(subscription).clone();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Define hooks: Note that the order of the hooks is important. The "loading" hooks
|
||||
// must be before the "saving" hooks.
|
||||
useEffect(() => {
|
||||
poller.startWorker();
|
||||
pruner.startWorker();
|
||||
const load = async () => {
|
||||
// Load subscriptions
|
||||
const subscriptions = repository.loadSubscriptions();
|
||||
const selectedSubscriptionId = await repository.getSelectedSubscriptionId();
|
||||
setSubscriptions(subscriptions);
|
||||
const subs = await db.subscriptions.toArray(); // Cannot be 'subscriptions'
|
||||
const selectedSubscriptionId = await prefs.selectedSubscriptionId();
|
||||
|
||||
// Set selected subscription
|
||||
const maybeSelectedSubscription = subscriptions.get(selectedSubscriptionId);
|
||||
if (maybeSelectedSubscription) {
|
||||
setSelectedSubscription(maybeSelectedSubscription);
|
||||
const maybeSelectedSubscription = subs?.filter(s => s.id = selectedSubscriptionId);
|
||||
if (maybeSelectedSubscription.length > 0) {
|
||||
setSelectedSubscription(maybeSelectedSubscription[0]);
|
||||
}
|
||||
|
||||
// Poll all subscriptions
|
||||
subscriptions.forEach((subscriptionId, subscription) => {
|
||||
poll(subscription);
|
||||
});
|
||||
};
|
||||
load();
|
||||
setTimeout(() => load(), 5000);
|
||||
}, [/* initial render */]);
|
||||
useEffect(() => {
|
||||
const notificationClickFallback = (subscription) => setSelectedSubscription(subscription);
|
||||
const handleNotification = (subscriptionId, notification) => {
|
||||
db.notifications.put({ ...notification, subscriptionId }); // FIXME
|
||||
setSubscriptions(prev => {
|
||||
const subscription = prev.get(subscriptionId);
|
||||
if (subscription.addNotification(notification)) {
|
||||
notificationManager.notify(subscription, notification, notificationClickFallback)
|
||||
}
|
||||
return prev.update(subscription).clone();
|
||||
});
|
||||
const handleNotification = async (subscriptionId, notification) => {
|
||||
try {
|
||||
const subscription = await db.subscriptions.get(subscriptionId); // FIXME
|
||||
await db.notifications.add({ ...notification, subscriptionId }); // FIXME, will throw if exists!
|
||||
await db.subscriptions.update(subscriptionId, { last: notification.id });
|
||||
await notificationManager.notify(subscription, notification, notificationClickFallback)
|
||||
} catch (e) {
|
||||
console.error(`[App] Error handling notification`, e);
|
||||
}
|
||||
};
|
||||
connectionManager.refresh(subscriptions, users, handleNotification);
|
||||
}, [subscriptions, users]);
|
||||
useEffect(() => repository.saveSubscriptions(subscriptions), [subscriptions]);
|
||||
useEffect(() => {
|
||||
const subscriptionId = (selectedSubscription) ? selectedSubscription.id : "";
|
||||
repository.setSelectedSubscriptionId(subscriptionId)
|
||||
prefs.setSelectedSubscriptionId(subscriptionId)
|
||||
}, [selectedSubscription]);
|
||||
|
||||
return (
|
||||
|
@ -137,7 +115,6 @@ const App = () => {
|
|||
<CssBaseline/>
|
||||
<ActionBar
|
||||
selectedSubscription={selectedSubscription}
|
||||
onClearAll={handleDeleteAllNotifications}
|
||||
onUnsubscribe={handleUnsubscribe}
|
||||
onMobileDrawerToggle={() => setMobileDrawerOpen(!mobileDrawerOpen)}
|
||||
/>
|
||||
|
@ -155,45 +132,46 @@ const App = () => {
|
|||
onRequestPermissionClick={handleRequestPermission}
|
||||
/>
|
||||
</Box>
|
||||
<Box
|
||||
component="main"
|
||||
sx={{
|
||||
display: 'flex',
|
||||
flexGrow: 1,
|
||||
flexDirection: 'column',
|
||||
padding: 3,
|
||||
width: {sm: `calc(100% - ${Navigation.width}px)`},
|
||||
height: '100vh',
|
||||
overflow: 'auto',
|
||||
backgroundColor: (theme) => theme.palette.mode === 'light' ? theme.palette.grey[100] : theme.palette.grey[900]
|
||||
}}
|
||||
>
|
||||
<Main>
|
||||
<Toolbar/>
|
||||
<MainContent
|
||||
<Content
|
||||
subscription={selectedSubscription}
|
||||
prefsOpen={prefsOpen}
|
||||
onDeleteNotification={handleDeleteNotification}
|
||||
/>
|
||||
</Box>
|
||||
</Main>
|
||||
</Box>
|
||||
</ThemeProvider>
|
||||
);
|
||||
}
|
||||
|
||||
const MainContent = (props) => {
|
||||
const Main = (props) => {
|
||||
return (
|
||||
<Box
|
||||
component="main"
|
||||
sx={{
|
||||
display: 'flex',
|
||||
flexGrow: 1,
|
||||
flexDirection: 'column',
|
||||
padding: 3,
|
||||
width: {sm: `calc(100% - ${Navigation.width}px)`},
|
||||
height: '100vh',
|
||||
overflow: 'auto',
|
||||
backgroundColor: (theme) => theme.palette.mode === 'light' ? theme.palette.grey[100] : theme.palette.grey[900]
|
||||
}}
|
||||
>
|
||||
{props.children}
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
const Content = (props) => {
|
||||
if (props.prefsOpen) {
|
||||
return <Preferences/>;
|
||||
}
|
||||
if (props.subscription !== null) {
|
||||
return (
|
||||
<Notifications
|
||||
subscription={props.subscription}
|
||||
onDeleteNotification={props.onDeleteNotification}
|
||||
/>
|
||||
);
|
||||
} else {
|
||||
return <NoTopics/>;
|
||||
if (props.subscription) {
|
||||
return <Notifications subscription={props.subscription}/>;
|
||||
}
|
||||
return <NoTopics/>;
|
||||
};
|
||||
|
||||
export default App;
|
||||
|
|
|
@ -9,6 +9,7 @@ import MenuList from '@mui/material/MenuList';
|
|||
import IconButton from "@mui/material/IconButton";
|
||||
import MoreVertIcon from "@mui/icons-material/MoreVert";
|
||||
import api from "../app/Api";
|
||||
import db from "../app/db";
|
||||
|
||||
// Originally from https://mui.com/components/menus/#MenuListComposition.js
|
||||
const IconSubscribeSettings = (props) => {
|
||||
|
@ -28,7 +29,10 @@ const IconSubscribeSettings = (props) => {
|
|||
|
||||
const handleClearAll = (event) => {
|
||||
handleClose(event);
|
||||
props.onClearAll(props.subscription.id);
|
||||
console.log(`[IconSubscribeSettings] Deleting all notifications from ${props.subscription.id}`);
|
||||
db.notifications
|
||||
.where({subscriptionId: props.subscription.id})
|
||||
.delete(); // FIXME
|
||||
};
|
||||
|
||||
const handleUnsubscribe = (event) => {
|
||||
|
@ -59,7 +63,6 @@ const IconSubscribeSettings = (props) => {
|
|||
if (prevOpen.current === true && open === false) {
|
||||
anchorRef.current.focus();
|
||||
}
|
||||
|
||||
prevOpen.current = open;
|
||||
}, [open]);
|
||||
|
||||
|
@ -71,9 +74,6 @@ const IconSubscribeSettings = (props) => {
|
|||
edge="end"
|
||||
ref={anchorRef}
|
||||
id="composition-button"
|
||||
aria-controls={open ? 'composition-menu' : undefined}
|
||||
aria-expanded={open ? 'true' : undefined}
|
||||
aria-haspopup="true"
|
||||
onClick={handleToggle}
|
||||
>
|
||||
<MoreVertIcon/>
|
||||
|
@ -99,7 +99,6 @@ const IconSubscribeSettings = (props) => {
|
|||
<MenuList
|
||||
autoFocusItem={open}
|
||||
id="composition-menu"
|
||||
aria-labelledby="composition-button"
|
||||
onKeyDown={handleListKeyDown}
|
||||
>
|
||||
<MenuItem onClick={handleSendTestMessage}>Send test notification</MenuItem>
|
||||
|
|
|
@ -14,6 +14,7 @@ import SubscribeDialog from "./SubscribeDialog";
|
|||
import {Alert, AlertTitle, ListSubheader} from "@mui/material";
|
||||
import Button from "@mui/material/Button";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import {topicShortUrl} from "../app/utils";
|
||||
|
||||
const navWidth = 240;
|
||||
|
||||
|
@ -61,8 +62,8 @@ const NavList = (props) => {
|
|||
handleSubscribeReset();
|
||||
props.onSubscribeSubmit(subscription);
|
||||
}
|
||||
const showSubscriptionsList = props.subscriptions.size() > 0;
|
||||
const showGrantPermissionsBox = props.subscriptions.size() > 0 && !props.notificationsGranted;
|
||||
const showSubscriptionsList = props.subscriptions?.length > 0;
|
||||
const showGrantPermissionsBox = props.subscriptions?.length > 0 && !props.notificationsGranted;
|
||||
return (
|
||||
<>
|
||||
<Toolbar sx={{
|
||||
|
@ -115,14 +116,14 @@ const NavList = (props) => {
|
|||
const SubscriptionList = (props) => {
|
||||
return (
|
||||
<>
|
||||
{props.subscriptions.map((id, subscription) =>
|
||||
{props.subscriptions.map(subscription =>
|
||||
<ListItemButton
|
||||
key={id}
|
||||
onClick={() => props.onSubscriptionClick(id)}
|
||||
selected={props.selectedSubscription && !props.prefsOpen && props.selectedSubscription.id === id}
|
||||
key={subscription.id}
|
||||
onClick={() => props.onSubscriptionClick(subscription.id)}
|
||||
selected={props.selectedSubscription && !props.prefsOpen && props.selectedSubscription.id === subscription.id}
|
||||
>
|
||||
<ListItemIcon><ChatBubbleOutlineIcon /></ListItemIcon>
|
||||
<ListItemText primary={subscription.shortUrl()}/>
|
||||
<ListItemText primary={topicShortUrl(subscription.baseUrl, subscription.topic)}/>
|
||||
</ListItemButton>
|
||||
)}
|
||||
</>
|
||||
|
|
|
@ -3,7 +3,7 @@ import {CardContent, Link, Stack} from "@mui/material";
|
|||
import Card from "@mui/material/Card";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import * as React from "react";
|
||||
import {formatMessage, formatTitle, topicUrl, unmatchedTags} from "../app/utils";
|
||||
import {formatMessage, formatTitle, topicShortUrl, unmatchedTags} from "../app/utils";
|
||||
import IconButton from "@mui/material/IconButton";
|
||||
import CloseIcon from '@mui/icons-material/Close';
|
||||
import {Paragraph, VerticallyCenteredContainer} from "./styles";
|
||||
|
@ -12,16 +12,16 @@ import db from "../app/db";
|
|||
|
||||
const Notifications = (props) => {
|
||||
const subscription = props.subscription;
|
||||
const subscriptionId = topicUrl(subscription.baseUrl, subscription.topic);
|
||||
const notifications = useLiveQuery(() => {
|
||||
return db.notifications
|
||||
.where({ subscriptionId: subscriptionId })
|
||||
.where({ subscriptionId: subscription.id })
|
||||
.toArray();
|
||||
}, [subscription]);
|
||||
if (!notifications || notifications.length === 0) {
|
||||
return <NothingHereYet subscription={subscription}/>;
|
||||
}
|
||||
const sortedNotifications = Array.from(notifications).sort((a, b) => a.time < b.time ? 1 : -1);
|
||||
const sortedNotifications = Array.from(notifications)
|
||||
.sort((a, b) => a.time < b.time ? 1 : -1);
|
||||
return (
|
||||
<Container maxWidth="lg" sx={{marginTop: 3, marginBottom: 3}}>
|
||||
<Stack spacing={3}>
|
||||
|
@ -30,7 +30,6 @@ const Notifications = (props) => {
|
|||
key={notification.id}
|
||||
subscriptionId={subscription.id}
|
||||
notification={notification}
|
||||
onDelete={(notificationId) => props.onDeleteNotification(subscription.id, notificationId)}
|
||||
/>)}
|
||||
</Stack>
|
||||
</Container>
|
||||
|
@ -38,15 +37,20 @@ const Notifications = (props) => {
|
|||
}
|
||||
|
||||
const NotificationItem = (props) => {
|
||||
const subscriptionId = props.subscriptionId;
|
||||
const notification = props.notification;
|
||||
const date = new Intl.DateTimeFormat('default', {dateStyle: 'short', timeStyle: 'short'})
|
||||
.format(new Date(notification.time * 1000));
|
||||
const otherTags = unmatchedTags(notification.tags);
|
||||
const tags = (otherTags.length > 0) ? otherTags.join(', ') : null;
|
||||
const handleDelete = async () => {
|
||||
console.log(`[Notifications] Deleting notification ${notification.id} from ${subscriptionId}`);
|
||||
await db.notifications.delete(notification.id); // FIXME
|
||||
}
|
||||
return (
|
||||
<Card sx={{ minWidth: 275 }}>
|
||||
<CardContent>
|
||||
<IconButton onClick={() => props.onDelete(notification.id)} sx={{ float: 'right', marginRight: -1, marginTop: -1 }}>
|
||||
<IconButton onClick={handleDelete} sx={{ float: 'right', marginRight: -1, marginTop: -1 }}>
|
||||
<CloseIcon />
|
||||
</IconButton>
|
||||
<Typography sx={{ fontSize: 14 }} color="text.secondary">
|
||||
|
@ -67,6 +71,7 @@ const NotificationItem = (props) => {
|
|||
}
|
||||
|
||||
const NothingHereYet = (props) => {
|
||||
const shortUrl = topicShortUrl(props.subscription.baseUrl, props.subscription.topic);
|
||||
return (
|
||||
<VerticallyCenteredContainer maxWidth="xs">
|
||||
<Typography variant="h5" align="center" sx={{ paddingBottom: 1 }}>
|
||||
|
@ -79,7 +84,7 @@ const NothingHereYet = (props) => {
|
|||
<Paragraph>
|
||||
Example:<br/>
|
||||
<tt>
|
||||
$ curl -d "Hi" {props.subscription.shortUrl()}
|
||||
$ curl -d "Hi" {shortUrl}
|
||||
</tt>
|
||||
</Paragraph>
|
||||
<Paragraph>
|
||||
|
|
|
@ -15,7 +15,7 @@ import {
|
|||
} from "@mui/material";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import Paper from "@mui/material/Paper";
|
||||
import repository from "../app/Repository";
|
||||
import prefs from "../app/Prefs";
|
||||
import {Paragraph} from "./styles";
|
||||
import EditIcon from '@mui/icons-material/Edit';
|
||||
import CloseIcon from "@mui/icons-material/Close";
|
||||
|
@ -60,9 +60,9 @@ const Notifications = () => {
|
|||
};
|
||||
|
||||
const MinPriority = () => {
|
||||
const minPriority = useLiveQuery(() => repository.getMinPriority());
|
||||
const minPriority = useLiveQuery(() => prefs.minPriority());
|
||||
const handleChange = async (ev) => {
|
||||
await repository.setMinPriority(ev.target.value);
|
||||
await prefs.setMinPriority(ev.target.value);
|
||||
}
|
||||
if (!minPriority) {
|
||||
return null; // While loading
|
||||
|
@ -83,9 +83,9 @@ const MinPriority = () => {
|
|||
};
|
||||
|
||||
const DeleteAfter = () => {
|
||||
const deleteAfter = useLiveQuery(async () => repository.getDeleteAfter());
|
||||
const deleteAfter = useLiveQuery(async () => prefs.deleteAfter());
|
||||
const handleChange = async (ev) => {
|
||||
await repository.setDeleteAfter(ev.target.value);
|
||||
await prefs.setDeleteAfter(ev.target.value);
|
||||
}
|
||||
if (!deleteAfter) {
|
||||
return null; // While loading
|
||||
|
@ -95,7 +95,7 @@ const DeleteAfter = () => {
|
|||
<FormControl fullWidth variant="standard" sx={{ m: 1 }}>
|
||||
<Select value={deleteAfter} onChange={handleChange}>
|
||||
<MenuItem value={0}>Never</MenuItem>
|
||||
<MenuItem value={10800}>After three hour</MenuItem>
|
||||
<MenuItem value={10800}>After three hours</MenuItem>
|
||||
<MenuItem value={86400}>After one day</MenuItem>
|
||||
<MenuItem value={604800}>After one week</MenuItem>
|
||||
<MenuItem value={2592000}>After one month</MenuItem>
|
||||
|
|
|
@ -7,7 +7,6 @@ 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 Subscription from "../app/Subscription";
|
||||
import {Autocomplete, Checkbox, FormControlLabel, useMediaQuery} from "@mui/material";
|
||||
import theme from "./theme";
|
||||
import api from "../app/Api";
|
||||
|
@ -25,7 +24,12 @@ const SubscribeDialog = (props) => {
|
|||
const fullScreen = useMediaQuery(theme.breakpoints.down('sm'));
|
||||
const handleSuccess = () => {
|
||||
const actualBaseUrl = (baseUrl) ? baseUrl : defaultBaseUrl; // FIXME
|
||||
const subscription = new Subscription(actualBaseUrl, topic);
|
||||
const subscription = {
|
||||
id: topicUrl(actualBaseUrl, topic),
|
||||
baseUrl: actualBaseUrl,
|
||||
topic: topic,
|
||||
last: null
|
||||
};
|
||||
props.onSuccess(subscription);
|
||||
}
|
||||
return (
|
||||
|
@ -54,8 +58,8 @@ const SubscribePage = (props) => {
|
|||
const [anotherServerVisible, setAnotherServerVisible] = useState(false);
|
||||
const baseUrl = (anotherServerVisible) ? props.baseUrl : defaultBaseUrl;
|
||||
const topic = props.topic;
|
||||
const existingTopicUrls = props.subscriptions.map((id, s) => s.url());
|
||||
const existingBaseUrls = Array.from(new Set(["https://ntfy.sh", ...props.subscriptions.map((id, s) => s.baseUrl)]))
|
||||
const existingTopicUrls = props.subscriptions.map(s => topicUrl(s.baseUrl, s.topic));
|
||||
const existingBaseUrls = Array.from(new Set(["https://ntfy.sh", ...props.subscriptions.map(s => s.baseUrl)]))
|
||||
.filter(s => s !== defaultBaseUrl);
|
||||
const handleSubscribe = async () => {
|
||||
const success = await api.auth(baseUrl, topic, null);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue