Skip to content

Commit b4edaee

Browse files
committed
pagination function working w/ dummy data from axios, styling completed, WIP link funct to user guides
1 parent fad074f commit b4edaee

File tree

7 files changed

+86
-172
lines changed

7 files changed

+86
-172
lines changed

how-to/src/components/MyGuidePosts.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,20 @@ import React from 'react';
22
import { Card, Image } from "semantic-ui-react";
33
import choco from "../chocomilk.jpg";
44

5-
const MyGuidePosts = (props) => {
5+
const MyGuidePosts = ({ posts, loading }) => {
6+
if(loading) {
7+
return <h2>Loading...</h2>;
8+
}
69

710
return (
811
<div>
9-
{props.pages.map(pagee => (
12+
{posts.map(post => (
1013
<Card.Group>
1114
<Image src={choco} avatar />
1215
<Card>
1316
<Card.Content>
14-
<Card.Header>{pagee.pageTitle}</Card.Header>
15-
<Card.Description>{pagee.pageDesc}</Card.Description>
17+
<Card.Header>{post.title}</Card.Header>
18+
<Card.Description>{post.body}</Card.Description>
1619
</Card.Content>
1720
</Card>
1821
</Card.Group>

how-to/src/components/MyGuides.css

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,39 @@
1-
div.ui.cards {
1+
/* div.ui.cards {
22
background: #7EA85E;
33
margin-bottom: 2em;
44
width: fit-content;
5-
65
height: 115px;
76
font-size: 0.76rem;
8-
}
97
10-
div.ui.cards>.card {
8+
padding: 0;
9+
display: flex;
10+
flex-direction: column;
11+
} */
12+
13+
/* div.ui.cards>.card {
1114
background: #7EA85E;
1215
border: none;
13-
display: contents;
16+
display: flex;
1417
font-size: 1.1em;
1518
margin-left: 15px;
1619
}
1720
21+
*/
22+
23+
div.ui.cards {
24+
margin-bottom: 20px;
25+
}
26+
1827
img.ui.avatar.image {
19-
width: 6em;
20-
height: 6em;
28+
width: 7em;
29+
height: 7em;
30+
margin: 0 auto;
31+
margin-bottom: 10px;
32+
margin-top: -15px;
2133
}
2234

2335
p {
2436
padding-bottom: 8px;
2537
width: 353px;
26-
}
38+
}
39+

how-to/src/components/MyGuides.js

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import React, { useEffect } from "react";
2-
import { Header, Card, Image, Pagination } from "semantic-ui-react";
2+
import { Header } from "semantic-ui-react";
33
import { Link } from "react-router-dom";
44
import styled from "styled-components";
55
import { connect } from "react-redux";
66
import GuideCard from "./GuideCard";
77
import { getGuides, getUsers } from "../store/actions";
88
import decode from "jwt-decode";
99

10-
import choco from "../chocomilk.jpg";
1110
import "./MyGuides.css";
11+
import MyGuidePosts from "./MyGuidePosts.js";
12+
import Pagination from './Pagination.js';
1213

1314
const GuideContainer = styled.div`
1415
margin: 0 auto;
@@ -36,10 +37,12 @@ if (localStorage.token) {
3637
}
3738

3839
function MyGuides({ guides, users, getGuides, getUsers }) {
40+
3941
useEffect(() => {
4042
getGuides();
4143
getUsers();
4244
}, [getGuides, getUsers]);
45+
4346
return (
4447
<div>
4548
<GuideContainer>
@@ -61,15 +64,6 @@ function MyGuides({ guides, users, getGuides, getUsers }) {
6164
))
6265
: null}
6366

64-
<Pagination
65-
boundaryRange={0}
66-
defaultActivePage={1}
67-
ellipsisItem={null}
68-
firstItem={null}
69-
lastItem={null}
70-
siblingRange={1}
71-
// totalPages={10}
72-
/>
7367
</GuideContainer>
7468
</div>
7569
);
@@ -86,3 +80,35 @@ export default connect(
8680
mapStateToProps,
8781
{ getGuides, getUsers }
8882
)(MyGuides);
83+
84+
85+
// const [posts, setPosts] = useState([]);
86+
// const [loading, setLoading] = useState("false");
87+
// const [currentPage, setCurrentPage] = useState(1);
88+
// const [postsPerPage] = useState(3);
89+
90+
// useEffect(() => {
91+
// const fetchPosts = async () => {
92+
// setLoading(true);
93+
// const res = await axios.get('https://jsonplaceholder.typicode.com/posts');
94+
// setPosts(res.data);
95+
// setLoading(false);
96+
// }
97+
98+
// fetchPosts();
99+
// }, []);
100+
101+
// // Get current posts
102+
// const indexOfLastPost = currentPage * postsPerPage;
103+
// const indexOfFirstPost = indexOfLastPost - postsPerPage;
104+
// const currentPosts2 = posts.slice(indexOfFirstPost, indexOfLastPost);
105+
106+
// Change page
107+
// const paginate = pageNumber => setCurrentPage(pageNumber);
108+
109+
// Pagination function in return();
110+
{/* <Pagination
111+
postsPerPage={postsPerPage}
112+
totalPosts={posts.length}
113+
paginate={paginate}
114+
/> */}

how-to/src/components/MyGuides2.js

Lines changed: 0 additions & 118 deletions
This file was deleted.

how-to/src/components/Paginate.js

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React from 'react';
2+
3+
const Pagination = ({ postsPerPage, totalPosts, paginate }) => {
4+
const pageNumbers = [];
5+
6+
for(let i = 1; i <= Math.ceil(totalPosts / postsPerPage); i++) {
7+
pageNumbers.push(i);
8+
}
9+
10+
return (
11+
<div>
12+
{pageNumbers.map(number => (
13+
<span onClick={() => paginate(number)}>
14+
{number + " "}
15+
</span>
16+
))}
17+
</div>
18+
);
19+
};
20+
21+
export default Pagination;

how-to/src/components/Welcome.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
import React from "react";
22
import "../../src/index.css";
3-
import { Link } from "react-router-dom";
4-
5-
// testing use: remove imports later
6-
import Guide from "./Guide.js";
7-
import MyGuides2 from "./MyGuides2.js";
83

94
function Welcome() {
105
return (
116
<div>
12-
<MyGuides2 />
137
<h1 className="ui header">WELCOME TO HOW-TO</h1>
148
</div>
159
);

0 commit comments

Comments
 (0)