Skip to content

Conversation

@ashiii1
Copy link

@ashiii1 ashiii1 commented Oct 19, 2024

LIVE: https://devblogs-frontend.vercel.app/

Added similar post cards for improved user navigation.
Implemented a back arrow for returning to the home page.
Similar cards are displayed below the main post.
Each card includes a title and image, and is clickable to redirect to the corresponding post detail page.

Screen.Recording.2024-10-19.141219.mp4

Type of Change

  • New feature (non-breaking change which adds functionality)

Screenshots

image

Additional Information

Comment on lines -5 to -41
const RecentPosts = () => {
const [posts, setPosts] = useState([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);

// Fetch posts from the /get-blogs route
useEffect(() => {
const fetchPosts = async () => {
try {
const response = await fetch("/get-blogs");

// Check if the response is JSON because sometime response geting is not in json
const contentType = response.headers.get("content-type");
if (!contentType || !contentType.includes("application/json")) {
throw new Error("Expected JSON, received: " + contentType);
}

const data = await response.json();
setPosts(data);
setLoading(false);
} catch (error) {
setError(error.message);
setLoading(false);
}
};

fetchPosts();
}, []);

if (loading) {
return <p className="text-white">Loading...</p>;
}

if (error) {
return <p className="text-red-500">Error: {error}</p>;
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dont remove this. We need to fetch posts instead of displaying mock data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants