frontend client for gemstone. decentralised workplace app

feat: working sessions

serenity b3c041dd 33ade536

Changed files
+36 -10
src
app
(protected)
providers
queries
+10 -4
src/app/(protected)/index.tsx
···
import ChatComponentProfiled from "@/components/ChatComponentProfiled";
import { useOAuthSession } from "@/providers/OAuthProvider";
import { Redirect } from "expo-router";
-
import { View } from "react-native";
export default function Index() {
-
const session = useOAuthSession();
return (
<View
style={{
···
alignItems: "center",
}}
>
-
{session ? (
-
<ChatComponentProfiled did={session.did} />
) : (
<Redirect href={"/login"} />
)}
</View>
);
}
···
import ChatComponentProfiled from "@/components/ChatComponentProfiled";
+
import { useLatticeSession } from "@/providers/authed/LatticeSessionsProvider";
import { useOAuthSession } from "@/providers/OAuthProvider";
import { Redirect } from "expo-router";
+
import { Text, View } from "react-native";
export default function Index() {
+
const oAuthSession = useOAuthSession();
+
const sessionsMap = useLatticeSession();
+
const sessions = sessionsMap.values().toArray();
return (
<View
style={{
···
alignItems: "center",
}}
>
+
{oAuthSession ? (
+
<ChatComponentProfiled did={oAuthSession.did} />
) : (
<Redirect href={"/login"} />
)}
+
{sessions.map((session, idx) => (
+
<Text key={idx}>{session.latticeDid}</Text>
+
))}
</View>
);
}
+13 -3
src/providers/authed/LatticeSessionsProvider.tsx
···
import type { OAuthSession } from "@atproto/oauth-client";
import { useQueries, useQuery } from "@tanstack/react-query";
import type { ReactNode } from "react";
-
import { createContext, useMemo } from "react";
type LatticeSessionsMap = Map<Did, LatticeSessionInfo>;
···
"Something went wrong while initiating handshakes",
);
}
-
// TODO: better validation
-
const did = latticeAtUri.data.authority as Did;
const handshakeResult = await initiateHandshakeTo(
{
did,
···
}
return channel;
};
···
import type { OAuthSession } from "@atproto/oauth-client";
import { useQueries, useQuery } from "@tanstack/react-query";
import type { ReactNode } from "react";
+
import { createContext, useContext, useMemo } from "react";
type LatticeSessionsMap = Map<Did, LatticeSessionInfo>;
···
"Something went wrong while initiating handshakes",
);
}
+
// TODO: unfuck this.
+
const did =
+
`did:web:${encodeURIComponent(latticeAtUri.data.rKey ?? "")}` as Did;
const handshakeResult = await initiateHandshakeTo(
{
did,
···
}
return channel;
};
+
+
export const useLatticeSession = () => {
+
const value = useContext(LatticeSessionsContext);
+
if (value === null)
+
throw new Error(
+
"Lattice session context not inited. Or ordering of providers was wrong.",
+
);
+
return value.sessions;
+
};
+13 -3
src/queries/get-membership-from-pds.ts
···
};
const { records, cursor: nextCursor } = results.data;
-
const { success, error, data } = z
-
.array(systemsGmstnDevelopmentChannelMembershipRecordSchema)
.safeParse(records);
if (!success) return { ok: false, error: z.treeifyError(error) };
-
allRecords.push(...data);
if (records.length < 100) continueLoop = false;
cursor = nextCursor;
···
};
const { records, cursor: nextCursor } = results.data;
+
const {
+
success,
+
error,
+
data: responses,
+
} = z
+
.array(
+
z.object({
+
cid: z.string(),
+
uri: z.string(),
+
value: systemsGmstnDevelopmentChannelMembershipRecordSchema,
+
}),
+
)
.safeParse(records);
if (!success) return { ok: false, error: z.treeifyError(error) };
+
allRecords.push(...responses.map((data) => data.value));
if (records.length < 100) continueLoop = false;
cursor = nextCursor;