From b4ad0cff4bbf77448b7bb49e1421ef2ab3271b66 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Wed, 28 Sep 2022 15:36:25 -0500 Subject: Add reply information to feed items --- src/view/com/util/UserInfoText.tsx | 48 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/view/com/util/UserInfoText.tsx (limited to 'src/view/com/util/UserInfoText.tsx') diff --git a/src/view/com/util/UserInfoText.tsx b/src/view/com/util/UserInfoText.tsx new file mode 100644 index 000000000..39aef3306 --- /dev/null +++ b/src/view/com/util/UserInfoText.tsx @@ -0,0 +1,48 @@ +import React, {useState, useEffect} from 'react' +import * as TodoSocialGetProfile from '../../../third-party/api/src/types/todo/social/getProfile' +import {StyleProp, Text, TextStyle} from 'react-native' +import {useStores} from '../../../state' + +export function UserInfoText({ + did, + attr, + loading, + failed, + prefix, + style, +}: { + did: string + attr?: keyof TodoSocialGetProfile.OutputSchema + loading?: string + failed?: string + prefix?: string + style?: StyleProp +}) { + attr = attr || 'name' + loading = loading || '...' + failed = failed || 'user' + + const store = useStores() + const [profile, setProfile] = useState< + undefined | TodoSocialGetProfile.OutputSchema + >(undefined) + const [didFail, setFailed] = useState(false) + + useEffect(() => { + // TODO use caching to reduce loads + store.api.todo.social.getProfile({user: did}).then( + v => { + setProfile(v.data) + }, + _err => { + setFailed(true) + }, + ) + }, [did, store.api.todo.social]) + + return ( + + {didFail ? failed : profile ? `${prefix}${profile[attr]}` : loading} + + ) +} -- cgit 1.4.1