From 21123dab4300bb55c0198e57c6c8ff2cee3be0b0 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Sun, 9 Jun 2024 10:05:34 -0700 Subject: [PATCH] Add ActorLabel --- .../appcom/vocabulary/ActorLabel.tsx | 54 +++++++++++++++++++ src/components/appcom/vocabulary/Label.tsx | 14 ++--- src/components/appcom/vocabulary/common.ts | 4 ++ src/components/appcom/vocabulary/index.tsx | 2 + src/view/screens/DebugAppcom.tsx | 19 +++++++ 5 files changed, 82 insertions(+), 11 deletions(-) create mode 100644 src/components/appcom/vocabulary/ActorLabel.tsx diff --git a/src/components/appcom/vocabulary/ActorLabel.tsx b/src/components/appcom/vocabulary/ActorLabel.tsx new file mode 100644 index 0000000000..dac73541c3 --- /dev/null +++ b/src/components/appcom/vocabulary/ActorLabel.tsx @@ -0,0 +1,54 @@ +import React from 'react' +import {AtUri} from '@atproto/api' +import {z} from 'zod' + +import {useProfileQuery} from '#/state/queries/profile' +import {useResolveDidQuery} from '#/state/queries/resolve-uri' +import {color} from './common' +import {Label} from './Label' + +const actorLabelProps = z.object({ + uri: z.string(), + field: z.enum(['handle', 'displayName', 'description']), + color, + size: z + .number() + .positive() + .default(16) + .transform(v => ({fontSize: v})), + lineHeight: z + .number() + .positive() + .default(1) + .transform(v => ({lineHeight: v})), + weight: z + .enum(['normal', 'semibold', 'bold']) + .default('normal') + .transform(v => ({fontWeight: v})), +}) + +export type ActorLabelProps = z.infer + +export function ActorLabel(props: React.PropsWithChildren) { + const propsParsed = actorLabelProps.parse(props) + const urip = new AtUri(propsParsed.uri) + + const {data: did} = useResolveDidQuery(urip.host) + const {data: profile} = useProfileQuery({did}) + + let text = '' + if (profile) { + if (props.field === 'handle') { + text = profile.handle + } + if (props.field === 'displayName') { + text = profile.displayName || profile.handle + } + if (props.field === 'description') { + text = profile.description || '' + } + } + + // TODO loading, error + return