Hopefully feature-complete Android Bluesky client written in Expo
atproto bluesky

Hook up session to the XRPC client

Changed files
+23 -9
src
app
(tabs)
+23 -9
src/app/(tabs)/_layout.tsx
··· 1 import { useInfiniteQuery } from "@tanstack/react-query"; 2 import { RefreshControl, Text, View, useColorScheme } from "react-native"; 3 import { SafeAreaView } from "react-native-safe-area-context"; 4 - import { Client, ok, simpleFetchHandler } from "@atcute/client"; 5 import { FlashList } from "@shopify/flash-list"; 6 import { StatusBar } from "expo-status-bar"; 7 import { useMaterial3Theme } from "@pchmn/expo-material3-theme"; 8 import Post from "@/src/components/Post"; 9 10 export default function TabLayout() { 11 const colorScheme = useColorScheme(); 12 const { theme } = useMaterial3Theme({ sourceColor: "#f4983c" }); 13 14 const feedQuery = useInfiniteQuery({ 15 queryKey: ["feed"], 16 initialPageParam: "", 17 queryFn: async ({ signal, pageParam }) => { 18 - const client = new Client({ handler: simpleFetchHandler({ service: "https://api.bsky.app" }) }); 19 - const res = await ok( 20 - client.get("app.bsky.feed.getAuthorFeed", { 21 - signal, 22 - params: { actor: "did:plc:irx36xprktslecsbopbwnh5w", cursor: pageParam, filter: "posts_no_replies" }, 23 - }) 24 - ); 25 26 - return res; 27 }, 28 getNextPageParam: (lastPage, allPages, lastPageParam, allPageParams) => lastPage.cursor, 29 getPreviousPageParam: (firstPage, allPages, firstPageParam, allPageParams) => firstPage.cursor,
··· 1 import { useInfiniteQuery } from "@tanstack/react-query"; 2 import { RefreshControl, Text, View, useColorScheme } from "react-native"; 3 import { SafeAreaView } from "react-native-safe-area-context"; 4 + import { Client, FetchHandler, ok } from "@atcute/client"; 5 import { FlashList } from "@shopify/flash-list"; 6 import { StatusBar } from "expo-status-bar"; 7 import { useMaterial3Theme } from "@pchmn/expo-material3-theme"; 8 import Post from "@/src/components/Post"; 9 + import { useOAuthSession } from "@/src/components/SessionProvider"; 10 11 export default function TabLayout() { 12 const colorScheme = useColorScheme(); 13 const { theme } = useMaterial3Theme({ sourceColor: "#f4983c" }); 14 + const session = useOAuthSession(); 15 16 const feedQuery = useInfiniteQuery({ 17 queryKey: ["feed"], 18 initialPageParam: "", 19 queryFn: async ({ signal, pageParam }) => { 20 + const wrapper: FetchHandler = async (pathname, init) => { 21 + return session.fetchHandler(pathname, init); 22 + }; 23 24 + try { 25 + const client = new Client({ 26 + handler: wrapper, 27 + proxy: { did: "did:web:api.bsky.app", serviceId: "#bsky_appview" }, 28 + }); 29 + const res = await ok( 30 + client.get("app.bsky.feed.getAuthorFeed", { 31 + signal, 32 + params: { actor: "did:plc:irx36xprktslecsbopbwnh5w", cursor: pageParam, filter: "posts_no_replies" }, 33 + }) 34 + ); 35 + 36 + return res; 37 + } catch (err) { 38 + console.log(err); 39 + throw err; 40 + } 41 }, 42 getNextPageParam: (lastPage, allPages, lastPageParam, allPageParams) => lastPage.cursor, 43 getPreviousPageParam: (firstPage, allPages, firstPageParam, allPageParams) => firstPage.cursor,