diff --git a/web/src/app/NotificationManager.js b/web/src/app/NotificationManager.js index 46225b48..8834d2e3 100644 --- a/web/src/app/NotificationManager.js +++ b/web/src/app/NotificationManager.js @@ -1,4 +1,4 @@ -import {formatMessage, formatTitleWithFallback, openUrl, topicShortUrl} from "./utils"; +import {formatMessage, formatTitleWithDefault, openUrl, topicShortUrl} from "./utils"; import prefs from "./Prefs"; import subscriptionManager from "./SubscriptionManager"; @@ -11,7 +11,7 @@ class NotificationManager { } const shortUrl = topicShortUrl(subscription.baseUrl, subscription.topic); const message = formatMessage(notification); - const title = formatTitleWithFallback(notification, shortUrl); + const title = formatTitleWithDefault(notification, shortUrl); console.log(`[NotificationManager, ${shortUrl}] Displaying notification ${notification.id}: ${message}`); const n = new Notification(title, { diff --git a/web/src/app/utils.js b/web/src/app/utils.js index 914240e5..9eabe1b3 100644 --- a/web/src/app/utils.js +++ b/web/src/app/utils.js @@ -33,7 +33,7 @@ const toEmojis = (tags) => { } -export const formatTitleWithFallback = (m, fallback) => { +export const formatTitleWithDefault = (m, fallback) => { if (m.title) { return formatTitle(m); } diff --git a/web/src/components/App.js b/web/src/components/App.js index 8f344c49..61da87a1 100644 --- a/web/src/components/App.js +++ b/web/src/components/App.js @@ -19,10 +19,10 @@ import pruner from "../app/Pruner"; import subscriptionManager from "../app/SubscriptionManager"; import userManager from "../app/UserManager"; -// TODO subscribe dialog check/use existing user // TODO make default server functional // TODO routing // TODO embed into ntfy server +// TODO new notification indicator const App = () => { const [mobileDrawerOpen, setMobileDrawerOpen] = useState(false); diff --git a/web/src/components/Preferences.js b/web/src/components/Preferences.js index bf88995b..d8695bcf 100644 --- a/web/src/components/Preferences.js +++ b/web/src/components/Preferences.js @@ -143,22 +143,24 @@ const Pref = (props) => { const DefaultServer = (props) => { return ( - - - Default server - - - This server is used as a default when adding new topics. - - - + + + + Default server + + + This server is used as a default when adding new topics. + + + + ); }; @@ -183,7 +185,7 @@ const Users = () => { } }; return ( - + Manage users diff --git a/web/src/components/SubscribeDialog.js b/web/src/components/SubscribeDialog.js index 5758339e..e9febf74 100644 --- a/web/src/components/SubscribeDialog.js +++ b/web/src/components/SubscribeDialog.js @@ -16,6 +16,7 @@ import userManager from "../app/UserManager"; import subscriptionManager from "../app/SubscriptionManager"; import poller from "../app/Poller"; +const publicBaseUrl = "https://ntfy.sh" const defaultBaseUrl = "http://127.0.0.1" //const defaultBaseUrl = "https://ntfy.sh" @@ -60,19 +61,27 @@ const SubscribeDialog = (props) => { const SubscribePage = (props) => { const [anotherServerVisible, setAnotherServerVisible] = useState(false); + const [errorText, setErrorText] = useState(""); const baseUrl = (anotherServerVisible) ? props.baseUrl : defaultBaseUrl; const topic = props.topic; 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)])) + const existingBaseUrls = Array.from(new Set([publicBaseUrl, ...props.subscriptions.map(s => s.baseUrl)])) .filter(s => s !== defaultBaseUrl); const handleSubscribe = async () => { - const success = await api.auth(baseUrl, topic, null); + const user = await userManager.get(baseUrl); // May be undefined + const username = (user) ? user.username : "anonymous"; + const success = await api.auth(baseUrl, topic, user); if (!success) { - console.log(`[SubscribeDialog] Login to ${topicUrl(baseUrl, topic)} failed for anonymous user`); - props.onNeedsLogin(); - return; + console.log(`[SubscribeDialog] Login to ${topicUrl(baseUrl, topic)} failed for user ${username}`); + if (user) { + setErrorText(`User ${username} not authorized`); + return; + } else { + props.onNeedsLogin(); + return; + } } - console.log(`[SubscribeDialog] Successful login to ${topicUrl(baseUrl, topic)} for anonymous user`); + console.log(`[SubscribeDialog] Successful login to ${topicUrl(baseUrl, topic)} for user ${username}`); props.onSuccess(); }; const handleUseAnotherChanged = (e) => { @@ -122,10 +131,10 @@ const SubscribePage = (props) => { } />} - + - + ); }; diff --git a/web/src/components/theme.js b/web/src/components/theme.js index 2b3f73c9..3fdafae8 100644 --- a/web/src/components/theme.js +++ b/web/src/components/theme.js @@ -21,6 +21,15 @@ const theme = createTheme({ }, }, }, + MuiCardContent: { + styleOverrides: { + root: { + ':last-child': { + paddingBottom: '16px' + } + } + } + } }, });