-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Show list tab on user profile page (#119)
- Loading branch information
Showing
2 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import { LabelChip, ModerationLabel } from '@/common/labels' | ||
import { Loading } from '@/common/Loader' | ||
import client from '@/lib/client' | ||
import { buildBlueSkyAppUrl } from '@/lib/util' | ||
import { useInfiniteQuery } from '@tanstack/react-query' | ||
import Link from 'next/link' | ||
|
||
export function Lists({ actor }: { actor: string }) { | ||
const { data, fetchNextPage, hasNextPage, isInitialLoading } = | ||
useInfiniteQuery({ | ||
queryKey: ['lists', { actor }], | ||
queryFn: async ({ pageParam }) => { | ||
const { data } = await client.api.app.bsky.graph.getLists( | ||
{ | ||
actor, | ||
limit: 25, | ||
cursor: pageParam, | ||
}, | ||
{ headers: client.proxyHeaders() }, | ||
) | ||
return data | ||
}, | ||
getNextPageParam: (lastPage) => lastPage.cursor, | ||
}) | ||
|
||
console.log(data, hasNextPage) | ||
|
||
if (isInitialLoading) { | ||
return ( | ||
<div className="py-8 mx-auto max-w-5xl px-4 sm:px-6 lg:px-12 text-xl"> | ||
<Loading /> | ||
</div> | ||
) | ||
} | ||
|
||
if (!data) { | ||
return ( | ||
<div className="py-8 mx-auto max-w-5xl px-4 sm:px-6 lg:px-12 text-xl"> | ||
<p>No lists found.</p> | ||
</div> | ||
) | ||
} | ||
|
||
const lists = data.pages.flatMap((page) => page.lists) | ||
|
||
return ( | ||
<div className="mx-auto mt-8 max-w-5xl px-4 pb-12 sm:px-6 lg:px-8"> | ||
<div className="mt-1 grid grid-cols-1 gap-4 sm:grid-cols-2 text-gray-900 dark:text-gray-200"> | ||
{lists.map((list) => ( | ||
<div | ||
key={list.uri} | ||
className="relative rounded-lg border border-gray-300 dark:border-slate-700 bg-white dark:bg-slate-800 p-3 shadow-sm dark:shadow-slate-800 focus-within:ring-2 focus-within:ring-pink-500 focus-within:ring-teal-500 focus-within:ring-offset-2 hover:border-gray-400 dark:hover:border-slate-700" | ||
> | ||
<p> | ||
<Link | ||
href={`/repositories/${list.uri.replace('at://', '')}`} | ||
className="hover:underline" | ||
> | ||
<span>{list.name}</span> | ||
</Link> | ||
· | ||
<a | ||
href={buildBlueSkyAppUrl({ | ||
did: list.creator.did, | ||
collection: 'lists', | ||
rkey: list.uri.split('/').pop(), | ||
})} | ||
target="_blank" | ||
rel="noreferrer" | ||
className="text-sm" | ||
> | ||
Peek | ||
</a> | ||
</p> | ||
<p className="text-sm"> | ||
Created By{' '} | ||
<Link | ||
href={`/repositories/${list.creator.did}`} | ||
className="focus:outline-none" | ||
> | ||
<span> | ||
{list.creator.displayName || ''} | ||
{` @${list.creator.handle}`} | ||
</span> | ||
</Link> | ||
</p> | ||
{list.description && ( | ||
<p className="text-sm text-gray-500 dark:text-gray-300"> | ||
{list.description} | ||
</p> | ||
)} | ||
<div className="pt-2"> | ||
<LabelChip className="bg-red-200 ml-0"> | ||
{list.purpose.split('#')[1]} | ||
</LabelChip> | ||
{list.labels?.map((label) => ( | ||
<ModerationLabel | ||
recordAuthorDid={list.creator.did} | ||
label={label} | ||
key={label.val} | ||
/> | ||
))} | ||
</div> | ||
</div> | ||
))} | ||
</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters