Skip to content

Commit

Permalink
✨ Use labels from 3p labeler
Browse files Browse the repository at this point in the history
  • Loading branch information
foysalit committed Mar 9, 2024
1 parent 970d95a commit a4984de
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
13 changes: 8 additions & 5 deletions components/common/labels/Grid.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import client from '@/lib/client'
import { useState } from 'react'
import Select from 'react-tailwindcss-select'
import { buildAllLabelOptions, ALL_LABELS, LabelGroupInfo } from './util'
import { ALL_LABELS, LabelGroupInfo } from './util'

const EMPTY_ARR = []
type SelectProps = React.ComponentProps<typeof Select>
Expand All @@ -21,10 +22,12 @@ export const LabelSelector = (props: LabelsProps) => {
value: label,
})),
)
const allOptions = buildAllLabelOptions(defaultLabels, options)
const selectorOptions = Object.values(ALL_LABELS).map((labelOption) => ({
label: labelOption.identifier,
value: labelOption.identifier,
const selectorOptions = [
...(client.session?.config.labeler?.policies?.['labelValues'] || []),
...Object.values(ALL_LABELS).map(({ identifier }) => identifier),

Check failure on line 27 in components/common/labels/Grid.tsx

View workflow job for this annotation

GitHub Actions / Build

Property 'identifier' does not exist on type 'LabelDefinition'.
].map((label) => ({
label,
value: label,
}))

// TODO: selected label text doesn't feel very nice here
Expand Down
39 changes: 37 additions & 2 deletions lib/client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
import { AtpAgent, AtpServiceClient, AtpSessionData } from '@atproto/api'
import {
AppBskyLabelerDefs,
AtpAgent,
AtpServiceClient,
AtpSessionData,
} from '@atproto/api'

interface ClientSession extends AtpSessionData {
service: string
config: {
labeler:
| AppBskyLabelerDefs.LabelerView
| AppBskyLabelerDefs.LabelerViewDetailed
| {
$type: string
[k: string]: unknown
}
| null
}
}

// exported api
Expand Down Expand Up @@ -54,8 +69,24 @@ class ClientManager extends EventTarget {
{ did: login.did },
{ headers: this.proxyHeaders() },
)
let labeler
const serviceDid = this.getServiceDid()
if (serviceDid) {
const {
data: { views },
} = await agent.api.app.bsky.labeler.getServices(
{
dids: [serviceDid.split('#')[0]],
},
{ headers: this.proxyHeaders() },
)
labeler = views[0]
}
this._session = {
service,
config: {
labeler,
},
accessJwt: login.accessJwt,
refreshJwt: login.refreshJwt,
handle: login.handle,
Expand All @@ -76,8 +107,12 @@ class ClientManager extends EventTarget {
this._emit('change')
}

getServiceDid(override?: string) {
return override ?? process.env.NEXT_PUBLIC_OZONE_SERVICE_DID
}

proxyHeaders(override?: string): Record<string, string> {
const proxy = override ?? process.env.NEXT_PUBLIC_OZONE_SERVICE_DID
const proxy = this.getServiceDid(override)
return proxy ? { 'atproto-proxy': proxy } : {}
}

Expand Down

0 comments on commit a4984de

Please sign in to comment.