f089f45781
Co-authored-by: Dan Abramov <dan.abramov@gmail.com> Co-authored-by: Paul Frazee <pfrazee@gmail.com> Co-authored-by: Eric Bailey <git@esb.lol> Co-authored-by: Samuel Newman <mozzius@protonmail.com>
55 lines
1.4 KiB
TypeScript
55 lines
1.4 KiB
TypeScript
import {AppBskyGraphDefs, AtUri} from '@atproto/api'
|
|
|
|
import {isInvalidHandle} from 'lib/strings/handles'
|
|
|
|
export function makeProfileLink(
|
|
info: {
|
|
did: string
|
|
handle: string
|
|
},
|
|
...segments: string[]
|
|
) {
|
|
let handleSegment = info.did
|
|
if (info.handle && !isInvalidHandle(info.handle)) {
|
|
handleSegment = info.handle
|
|
}
|
|
return [`/profile`, handleSegment, ...segments].join('/')
|
|
}
|
|
|
|
export function makeCustomFeedLink(
|
|
did: string,
|
|
rkey: string,
|
|
...segments: string[]
|
|
) {
|
|
return [`/profile`, did, 'feed', rkey, ...segments].join('/')
|
|
}
|
|
|
|
export function makeListLink(did: string, rkey: string, ...segments: string[]) {
|
|
return [`/profile`, did, 'lists', rkey, ...segments].join('/')
|
|
}
|
|
|
|
export function makeTagLink(did: string) {
|
|
return `/search?q=${encodeURIComponent(did)}`
|
|
}
|
|
|
|
export function makeSearchLink(props: {query: string; from?: 'me' | string}) {
|
|
return `/search?q=${encodeURIComponent(
|
|
props.query + (props.from ? ` from:${props.from}` : ''),
|
|
)}`
|
|
}
|
|
|
|
export function makeStarterPackLink(
|
|
starterPackOrName:
|
|
| AppBskyGraphDefs.StarterPackViewBasic
|
|
| AppBskyGraphDefs.StarterPackView
|
|
| string,
|
|
rkey?: string,
|
|
) {
|
|
if (typeof starterPackOrName === 'string') {
|
|
return `https://bsky.app/start/${starterPackOrName}/${rkey}`
|
|
} else {
|
|
const uriRkey = new AtUri(starterPackOrName.uri).rkey
|
|
return `https://bsky.app/start/${starterPackOrName.creator.handle}/${uriRkey}`
|
|
}
|
|
}
|