Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3340588
D13743.id45251.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D13743.id45251.diff
View Options
diff --git a/lib/hooks/fc-cache.js b/lib/hooks/fc-cache.js
--- a/lib/hooks/fc-cache.js
+++ b/lib/hooks/fc-cache.js
@@ -181,4 +181,46 @@
}, [fid, cachedAvatarURL, farcasterAvatarURL]);
}
-export { useFCNames, useFarcasterUserAvatarURL };
+function useFarcasterChannelAvatarURL(channelID: ?string): ?string {
+ const neynarClientContext = React.useContext(NeynarClientContext);
+ const fcCache = neynarClientContext?.fcCache;
+
+ const cachedAvatarURL = React.useMemo(() => {
+ if (!channelID || !fcCache) {
+ return null;
+ }
+ const cachedChannel =
+ fcCache.getCachedFarcasterChannelForChannelID(channelID);
+ return cachedChannel?.image_url ?? null;
+ }, [fcCache, channelID]);
+
+ const [farcasterAvatarURL, setFarcasterAvatarURL] =
+ React.useState<?string>(null);
+
+ React.useEffect(() => {
+ if (!fcCache || !channelID || cachedAvatarURL) {
+ return;
+ }
+ void (async () => {
+ const farcasterChannel =
+ await fcCache.getFarcasterChannelForChannelID(channelID);
+ const avatarURL = farcasterChannel?.image_url;
+ if (!avatarURL) {
+ return;
+ }
+ setFarcasterAvatarURL(avatarURL);
+ })();
+ }, [fcCache, cachedAvatarURL, channelID]);
+
+ return React.useMemo(() => {
+ if (!channelID) {
+ return null;
+ } else if (cachedAvatarURL) {
+ return cachedAvatarURL;
+ } else {
+ return farcasterAvatarURL;
+ }
+ }, [channelID, cachedAvatarURL, farcasterAvatarURL]);
+}
+
+export { useFCNames, useFarcasterUserAvatarURL, useFarcasterChannelAvatarURL };
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 22, 10:04 PM (16 h, 33 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2563498
Default Alt Text
D13743.id45251.diff (1 KB)
Attached To
Mode
D13743: [lib] add hook to fetch channel avatar url
Attached
Detach File
Event Timeline
Log In to Comment