import React from 'react'; import { Box, Text, useColorModeValue } from '@chakra-ui/react'; import SavedPostItem from './SavedPostItem'; import { BsBookmark } from 'react-icons/bs'; import SavedPostItemSkeleton from '../skeletons/SavedPostItemSkeleton'; import { useLocation } from 'react-router-dom'; const Container = ({ children }) => { return ( {children} ); }; const NoFilteredPostMessage = () => { return ( Nothing with this filter 🤔 ); }; const Right = ({ savedPosts, archivedPosts, selectedTagName, searchTerm, loading, }) => { const location = useLocation(); const queryParam = new URLSearchParams(location.search); const query = queryParam.get(''); let transformedSavedPosts = []; const currentPosts = query ? archivedPosts : savedPosts; currentPosts.forEach((postData) => { const tags = postData.tags; if (selectedTagName === 'All tags') { transformedSavedPosts = currentPosts; return; } if ( tags.length !== 0 && tags.find((item) => item.tagName === selectedTagName) ) { transformedSavedPosts.push(postData); } }); const filteredPosts = transformedSavedPosts.filter((postData) => postData.title.toLowerCase().includes(searchTerm.toLowerCase()) ); const titleColor = useColorModeValue('#3d3d3d', '#d6d6d7'); const discriptionColor = useColorModeValue('#717171', '#a3a3a3'); if (!loading && currentPosts.length === 0) { return ( Your {query ? 'archive' : 'reading'} list is empty {!query && ( Click the bookmark reaction {' '} {' '} when viewing a post to add it to your reading list. )} ); } return ( {loading && } {!loading && filteredPosts.length === 0 && } {filteredPosts.map((postData) => ( ))} ); }; export default Right;