diff --git a/web/src/components/App.js b/web/src/components/App.js index 29899850..1843f59e 100644 --- a/web/src/components/App.js +++ b/web/src/components/App.js @@ -14,7 +14,7 @@ import Preferences from "./Preferences"; import {useLiveQuery} from "dexie-react-hooks"; import subscriptionManager from "../app/SubscriptionManager"; import userManager from "../app/UserManager"; -import {BrowserRouter, Route, Routes, useNavigate, useParams} from "react-router-dom"; +import {BrowserRouter, Route, Routes, Outlet, useOutletContext, useNavigate, useParams} from "react-router-dom"; import {expandUrl, subscriptionRoute} from "../app/utils"; // TODO support unsubscribed routes @@ -28,62 +28,40 @@ const App = () => { - + + }> + } /> + } /> + } /> + } /> + + ); } -const Content = () => { - const subscriptions = useLiveQuery(() => subscriptionManager.all()); - // const context = { subscriptions }; - return ( - - } /> - } /> - } /> - } /> - } /> - - ) -}; - -const AllSubscriptions = (props) => { - return ( - - - - ); +const AllSubscriptions = () => { + const { subscriptions } = useOutletContext(); + return ; } -const SingleSubscription = (props) => { +const SingleSubscription = () => { + const { selected } = useOutletContext(); + return ; +} + +const Layout = () => { const params = useParams(); - const [selected] = (props.subscriptions || []).filter(s => { - return (params.baseUrl && expandUrl(params.baseUrl).includes(s.baseUrl) && params.topic === s.topic) - || (window.location.origin === s.baseUrl && params.topic === s.topic) - }); - return ( - - - - ); -} - -const PrefLayout = (props) => { - return ( - - - - ); -} - -const Layout = (props) => { - const subscriptions = props.subscriptions; // May be null/undefined - const selected = props.selected; // May be null/undefined const [mobileDrawerOpen, setMobileDrawerOpen] = useState(false); const [notificationsGranted, setNotificationsGranted] = useState(notifier.granted()); const users = useLiveQuery(() => userManager.all()); + const subscriptions = useLiveQuery(() => subscriptionManager.all()); const newNotificationsCount = subscriptions?.reduce((prev, cur) => prev + cur.new, 0) || 0; + const [selected] = (subscriptions || []).filter(s => { + return (params.baseUrl && expandUrl(params.baseUrl).includes(s.baseUrl) && params.topic === s.topic) + || (window.location.origin === s.baseUrl && params.topic === s.topic) + }); useConnectionListeners(); @@ -107,7 +85,7 @@ const Layout = (props) => { />
- {props.children} +
);