import React from 'react'; import styles from './styles.module.css'; import BlogCard from '../BlogCard'; import BounceLoader from 'react-spinners/BounceLoader'; import {getBlogPosts, getTopic} from '../../../services/DiscourseService'; export default function BlogCards({ filterCallback }) { const [cardData, setCardData] = React.useState(); const [loadingCards, setLoadingCards] = React.useState(true); const getPosts = async () => { const data = await getBlogPosts(filterCallback.join(',')); const resultset = [] if (data.topics) { for (const topic of data.topics) { resultset.push(await getPostList(topic)) } setCardData(resultset); } else { setCardData(undefined); } setLoadingCards(false); }; React.useEffect(() => { getPosts(); setCardData(undefined); setLoadingCards(true); }, [filterCallback]); if (cardData) { return (
{cardData.map(function(a, index){ return })}
); } else if (loadingCards) { return ( ); } else { return (
{' '} No Blogposts Found with the Given Search Criteria
); } } async function getPostList(topic) { const fullTopic = await getTopic(topic.id); return { name: fullTopic.details.created_by.name, excerpt: styleExcerpt(topic.excerpt), creatorImage: getavatarURL(fullTopic.details.created_by.avatar_template), tags: topic.tags, image: fullTopic.image_url, link: 'https://developer.sailpoint.com/discuss/t/' + topic.slug + '/' + topic.id, title: topic.title, views: fullTopic.views, liked: topic.like_count, replies: fullTopic.posts_count, solution: topic.has_accepted_answer, readTime: parseInt(fullTopic.word_count/100), }; } function getavatarURL(avatar) { return "https://developer.sailpoint.com" + avatar.replace("{size}", "120") } function styleExcerpt(excerpt) { if (excerpt.length > 150) { return excerpt.slice(0, 150) + "..." } else { return excerpt.replace("…", "") } }