import { useSelector } from "react-redux"; import { fetchFollowedPosts, fetchGlobalPosts, selectAllPosts, selectFollowedPosts, } from "../app/postSlice"; import { useAppDispatch } from "../app/store"; import { useEffect } from "react"; import { Box, List, Typography } from "@mui/material"; import { Post } from "../api"; import PostListItem from "../components/postListItem"; interface PostListProps { type: "all" | "user"; } export default function PostList(props: PostListProps) { const dispatch = useAppDispatch(); const followedPosts = useSelector(selectFollowedPosts); const globalPosts = useSelector(selectAllPosts); useEffect(() => { if (props.type === "all") dispatch(fetchGlobalPosts()); if (props.type === "user") dispatch(fetchFollowedPosts()); }, []); return ( {props.type === "all" && ( {globalPosts.map((post: Post) => ( ))} )} {props.type === "user" && ( {followedPosts.map((post: Post) => ( ))} {followedPosts.length === 0 && ( Whops! There is no content here! Try following some users, or check the global feed )} )} ); }