1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-11-23 11:02:35 +03:00

WIP my account page

This commit is contained in:
Quentin Gliech
2023-04-27 16:38:02 +02:00
parent 574514638e
commit 3c933a9d29
14 changed files with 711 additions and 860 deletions

View File

@@ -15,42 +15,58 @@
import BlockList from "./BlockList";
import BrowserSession from "./BrowserSession";
import { Title } from "./Typography";
import { FragmentType, graphql, useFragment } from "../gql";
import { graphql } from "../gql";
import { atomFamily } from "jotai/utils";
import { atomWithQuery } from "jotai-urql";
import { useAtomValue } from "jotai";
import { currentBrowserSessionIdAtom } from "../atoms";
const FRAGMENT = graphql(/* GraphQL */ `
fragment BrowserSessionList_user on User {
browserSessions(first: 10) {
edges {
cursor
node {
id
...BrowserSession_session
const QUERY = graphql(/* GraphQL */ `
query BrowserSessionList($userId: ID!) {
user(id: $userId) {
id
browserSessions(first: 10) {
edges {
cursor
node {
id
...BrowserSession_session
}
}
}
}
}
`);
type Props = {
user: FragmentType<typeof FRAGMENT>;
currentSessionId: string;
};
const browserSessionListFamily = atomFamily((userId: string) => {
const browserSessionList = atomWithQuery({
query: QUERY,
getVariables: () => ({ userId }),
});
return browserSessionList;
});
const BrowserSessionList: React.FC<Props> = ({ user, currentSessionId }) => {
const data = useFragment(FRAGMENT, user);
const BrowserSessionList: React.FC<{ userId: string }> = ({ userId }) => {
const result = useAtomValue(browserSessionListFamily(userId));
const currentSessionId = useAtomValue(currentBrowserSessionIdAtom);
return (
<BlockList>
<Title>List of browser sessions:</Title>
{data.browserSessions.edges.map((n) => (
<BrowserSession
key={n.cursor}
session={n.node}
isCurrent={n.node.id === currentSessionId}
/>
))}
</BlockList>
);
if (result.data?.user?.browserSessions) {
const data = result.data.user.browserSessions;
return (
<BlockList>
<Title>List of browser sessions:</Title>
{data.edges.map((n) => (
<BrowserSession
key={n.cursor}
session={n.node}
isCurrent={n.node.id === currentSessionId}
/>
))}
</BlockList>
);
}
return <>Failed to load browser sessions</>;
};
export default BrowserSessionList;