feat: rpc client
This commit is contained in:
@@ -4,7 +4,7 @@ import "react-native-reanimated";
|
||||
import { authClient } from "@/lib/auth-client";
|
||||
import { ZeroProvider } from "@rocicorp/zero/react";
|
||||
import { useMemo } from "react";
|
||||
import { authDataSchema } from "@money/shared/auth";
|
||||
import { AuthSchema } from "@money/shared/auth";
|
||||
import { Platform } from "react-native";
|
||||
import type { ZeroOptions } from "@rocicorp/zero";
|
||||
import {
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
BASE_URL,
|
||||
} from "@money/shared";
|
||||
import { expoSQLiteStoreProvider } from "@rocicorp/zero/react-native";
|
||||
import { Schema as S } from "effect";
|
||||
|
||||
export const unstable_settings = {
|
||||
anchor: "index",
|
||||
@@ -26,8 +27,8 @@ export default function RootLayout() {
|
||||
const { data: session, isPending } = authClient.useSession();
|
||||
|
||||
const authData = useMemo(() => {
|
||||
const result = authDataSchema.safeParse(session);
|
||||
return result.success ? result.data : null;
|
||||
const result = session ? S.decodeSync(AuthSchema)(session) : null;
|
||||
return result ? result : null;
|
||||
}, [session]);
|
||||
|
||||
const cookie = useMemo(() => {
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
import { Button, Text, View } from "react-native";
|
||||
import { AtomRpc, useAtomSet } from "@effect-atom/atom-react";
|
||||
import { Layer } from "effect";
|
||||
import { LinkRpcs } from "@money/shared/rpc";
|
||||
import { FetchHttpClient } from "@effect/platform";
|
||||
import { RpcClient, RpcSerialization } from "@effect/rpc";
|
||||
|
||||
class Client extends AtomRpc.Tag<Client>()("RpcClient", {
|
||||
group: LinkRpcs,
|
||||
protocol: RpcClient.layerProtocolHttp({
|
||||
url: "http://laptop:3000/rpc",
|
||||
}).pipe(Layer.provide([RpcSerialization.layerJson, FetchHttpClient.layer])),
|
||||
}) {}
|
||||
|
||||
export default function Page() {
|
||||
const create = useAtomSet(Client.mutation("CreateLink"));
|
||||
|
||||
const onPress = () => {
|
||||
create({
|
||||
payload: void 0,
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<View>
|
||||
<Text>RPC Test</Text>
|
||||
<Button onPress={onPress} title="Create link" />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user