@@ -5,95 +5,90 @@ import Layout from "../components/Layout";
55import Search from "../components/Search" ;
66import { PostTemplate } from "../templates/post.js" ;
77
8- class IndexPage extends React . Component {
9- state = { search : "" } ;
8+ const IndexPage = ( { pageContext } ) => {
9+ //const [search, setSearch] = useState("");
10+ // const [searchMatches, setSearchMatches] = useState([]);
1011
11- render ( ) {
12- const { pageContext } = this . props ;
13- const { group, index, first, last, pageCount } = pageContext ;
14- const previousUrl = index - 1 == 1 ? "/" : `/page/${ index - 1 } ` ;
15- const nextUrl = "/page/" + ( index + 1 ) . toString ( ) ;
16- const { search } = this . state ;
12+ const { group, index, first, last, pageCount } = pageContext ;
13+ const previousUrl = index - 1 == 1 ? "/" : `/page/${ index - 1 } ` ;
14+ const nextUrl = "/page/" + ( index + 1 ) . toString ( ) ;
1715
18- // const filteredPosts = search ? searchPosts(posts, search) : posts;
16+ return (
17+ < Layout >
18+ { /*
19+ <Search
20+ value={search}
21+ onChange={value => setSearch({ search: value })}
22+ />
23+ */ }
1924
20- return (
21- < Layout >
22- { /*
23- <Search
24- value={this.search }
25- onChange={value => this.setState({ search: value }) }
25+ { group . map ( ( { node } ) => (
26+ < PostTemplate
27+ key = { node . id }
28+ content = { node . html }
29+ frontmatter = { node . frontmatter }
30+ slug = { node . fields . slug }
2631 />
27- */ }
28-
29- { group . map ( ( { node } ) => (
30- < PostTemplate
31- key = { node . id }
32- content = { node . html }
33- frontmatter = { node . frontmatter }
34- slug = { node . fields . slug }
35- />
36- ) ) }
32+ ) ) }
3733
38- < nav
39- className = "pagination is-centered"
40- role = "navigation"
41- aria-label = "pagination"
34+ < nav
35+ className = "pagination is-centered"
36+ role = "navigation"
37+ aria-label = "pagination"
38+ style = { {
39+ maxWidth : "600px" ,
40+ margin : "0 auto"
41+ } }
42+ >
43+ < Link
44+ className = "pagination-previous"
45+ to = { previousUrl }
46+ disabled = { first }
4247 style = { {
43- maxWidth : "600px" ,
44- margin : "0 auto"
48+ // Temp hack to prevent clicking
49+ // TODO: Render a link without a href instead
50+ pointerEvents : first ? "none" : "auto"
4551 } }
4652 >
47- < Link
48- className = "pagination-previous"
49- to = { previousUrl }
50- disabled = { first }
51- style = { {
52- // Temp hack to prevent clicking
53- // TODO: Render a link without a href instead
54- pointerEvents : first ? "none" : "auto"
55- } }
56- >
57- Previous
58- </ Link >
59- < Link
60- className = "pagination-next"
61- to = { nextUrl }
62- disabled = { last }
63- style = { {
64- pointerEvents : last ? "none" : "auto"
65- } }
66- >
67- Next Page
68- </ Link >
69- < ul className = "pagination-list" >
70- { Array ( pageCount )
71- . fill ( null )
72- . map ( ( value , i ) => {
73- const pageNum = i + 1 ;
74- const isCurrent = index === pageNum ;
75- const url = pageNum === 1 ? "/" : `/page/${ pageNum } ` ;
53+ Previous
54+ </ Link >
55+ < Link
56+ className = "pagination-next"
57+ to = { nextUrl }
58+ disabled = { last }
59+ style = { {
60+ pointerEvents : last ? "none" : "auto"
61+ } }
62+ >
63+ Next Page
64+ </ Link >
65+ < ul className = "pagination-list" >
66+ { Array ( pageCount )
67+ . fill ( null )
68+ . map ( ( value , i ) => {
69+ const pageNum = i + 1 ;
70+ const isCurrent = index === pageNum ;
71+ const url = pageNum === 1 ? "/" : `/page/${ pageNum } ` ;
7672
77- return (
78- < li key = { i } >
79- < Link
80- className = {
81- "pagination-link" + ( isCurrent ? " is-current" : "" )
82- }
83- to = { url }
84- >
85- { pageNum }
86- </ Link >
87- </ li >
88- ) ;
89- } ) }
90- </ ul >
91- { /*<span>{` Page ${index} of ${pageCount}`}</span>*/ }
92- </ nav >
93- </ Layout >
94- ) ;
95- }
96- }
73+ return (
74+ < li key = { i } >
75+ < Link
76+ className = {
77+ "pagination-link" + ( isCurrent ? " is-current" : "" )
78+ }
79+ to = { url }
80+ >
81+ { pageNum }
82+ </ Link >
83+ </ li >
84+ ) ;
85+ } ) }
86+ </ ul >
87+ { /*<span>{` Page ${index} of ${pageCount}`}</span>*/ }
88+ </ nav >
89+ </ Layout >
90+ ) ;
91+ } ;
9792
9893export default IndexPage ;
9994
0 commit comments