diff --git a/web/src/lib/api/reaction.ts b/web/src/lib/api/reaction.ts new file mode 100644 index 00000000..d30d5ada --- /dev/null +++ b/web/src/lib/api/reaction.ts @@ -0,0 +1,37 @@ +import { ok } from "@atcute/client"; +import { mainSchema as putRecordSchema } from "@atcute/atproto/types/repo/putRecord"; +import { mainSchema as deleteRecordSchema } from "@atcute/atproto/types/repo/deleteRecord"; +import type { Nsid, RecordKey } from "@atcute/lexicons/syntax"; +import type { OAuthUserAgent } from "@atcute/oauth-browser-client"; +import { createClient } from "$lib/auth/agent"; +import type { ReactionRecord, RecordView } from "./records"; + +const REACTION_COLLECTION = "sh.tangled.feed.reaction" as Nsid; + +export const putReaction = async ( + agent: OAuthUserAgent, + rkey: string, + record: ReactionRecord +): Promise> => { + const rpc = createClient(agent); + const { uri, cid } = await ok( + rpc.call(putRecordSchema, { + input: { + repo: agent.sub, + collection: REACTION_COLLECTION, + rkey: rkey as RecordKey, + record + } + }) + ); + return { uri, cid, value: record }; +}; + +export const deleteReaction = async (agent: OAuthUserAgent, rkey: string): Promise => { + const rpc = createClient(agent); + await ok( + rpc.call(deleteRecordSchema, { + input: { repo: agent.sub, collection: REACTION_COLLECTION, rkey: rkey as RecordKey } + }) + ); +}; diff --git a/web/src/routes/+layout.svelte b/web/src/routes/+layout.svelte index 3699b20c..7bc99133 100644 --- a/web/src/routes/+layout.svelte +++ b/web/src/routes/+layout.svelte @@ -32,7 +32,7 @@