-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
167 additions
and
45 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
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,75 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import { CastType } from "@/common/constants/farcaster" | ||
import { getNeynarCastThreadEndpoint } from "../helpers/neynar"; | ||
import { Loading } from "./Loading"; | ||
import { CastRow } from "./CastRow"; | ||
import { useAccountStore } from "@/stores/useAccountStore"; | ||
|
||
// todo: cast in thread has slightly different structure | ||
// pfps don't seem to render | ||
// can auto expand images | ||
// add up down selector hotkeys in list with j and k | ||
|
||
export const CastThreadView = ({ cast, onBack, fid }: { cast: CastType, onBack: () => void, fid?: string }) => { | ||
const [isLoading, setIsLoading] = useState(true); | ||
const [casts, setCasts] = useState<CastType[]>([]); | ||
|
||
const { | ||
channels, | ||
selectedChannelIdx | ||
} = useAccountStore(); | ||
|
||
const renderGoBackButton = () => ( | ||
<button | ||
type="button" | ||
className="w-20 inline-flex items-center px-2 py-1 border border-transparent shadow-sm text-sm font-medium rounded-sm text-gray-100 bg-gray-700 hover:bg-gray-600 focus:outline-none" | ||
onClick={() => onBack()} | ||
> | ||
go back | ||
</button> | ||
); | ||
|
||
useEffect(() => { | ||
const loadData = async () => { | ||
const neynarEndpoint = getNeynarCastThreadEndpoint({ castHash: cast.hash, fid }); | ||
await fetch(neynarEndpoint) | ||
.then((response) => response.json()) | ||
.then((resp) => { | ||
console.log(resp.result.casts) | ||
setCasts(resp.result.casts) | ||
}) | ||
.catch((error) => { | ||
console.log({ error }) | ||
}) | ||
.finally(() => { | ||
setIsLoading(false) | ||
}) | ||
} | ||
|
||
loadData(); | ||
}, []) | ||
|
||
const renderThread = () => ( | ||
<ul role="list" className="divide-y divide-gray-700"> | ||
{casts.map((cast: CastType, idx: number) => ( | ||
<li key={cast.hash} | ||
className="relative flex items-center space-x-4 py-2 max-w-full md:max-w-2xl xl:max-w-4xl"> | ||
<CastRow | ||
cast={cast} | ||
channels={channels} | ||
showChannel={selectedChannelIdx === null} | ||
/* isSelected={selectedCastIdx === idx} */ | ||
/* onSelect={() => selectedCastIdx === idx ? onSelectCast(idx) : setSelectedCastIdx(idx)} */ | ||
/> | ||
</li> | ||
))} | ||
</ul> | ||
); | ||
|
||
return <div className="flex flex-col text-gray-100 text-lg"> | ||
{isLoading ? <Loading /> : renderThread()} | ||
<div className="py-2"> | ||
{renderGoBackButton()} | ||
</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
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 @@ | ||
export const Loading = () => <span className="my-4 font-semibold text-gray-200">Loading...</span> |
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,42 @@ | ||
import { VITE_NEYNAR_API_KEY } from "@/common/constants/farcaster"; | ||
|
||
const DEFAULT_FEED_PAGE_SIZE = 15; | ||
|
||
type FeedEndpointProps = { | ||
fid?: string; | ||
parentUrl?: string; | ||
cursor?: string; | ||
limit?: number; | ||
}; | ||
|
||
type CastThreadEndpointProps = { | ||
castHash: string; | ||
fid?: string; | ||
} | ||
|
||
|
||
export const getNeynarFeedEndpoint = ({ fid, parentUrl, cursor, limit }: FeedEndpointProps): string => { | ||
let neynarEndpoint = `https://api.neynar.com/v2/farcaster/feed/?api_key=${VITE_NEYNAR_API_KEY}&limit=${limit || DEFAULT_FEED_PAGE_SIZE}`; | ||
|
||
if (parentUrl) { | ||
neynarEndpoint += `&feed_type=filter&filter_type=parent_url&parent_url=${parentUrl}`; | ||
} else if (fid) { | ||
neynarEndpoint += `&fid=${fid}`; | ||
} | ||
|
||
if (cursor) { | ||
neynarEndpoint += `&cursor=${cursor}`; | ||
} | ||
|
||
return neynarEndpoint; | ||
} | ||
|
||
export const getNeynarCastThreadEndpoint = ({ castHash, fid }: CastThreadEndpointProps): string => { | ||
let neynarEndpoint = `https://api.neynar.com/v1/farcaster/all-casts-in-thread/?api_key=${VITE_NEYNAR_API_KEY}&threadHash=${castHash}`; | ||
|
||
if (fid) { | ||
neynarEndpoint += `&viewerFid=${fid}`; | ||
} | ||
|
||
return neynarEndpoint; | ||
} |
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