Start work on ephemeral topics
This commit is contained in:
		
							parent
							
								
									0aefcf29ef
								
							
						
					
					
						commit
						d3462d2905
					
				
					 4 changed files with 31 additions and 14 deletions
				
			
		|  | @ -14,8 +14,8 @@ import Preferences from "./Preferences"; | |||
| import {useLiveQuery} from "dexie-react-hooks"; | ||||
| import subscriptionManager from "../app/SubscriptionManager"; | ||||
| import userManager from "../app/UserManager"; | ||||
| import {BrowserRouter, Route, Routes, Outlet, useOutletContext, useNavigate, useParams} from "react-router-dom"; | ||||
| import {expandUrl, subscriptionRoute} from "../app/utils"; | ||||
| import {BrowserRouter, Outlet, Route, Routes, useNavigate, useOutletContext, useParams} from "react-router-dom"; | ||||
| import {expandSecureUrl, expandUrl, subscriptionRoute, topicUrl} from "../app/utils"; | ||||
| 
 | ||||
| // TODO support unsubscribed routes
 | ||||
| // TODO "copy url" toast
 | ||||
|  | @ -44,12 +44,25 @@ const App = () => { | |||
| const AllSubscriptions = () => { | ||||
|     const { subscriptions } = useOutletContext(); | ||||
|     return <Notifications mode="all" subscriptions={subscriptions}/>; | ||||
| } | ||||
| }; | ||||
| 
 | ||||
| const SingleSubscription = () => { | ||||
|     const { selected } = useOutletContext(); | ||||
|     const { subscriptions, selected } = useOutletContext(); | ||||
|     const [missingAdded, setMissingAdded] = useState(false); | ||||
|     const params = useParams(); | ||||
|     useEffect(() => { | ||||
|         const loaded = subscriptions !== null && subscriptions !== undefined; | ||||
|         const missing = loaded && params.topic && !selected && !missingAdded; | ||||
|         if (missing) { | ||||
|             setMissingAdded(true); | ||||
|             const baseUrl = (params.baseUrl) ? expandSecureUrl(params.baseUrl) : window.location.origin; | ||||
|             console.log(`[App] Adding ephemeral subscription for ${topicUrl(baseUrl, params.topic)}`); | ||||
|             // subscriptionManager.add(baseUrl, params.topic, true); // Dangle!
 | ||||
|         } | ||||
|     }, [params, subscriptions, selected, missingAdded]); | ||||
| 
 | ||||
|     return <Notifications mode="one" subscription={selected}/>; | ||||
| } | ||||
| }; | ||||
| 
 | ||||
| const Layout = () => { | ||||
|     const params = useParams(); | ||||
|  |  | |||
|  | @ -25,13 +25,7 @@ const SubscribeDialog = (props) => { | |||
|     const fullScreen = useMediaQuery(theme.breakpoints.down('sm')); | ||||
|     const handleSuccess = async () => { | ||||
|         const actualBaseUrl = (baseUrl) ? baseUrl : window.location.origin; | ||||
|         const subscription = { | ||||
|             id: topicUrl(actualBaseUrl, topic), | ||||
|             baseUrl: actualBaseUrl, | ||||
|             topic: topic, | ||||
|             last: null | ||||
|         }; | ||||
|         await subscriptionManager.save(subscription); | ||||
|         const subscription = await subscriptionManager.add(actualBaseUrl, topic, false); | ||||
|         poller.pollInBackground(subscription); // Dangle!
 | ||||
|         props.onSuccess(subscription); | ||||
|     } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue