mirror of
https://github.com/binwiederhier/ntfy.git
synced 2025-07-20 10:04:08 +00:00
Small refactor
This commit is contained in:
parent
2f5acee798
commit
75a4b5bd88
8 changed files with 98 additions and 113 deletions
|
@ -242,11 +242,6 @@ const WebPushEnabled = () => {
|
|||
await prefs.setWebPushEnabled(ev.target.value);
|
||||
};
|
||||
|
||||
// while loading
|
||||
if (defaultEnabled == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!notifier.pushPossible()) {
|
||||
return null;
|
||||
}
|
||||
|
@ -254,7 +249,7 @@ const WebPushEnabled = () => {
|
|||
return (
|
||||
<Pref labelId={labelId} title={t("prefs_notifications_web_push_title")} description={t("prefs_notifications_web_push_description")}>
|
||||
<FormControl fullWidth variant="standard" sx={{ m: 1 }}>
|
||||
<Select value={defaultEnabled} onChange={handleChange} aria-labelledby={labelId}>
|
||||
<Select value={defaultEnabled ?? false} onChange={handleChange} aria-labelledby={labelId}>
|
||||
<MenuItem value>{t("prefs_notifications_web_push_enabled")}</MenuItem>
|
||||
<MenuItem value={false}>{t("prefs_notifications_web_push_disabled")}</MenuItem>
|
||||
</Select>
|
||||
|
|
|
@ -142,6 +142,10 @@ export const SubscriptionPopup = (props) => {
|
|||
await subscriptionManager.deleteNotifications(props.subscription.id);
|
||||
};
|
||||
|
||||
const handleSetMutedUntil = async (mutedUntil) => {
|
||||
await subscriptionManager.setMutedUntil(subscription.id, mutedUntil);
|
||||
};
|
||||
|
||||
const handleUnsubscribe = async () => {
|
||||
console.log(`[SubscriptionPopup] Unsubscribing from ${props.subscription.id}`, props.subscription);
|
||||
await subscriptionManager.remove(props.subscription);
|
||||
|
@ -166,8 +170,6 @@ export const SubscriptionPopup = (props) => {
|
|||
return (
|
||||
<>
|
||||
<PopupMenu horizontal={placement} anchorEl={props.anchor} open={!!props.anchor} onClose={props.onClose}>
|
||||
<NotificationToggle subscription={subscription} />
|
||||
|
||||
<MenuItem onClick={handleChangeDisplayName}>
|
||||
<ListItemIcon>
|
||||
<Edit fontSize="small" />
|
||||
|
@ -198,7 +200,6 @@ export const SubscriptionPopup = (props) => {
|
|||
<ListItemIcon>
|
||||
<EnhancedEncryption fontSize="small" />
|
||||
</ListItemIcon>
|
||||
|
||||
{t("action_bar_reservation_edit")}
|
||||
</MenuItem>
|
||||
)}
|
||||
|
@ -207,7 +208,6 @@ export const SubscriptionPopup = (props) => {
|
|||
<ListItemIcon>
|
||||
<LockOpen fontSize="small" />
|
||||
</ListItemIcon>
|
||||
|
||||
{t("action_bar_reservation_delete")}
|
||||
</MenuItem>
|
||||
)}
|
||||
|
@ -215,21 +215,34 @@ export const SubscriptionPopup = (props) => {
|
|||
<ListItemIcon>
|
||||
<Send fontSize="small" />
|
||||
</ListItemIcon>
|
||||
|
||||
{t("action_bar_send_test_notification")}
|
||||
</MenuItem>
|
||||
<MenuItem onClick={handleClearAll}>
|
||||
<ListItemIcon>
|
||||
<ClearAll fontSize="small" />
|
||||
</ListItemIcon>
|
||||
|
||||
{t("action_bar_clear_notifications")}
|
||||
</MenuItem>
|
||||
{!!subscription.mutedUntil && (
|
||||
<MenuItem onClick={() => handleSetMutedUntil(0)}>
|
||||
<ListItemIcon>
|
||||
<Notifications fontSize="small" />
|
||||
</ListItemIcon>
|
||||
{t("action_bar_unmute_notifications")}
|
||||
</MenuItem>
|
||||
)}
|
||||
{!subscription.mutedUntil && (
|
||||
<MenuItem onClick={() => handleSetMutedUntil(1)}>
|
||||
<ListItemIcon>
|
||||
<NotificationsOff fontSize="small" />
|
||||
</ListItemIcon>
|
||||
{t("action_bar_mute_notifications")}
|
||||
</MenuItem>
|
||||
)}
|
||||
<MenuItem onClick={handleUnsubscribe}>
|
||||
<ListItemIcon>
|
||||
<RemoveCircle fontSize="small" />
|
||||
</ListItemIcon>
|
||||
|
||||
{t("action_bar_unsubscribe")}
|
||||
</MenuItem>
|
||||
</PopupMenu>
|
||||
|
@ -331,31 +344,6 @@ const DisplayNameDialog = (props) => {
|
|||
);
|
||||
};
|
||||
|
||||
const NotificationToggle = ({ subscription }) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const handleToggleMute = async () => {
|
||||
const mutedUntil = subscription.mutedUntil ? 0 : 1; // Make this a timestamp in the future
|
||||
await subscriptionManager.setMutedUntil(subscription.id, mutedUntil);
|
||||
};
|
||||
|
||||
return subscription.mutedUntil ? (
|
||||
<MenuItem onClick={handleToggleMute}>
|
||||
<ListItemIcon>
|
||||
<Notifications />
|
||||
</ListItemIcon>
|
||||
{t("notification_toggle_unmute")}
|
||||
</MenuItem>
|
||||
) : (
|
||||
<MenuItem onClick={handleToggleMute}>
|
||||
<ListItemIcon>
|
||||
<NotificationsOff />
|
||||
</ListItemIcon>
|
||||
{t("notification_toggle_mute")}
|
||||
</MenuItem>
|
||||
);
|
||||
};
|
||||
|
||||
export const ReserveLimitChip = () => {
|
||||
const { account } = useContext(AccountContext);
|
||||
if (account?.role === Role.ADMIN || account?.stats.reservations_remaining > 0) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue