Skip to content

Commit 9591998

Browse files
committed
init useProfileLikes composable, add likes grid to profile page
1 parent ecdc8cf commit 9591998

5 files changed

Lines changed: 77 additions & 12 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
export type LikesResult = {
2+
records: {
3+
value: {
4+
subjectRef: string
5+
}
6+
}[]
7+
}
8+
9+
export function useProfileLikes(handle: MaybeRefOrGetter<string>) {
10+
const cachedFetch = useCachedFetch()
11+
const asyncData = useLazyAsyncData(
12+
`profile:${toValue(handle)}:likes`,
13+
async (_nuxtApp, { signal }) => {
14+
const { data: likes, isStale } = await cachedFetch<LikesResult>(
15+
`/api/social/profile/${toValue(handle)}/likes`,
16+
{ signal },
17+
)
18+
19+
return { likes, isStale }
20+
},
21+
)
22+
23+
if (import.meta.client) {
24+
onMounted(() => {
25+
asyncData.refresh()
26+
})
27+
}
28+
29+
return asyncData
30+
}

app/pages/profile/[handle]/index.vue

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ import { normalizeSearchParam } from '#shared/utils/url'
55
const route = useRoute('/profile/[handle]')
66
const router = useRouter()
77
8+
type LikesResult = {
9+
records: {
10+
value: {
11+
subjectRef: string
12+
}
13+
}[]
14+
}
15+
816
const handle = computed(() => route.params.handle)
917
1018
const { data: profile }: { data?: NPMXProfile } = useFetch(
@@ -15,11 +23,18 @@ const { data: profile }: { data?: NPMXProfile } = useFetch(
1523
},
1624
)
1725
26+
const { data: likes, status } = await useProfileLikes(handle)
27+
1828
useSeoMeta({
1929
title: () => `${handle.value} - npmx`,
2030
description: () => `npmx profile by ${handle.value}`,
2131
})
2232
33+
function extractPackageFromRef(ref: string) {
34+
const { pkg } = /https:\/\/npmx.dev\/package\/(?<pkg>.*)/.exec(ref).groups
35+
return pkg
36+
}
37+
2338
/**
2439
defineOgImageComponent('Default', {
2540
title: () => `~${username.value}`,
@@ -42,14 +57,36 @@ defineOgImageComponent('Default', {
4257
</div>
4358
</header>
4459

45-
<!-- Empty state (no packages found for user) -->
46-
<div class="flex-1 flex items-center justify-center">
47-
<div class="text-center">
48-
<p class="text-fg-muted font-mono">
49-
{{ $t('user.page.no_packages') }} <span class="text-fg">~{{ handle }}</span>
50-
</p>
51-
<p class="text-fg-subtle text-sm mt-2">{{ $t('user.page.no_packages_hint') }}</p>
60+
<section class="flex flex-col gap-3">
61+
<h1
62+
class="font-mono text-2xl sm:text-3xl font-medium min-w-0 break-words"
63+
:title="Likes"
64+
dir="ltr"
65+
>
66+
Likes <span v-if="status === 'success'">({{ likes.likes.records.length ?? 0 }})</span>
67+
</h1>
68+
<div v-if="status === 'pending'">
69+
<p>Loading...</p>
70+
</div>
71+
<div v-else-if="status === 'error'">
72+
<p>Error</p>
73+
</div>
74+
<div v-else class="grid grid-cols-1 lg:grid-cols-3 gap-4">
75+
<NuxtLink
76+
:to="{
77+
name: 'package-pkg',
78+
params: { pkg: extractPackageFromRef(like.value.subjectRef) },
79+
}"
80+
v-for="like in likes.likes.records"
81+
>
82+
<BaseCard class="group font-mono flex justify-between">
83+
<p>
84+
{{ extractPackageFromRef(like.value.subjectRef) }}
85+
</p>
86+
<p class="transition-transform duration-150 group-hover:rotate-45">↗</p>
87+
</BaseCard>
88+
</NuxtLink>
5289
</div>
53-
</div>
90+
</section>
5491
</main>
5592
</template>

server/api/social/profile/[identifier]/index.get.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@ export default defineEventHandler(async event => {
99

1010
const profileUtil = new ProfileUtils()
1111
const profile = await profileUtil.getProfile(identifier)
12-
console.log('ENDPOINT', { identifier, profile })
1312
return profile
1413
})

server/utils/atproto/utils/likes.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,11 @@ export class PackageLikesUtils {
265265
const client = new Client(miniDoc.pds, {
266266
headers: { 'User-Agent': 'npmx' },
267267
})
268-
const result = client.list(dev.npmx.feed.like, {
268+
const result = await client.list(dev.npmx.feed.like, {
269269
limit,
270270
repo: miniDoc.did,
271271
})
272+
272273
return result
273274
}
274275
}

server/utils/atproto/utils/profile.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ export class ProfileUtils {
3838
miniDoc = cachedMiniDoc
3939
} else {
4040
const resolveUrl = `https://${SLINGSHOT_HOST}/xrpc/blue.microcosm.identity.resolveMiniDoc?identifier=${encodeURIComponent(handle)}`
41-
console.log({ resolveUrl })
4241
const response = await fetch(resolveUrl, {
4342
headers: { 'User-Agent': 'npmx' },
4443
})
@@ -47,7 +46,6 @@ export class ProfileUtils {
4746
miniDoc = value
4847
await this.cache.set(miniDocKey, value, CACHE_MAX_AGE)
4948
}
50-
console.log({ miniDoc })
5149

5250
return miniDoc
5351
}

0 commit comments

Comments
 (0)