using category as tag if not already present in post meta

This commit is contained in:
Nouman Tahir 2021-05-24 15:25:38 +05:00
parent c24739ffb4
commit 29f88adda7

View File

@ -50,6 +50,8 @@ const PostDisplayView = ({
const [refreshing, setRefreshing] = useState(false);
const [postBodyLoading, setPostBodyLoading] = useState(false);
const [tags, setTags] = useState([]);
// Component Life Cycles
useEffect(() => {
if (isLoggedIn && get(currentAccount, 'name') && !isNewPost) {
@ -57,6 +59,16 @@ const PostDisplayView = ({
}
}, []);
useEffect(() => {
if (post) {
const _tags = post.json_metadata ? post.json_metadata.tags : [];
if (post.category && _tags[0] !== post.category) {
_tags.splice(0, 0, post.category);
}
setTags(_tags);
}
}, [post]);
// Component Functions
const onRefresh = useCallback(() => {
setRefreshing(true);
@ -216,7 +228,7 @@ const PostDisplayView = ({
<PostBody body={post.body} onLoadEnd={_handleOnPostBodyLoad} />
{!postBodyLoading && (
<View style={styles.footer}>
<Tags tags={post.json_metadata && post.json_metadata.tags} />
<Tags tags={tags} />
<Text style={styles.footerText}>
Posted by
<Text style={styles.footerName}>{` ${author || post.author} `}</Text>