the statusphere demo reworked into a vite/react app in a monorepo

move code to hydrate.ts

+24 -14
+22 -1
packages/appview/src/lib/hydrate.ts
··· 1 - import { XyzStatusphereDefs } from '@statusphere/lexicon' 2 3 import { Status } from '#/db' 4 import { AppContext } from '#/index' ··· 19 }, 20 } 21 }
··· 1 + import { 2 + AppBskyActorDefs, 3 + AppBskyActorProfile, 4 + XyzStatusphereDefs, 5 + } from '@statusphere/lexicon' 6 7 import { Status } from '#/db' 8 import { AppContext } from '#/index' ··· 23 }, 24 } 25 } 26 + 27 + export async function bskyProfileToProfileView( 28 + did: string, 29 + profile: AppBskyActorProfile.Record, 30 + ctx: AppContext, 31 + ): Promise<AppBskyActorDefs.ProfileView> { 32 + return { 33 + $type: 'app.bsky.actor.defs#profileView', 34 + did: did, 35 + handle: await ctx.resolver.resolveDidToHandle(did), 36 + avatar: profile.avatar 37 + ? `https://atproto.pictures/img/${did}/${profile.avatar.ref}` 38 + : undefined, 39 + displayName: profile.displayName, 40 + createdAt: profile.createdAt, 41 + } 42 + }
+2 -13
packages/appview/src/routes.ts
··· 13 14 import type { AppContext } from '#/index' 15 import { env } from '#/lib/env' 16 - import { statusToStatusView } from '#/lib/hydrate' 17 18 type Session = { did: string } 19 ··· 222 } 223 } 224 225 - const profileView: AppBskyActorDefs.ProfileView = { 226 - $type: 'app.bsky.actor.defs#profileView', 227 - did: did, 228 - handle: await ctx.resolver.resolveDidToHandle(did), 229 - avatar: profile.avatar 230 - ? `https://atproto.pictures/img/${did}/${profile.avatar.ref}` 231 - : undefined, 232 - displayName: profile.displayName, 233 - createdAt: profile.createdAt, 234 - } 235 - 236 // Fetch user status 237 const status = await ctx.db 238 .selectFrom('status') ··· 243 244 res.json({ 245 did: agent.assertDid, 246 - profile: profileView, 247 status: status ? await statusToStatusView(status, ctx) : undefined, 248 }) 249 } catch (err) {
··· 13 14 import type { AppContext } from '#/index' 15 import { env } from '#/lib/env' 16 + import { bskyProfileToProfileView, statusToStatusView } from '#/lib/hydrate' 17 18 type Session = { did: string } 19 ··· 222 } 223 } 224 225 // Fetch user status 226 const status = await ctx.db 227 .selectFrom('status') ··· 232 233 res.json({ 234 did: agent.assertDid, 235 + profile: await bskyProfileToProfileView(did, profile, ctx), 236 status: status ? await statusToStatusView(status, ctx) : undefined, 237 }) 238 } catch (err) {