You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-11-24 23:01:05 +03:00
DM: Simplify session components API (#1745)
Co-authored-by: Quentin Gliech <quenting@element.io>
This commit is contained in:
@@ -24,6 +24,7 @@ import {
|
|||||||
parseUserAgent,
|
parseUserAgent,
|
||||||
sessionNameFromDeviceInformation,
|
sessionNameFromDeviceInformation,
|
||||||
} from "../utils/parseUserAgent";
|
} from "../utils/parseUserAgent";
|
||||||
|
import { useCurrentBrowserSessionId } from "../utils/session/useCurrentBrowserSessionId";
|
||||||
|
|
||||||
import EndSessionButton from "./Session/EndSessionButton";
|
import EndSessionButton from "./Session/EndSessionButton";
|
||||||
import Session from "./Session/Session";
|
import Session from "./Session/Session";
|
||||||
@@ -92,11 +93,12 @@ export const useEndBrowserSession = (
|
|||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
session: FragmentType<typeof BROWSER_SESSION_FRAGMENT>;
|
session: FragmentType<typeof BROWSER_SESSION_FRAGMENT>;
|
||||||
isCurrent: boolean;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const BrowserSession: React.FC<Props> = ({ session, isCurrent }) => {
|
const BrowserSession: React.FC<Props> = ({ session }) => {
|
||||||
|
const currentBrowserSessionId = useCurrentBrowserSessionId();
|
||||||
const data = useFragment(BROWSER_SESSION_FRAGMENT, session);
|
const data = useFragment(BROWSER_SESSION_FRAGMENT, session);
|
||||||
|
const isCurrent = data.id === currentBrowserSessionId;
|
||||||
|
|
||||||
const onSessionEnd = useEndBrowserSession(data.id, isCurrent);
|
const onSessionEnd = useEndBrowserSession(data.id, isCurrent);
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ import {
|
|||||||
Pagination,
|
Pagination,
|
||||||
} from "../pagination";
|
} from "../pagination";
|
||||||
import { isOk, unwrap, unwrapOk } from "../result";
|
import { isOk, unwrap, unwrapOk } from "../result";
|
||||||
import { useCurrentBrowserSessionId } from "../utils/session/useCurrentBrowserSessionId";
|
|
||||||
|
|
||||||
import BlockList from "./BlockList";
|
import BlockList from "./BlockList";
|
||||||
import BrowserSession from "./BrowserSession";
|
import BrowserSession from "./BrowserSession";
|
||||||
@@ -112,7 +111,6 @@ const paginationFamily = atomFamily((userId: string) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const BrowserSessionList: React.FC<{ userId: string }> = ({ userId }) => {
|
const BrowserSessionList: React.FC<{ userId: string }> = ({ userId }) => {
|
||||||
const currentBrowserSessionId = useCurrentBrowserSessionId();
|
|
||||||
const [pending, startTransition] = useTransition();
|
const [pending, startTransition] = useTransition();
|
||||||
const result = useAtomValue(browserSessionListFamily(userId));
|
const result = useAtomValue(browserSessionListFamily(userId));
|
||||||
const setPagination = useSetAtom(currentPaginationAtom);
|
const setPagination = useSetAtom(currentPaginationAtom);
|
||||||
@@ -157,11 +155,7 @@ const BrowserSessionList: React.FC<{ userId: string }> = ({ userId }) => {
|
|||||||
Active only
|
Active only
|
||||||
</label>
|
</label>
|
||||||
{browserSessions.edges.map((n) => (
|
{browserSessions.edges.map((n) => (
|
||||||
<BrowserSession
|
<BrowserSession key={n.cursor} session={n.node} />
|
||||||
key={n.cursor}
|
|
||||||
session={n.node}
|
|
||||||
isCurrent={n.node.id === currentBrowserSessionId}
|
|
||||||
/>
|
|
||||||
))}
|
))}
|
||||||
</BlockList>
|
</BlockList>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user