mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import {AppBskyGraphDefs, AtUri} from '@atproto/api'
2
3import {isInvalidHandle} from '#/lib/strings/handles'
4
5export function makeProfileLink(
6 info: {
7 did: string
8 handle: string
9 },
10 ...segments: string[]
11) {
12 let handleSegment = info.did
13 if (info.handle && !isInvalidHandle(info.handle)) {
14 handleSegment = info.handle
15 }
16 return [`/profile`, handleSegment, ...segments].join('/')
17}
18
19export function makeCustomFeedLink(
20 did: string,
21 rkey: string,
22 ...segments: string[]
23) {
24 return [`/profile`, did, 'feed', rkey, ...segments].join('/')
25}
26
27export function makeListLink(did: string, rkey: string, ...segments: string[]) {
28 return [`/profile`, did, 'lists', rkey, ...segments].join('/')
29}
30
31export function makeTagLink(did: string) {
32 return `/search?q=${encodeURIComponent(did)}`
33}
34
35export function makeSearchLink(props: {query: string; from?: 'me' | string}) {
36 return `/search?q=${encodeURIComponent(
37 props.query + (props.from ? ` from:${props.from}` : ''),
38 )}`
39}
40
41export function makeStarterPackLink(
42 starterPackOrName:
43 | AppBskyGraphDefs.StarterPackViewBasic
44 | AppBskyGraphDefs.StarterPackView
45 | string,
46 rkey?: string,
47) {
48 if (typeof starterPackOrName === 'string') {
49 return `https://bsky.app/start/${starterPackOrName}/${rkey}`
50 } else {
51 const uriRkey = new AtUri(starterPackOrName.uri).rkey
52 return `https://bsky.app/start/${starterPackOrName.creator.handle}/${uriRkey}`
53 }
54}