From 0aefcf29ef236c455288b3cd4baee7af744f3b54 Mon Sep 17 00:00:00 2001 From: Philipp Heckel Date: Tue, 8 Mar 2022 14:29:03 -0500 Subject: [PATCH] This is it --- web/src/components/App.js | 70 ++++++++++++++------------------------- 1 file changed, 24 insertions(+), 46 deletions(-) diff --git a/web/src/components/App.js b/web/src/components/App.js index 2989985..1843f59 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} +
);