Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TODO] Build a Blog page #24

Open
gbowne1 opened this issue Apr 22, 2023 · 3 comments
Open

[TODO] Build a Blog page #24

gbowne1 opened this issue Apr 22, 2023 · 3 comments
Labels
bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request good first issue Good for newcomers hacktoberbest The hacktoberfest label help wanted Extra attention is needed question Further information is requested

Comments

@gbowne1
Copy link
Owner

gbowne1 commented Apr 22, 2023

I just added a new Blog.jsx to the App as a baseline to start with.

I need a paginated Blog container with a comment container. so people can page through my different posts with breadcrumbs or tabs.

I want to be able to include a picture with my blog post.

I also created a boilerplate Editor.jsx too that can be included. Will push this up tonight.

@gbowne1 gbowne1 added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels Apr 22, 2023
@gbowne1 gbowne1 added this to the Finish v1.0 of Frontend milestone Apr 22, 2023
@gbowne1
Copy link
Owner Author

gbowne1 commented Apr 22, 2023

@k-deepak04

I added Editor.jsx and made some changes to Blog.jsx last night

Editor.jsx should be a component internal to the Blog.jsx

@k-deepak04
Copy link
Collaborator

@gbowne1 i'll pull the changes and see the things.

k-deepak04 added a commit that referenced this issue Apr 22, 2023
tried building a good pagination
@gbowne1
Copy link
Owner Author

gbowne1 commented Apr 22, 2023

My thought was:

Blog.jsx

import React, { useState, useEffect } from 'react';
import Post from './Post';

const Blog = () => {
  const [posts, setPosts] = useState([]);

  useEffect(() => {
    fetch('/api/posts')
      .then(response => response.json())
      .then(data => setPosts(data));
  }, []);

  return (
    <div>
      <h1>My Personal Blog</h1>
      {posts.map(post => (
        <Post key={post.id} post={post} />
      ))}
    </div>
  );
};

export default Blog;

Post.jsx

import React, { useState } from 'react';
import { Pagination } from '@mui/material';

const Post = ({ post }) => {
  const [page, setPage] = useState(1);
  const postsPerPage = 5;
  const startIndex = (page - 1) * postsPerPage;
  const endIndex = startIndex + postsPerPage;
  const paginatedPosts = post.slice(startIndex, endIndex);

  const handlePageChange = (event, value) => {
    setPage(value);
  };

  return (
    <div>
      {paginatedPosts.map(p => (
        <div key={p.id}>
          <h2>{p.title}</h2>
          <p>{p.content}</p>
        </div>
      ))}
      <Pagination count={Math.ceil(post.length / postsPerPage)} page={page} onChange={handlePageChange} />
    </div>
  );
};

export default Post;


or an alternative Post.jsx
```jsx
import React from 'react';
import { Breadcrumbs, Link } from '@mui/material';

const Post = ({ post }) => {
  return (
    <div>
      <Breadcrumbs aria-label="breadcrumb">
        <Link color="inherit" href="/">
          Home
        </Link>
        <Link color="inherit" href="/blog">
          Blog
        </Link>
        <Link color="inherit" href={`/blog/\${post.id}`}>
          {post.title}
        </Link>
      </Breadcrumbs>
      <h2>{post.title}</h2>
      <p>{post.content}</p>
    </div>
  );
};

export default Post;

@gbowne1 gbowne1 added bug Something isn't working documentation Improvements or additions to documentation question Further information is requested hacktoberbest The hacktoberfest label labels Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request good first issue Good for newcomers hacktoberbest The hacktoberfest label help wanted Extra attention is needed question Further information is requested
Development

No branches or pull requests

2 participants