Remove webPushDefaultEnabled
				
					
				
			This commit is contained in:
		
							parent
							
								
									46f34ca1e3
								
							
						
					
					
						commit
						03aa67ed68
					
				
					 6 changed files with 8 additions and 80 deletions
				
			
		|  | @ -48,7 +48,6 @@ import { PermissionDenyAll, PermissionRead, PermissionReadWrite, PermissionWrite | |||
| import { ReserveAddDialog, ReserveDeleteDialog, ReserveEditDialog } from "./ReserveDialogs"; | ||||
| import { UnauthorizedError } from "../app/errors"; | ||||
| import { subscribeTopic } from "./SubscribeDialog"; | ||||
| import notifier from "../app/Notifier"; | ||||
| 
 | ||||
| const maybeUpdateAccountSettings = async (payload) => { | ||||
|   if (!session.exists()) { | ||||
|  | @ -86,7 +85,6 @@ const Notifications = () => { | |||
|         <Sound /> | ||||
|         <MinPriority /> | ||||
|         <DeleteAfter /> | ||||
|         {notifier.pushPossible() && <WebPushDefaultEnabled />} | ||||
|       </PrefGroup> | ||||
|     </Card> | ||||
|   ); | ||||
|  | @ -234,36 +232,6 @@ const DeleteAfter = () => { | |||
|   ); | ||||
| }; | ||||
| 
 | ||||
| const WebPushDefaultEnabled = () => { | ||||
|   const { t } = useTranslation(); | ||||
|   const labelId = "prefWebPushDefaultEnabled"; | ||||
|   const defaultEnabled = useLiveQuery(async () => prefs.webPushDefaultEnabled()); | ||||
|   const handleChange = async (ev) => { | ||||
|     await prefs.setWebPushDefaultEnabled(ev.target.value); | ||||
|   }; | ||||
| 
 | ||||
|   // while loading | ||||
|   if (defaultEnabled == null) { | ||||
|     return null; | ||||
|   } | ||||
| 
 | ||||
|   return ( | ||||
|     <Pref | ||||
|       labelId={labelId} | ||||
|       title={t("prefs_notifications_web_push_default_title")} | ||||
|       description={t("prefs_notifications_web_push_default_description")} | ||||
|     > | ||||
|       <FormControl fullWidth variant="standard" sx={{ m: 1 }}> | ||||
|         <Select value={defaultEnabled} onChange={handleChange} aria-labelledby={labelId}> | ||||
|           {defaultEnabled === "initial" && <MenuItem value="initial">{t("prefs_notifications_web_push_default_initial")}</MenuItem>} | ||||
|           <MenuItem value="enabled">{t("prefs_notifications_web_push_default_enabled")}</MenuItem> | ||||
|           <MenuItem value="disabled">{t("prefs_notifications_web_push_default_disabled")}</MenuItem> | ||||
|         </Select> | ||||
|       </FormControl> | ||||
|     </Pref> | ||||
|   ); | ||||
| }; | ||||
| 
 | ||||
| const Users = () => { | ||||
|   const { t } = useTranslation(); | ||||
|   const [dialogKey, setDialogKey] = useState(0); | ||||
|  |  | |||
|  | @ -14,7 +14,6 @@ import { | |||
|   Switch, | ||||
| } from "@mui/material"; | ||||
| import { useTranslation } from "react-i18next"; | ||||
| import { useLiveQuery } from "dexie-react-hooks"; | ||||
| import theme from "./theme"; | ||||
| import api from "../app/Api"; | ||||
| import { randomAlphanumericString, topicUrl, validTopic, validUrl } from "../app/utils"; | ||||
|  | @ -30,7 +29,6 @@ import { AccountContext } from "./App"; | |||
| import { TopicReservedError, UnauthorizedError } from "../app/errors"; | ||||
| import { ReserveLimitChip } from "./SubscriptionPopup"; | ||||
| import notifier from "../app/Notifier"; | ||||
| import prefs from "../app/Prefs"; | ||||
| 
 | ||||
| const publicBaseUrl = "https://ntfy.sh"; | ||||
| 
 | ||||
|  | @ -55,8 +53,6 @@ const SubscribeDialog = (props) => { | |||
|   const [showLoginPage, setShowLoginPage] = useState(false); | ||||
|   const fullScreen = useMediaQuery(theme.breakpoints.down("sm")); | ||||
| 
 | ||||
|   const webPushDefaultEnabled = useLiveQuery(async () => prefs.webPushDefaultEnabled()); | ||||
| 
 | ||||
|   const handleSuccess = async (webPushEnabled) => { | ||||
|     console.log(`[SubscribeDialog] Subscribing to topic ${topic}`); | ||||
|     const actualBaseUrl = baseUrl || config.base_url; | ||||
|  | @ -64,20 +60,9 @@ const SubscribeDialog = (props) => { | |||
|       webPushEnabled, | ||||
|     }); | ||||
|     poller.pollInBackground(subscription); // Dangle! | ||||
| 
 | ||||
|     // if the user hasn't changed the default web push setting yet, set it to enabled | ||||
|     if (webPushEnabled && webPushDefaultEnabled === "initial") { | ||||
|       await prefs.setWebPushDefaultEnabled(true); | ||||
|     } | ||||
| 
 | ||||
|     props.onSuccess(subscription); | ||||
|   }; | ||||
| 
 | ||||
|   // wait for liveQuery load | ||||
|   if (webPushDefaultEnabled === undefined) { | ||||
|     return <></>; | ||||
|   } | ||||
| 
 | ||||
|   return ( | ||||
|     <Dialog open={props.open} onClose={props.onCancel} fullScreen={fullScreen}> | ||||
|       {!showLoginPage && ( | ||||
|  | @ -90,7 +75,6 @@ const SubscribeDialog = (props) => { | |||
|           onCancel={props.onCancel} | ||||
|           onNeedsLogin={() => setShowLoginPage(true)} | ||||
|           onSuccess={handleSuccess} | ||||
|           webPushDefaultEnabled={webPushDefaultEnabled} | ||||
|         /> | ||||
|       )} | ||||
|       {showLoginPage && <LoginPage baseUrl={baseUrl} topic={topic} onBack={() => setShowLoginPage(false)} onSuccess={handleSuccess} />} | ||||
|  | @ -115,7 +99,7 @@ const SubscribePage = (props) => { | |||
|   const reserveTopicEnabled = | ||||
|     session.exists() && (account?.role === Role.ADMIN || (account?.role === Role.USER && (account?.stats.reservations_remaining || 0) > 0)); | ||||
| 
 | ||||
|   const [backgroundNotificationsEnabled, setBackgroundNotificationsEnabled] = useState(props.webPushDefaultEnabled === "enabled"); | ||||
|   const [backgroundNotificationsEnabled, setBackgroundNotificationsEnabled] = useState(false); | ||||
| 
 | ||||
|   const handleBackgroundNotificationsChanged = (e) => { | ||||
|     setBackgroundNotificationsEnabled(e.target.checked); | ||||
|  |  | |||
|  | @ -169,7 +169,7 @@ export const SubscriptionPopup = (props) => { | |||
|   return ( | ||||
|     <> | ||||
|       <PopupMenu horizontal={placement} anchorEl={props.anchor} open={!!props.anchor} onClose={props.onClose}> | ||||
|         <NotificationToggle subscription={subscription} /> | ||||
|         {notifier.pushPossible() && <NotificationToggle subscription={subscription} />} | ||||
|         <Divider /> | ||||
|         <MenuItem onClick={handleChangeDisplayName}> | ||||
|           <ListItemIcon> | ||||
|  | @ -367,18 +367,12 @@ const NotificationToggle = ({ subscription }) => { | |||
|   } | ||||
| 
 | ||||
|   return ( | ||||
|     <> | ||||
|       {notifier.pushPossible() && ( | ||||
|         <> | ||||
|           <MenuItem> | ||||
|             {subscription.webPushEnabled === 1 && checkedItem} | ||||
|             <ListItemText inset={subscription.webPushEnabled !== 1} onClick={handleToggleBackground}> | ||||
|               {t("notification_toggle_background")} | ||||
|             </ListItemText> | ||||
|           </MenuItem> | ||||
|         </> | ||||
|       )} | ||||
|     </> | ||||
|     <MenuItem> | ||||
|       {subscription.webPushEnabled === 1 && checkedItem} | ||||
|       <ListItemText inset={subscription.webPushEnabled !== 1} onClick={handleToggleBackground}> | ||||
|         {t("notification_toggle_background")} | ||||
|       </ListItemText> | ||||
|     </MenuItem> | ||||
|   ); | ||||
| }; | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue