From ff66f052a03eb627f4a3cde7cefe9e07dedd3a73 Mon Sep 17 00:00:00 2001 From: Kerry Date: Fri, 15 Sep 2023 00:41:30 +1200 Subject: [PATCH] DM: Simplify session components API (#1745) Co-authored-by: Quentin Gliech --- frontend/src/components/BrowserSession.tsx | 6 ++++-- frontend/src/components/BrowserSessionList.tsx | 8 +------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/frontend/src/components/BrowserSession.tsx b/frontend/src/components/BrowserSession.tsx index 5833a51ac..17f14e2c7 100644 --- a/frontend/src/components/BrowserSession.tsx +++ b/frontend/src/components/BrowserSession.tsx @@ -24,6 +24,7 @@ import { parseUserAgent, sessionNameFromDeviceInformation, } from "../utils/parseUserAgent"; +import { useCurrentBrowserSessionId } from "../utils/session/useCurrentBrowserSessionId"; import EndSessionButton from "./Session/EndSessionButton"; import Session from "./Session/Session"; @@ -92,11 +93,12 @@ export const useEndBrowserSession = ( type Props = { session: FragmentType; - isCurrent: boolean; }; -const BrowserSession: React.FC = ({ session, isCurrent }) => { +const BrowserSession: React.FC = ({ session }) => { + const currentBrowserSessionId = useCurrentBrowserSessionId(); const data = useFragment(BROWSER_SESSION_FRAGMENT, session); + const isCurrent = data.id === currentBrowserSessionId; const onSessionEnd = useEndBrowserSession(data.id, isCurrent); diff --git a/frontend/src/components/BrowserSessionList.tsx b/frontend/src/components/BrowserSessionList.tsx index 5750dc8e4..02c0429a5 100644 --- a/frontend/src/components/BrowserSessionList.tsx +++ b/frontend/src/components/BrowserSessionList.tsx @@ -27,7 +27,6 @@ import { Pagination, } from "../pagination"; import { isOk, unwrap, unwrapOk } from "../result"; -import { useCurrentBrowserSessionId } from "../utils/session/useCurrentBrowserSessionId"; import BlockList from "./BlockList"; import BrowserSession from "./BrowserSession"; @@ -112,7 +111,6 @@ const paginationFamily = atomFamily((userId: string) => { }); const BrowserSessionList: React.FC<{ userId: string }> = ({ userId }) => { - const currentBrowserSessionId = useCurrentBrowserSessionId(); const [pending, startTransition] = useTransition(); const result = useAtomValue(browserSessionListFamily(userId)); const setPagination = useSetAtom(currentPaginationAtom); @@ -157,11 +155,7 @@ const BrowserSessionList: React.FC<{ userId: string }> = ({ userId }) => { Active only {browserSessions.edges.map((n) => ( - + ))} );