-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
666 additions
and
578 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import Wpapi from 'wpapi' | ||
import { GET_FRONTPAGE, GET_ARCHIVES, GET_PAGE, GET_SINGLE, WP_API, WP_POSTS_PER_PAGE, WP_PAGE_ON_FRONT } from '../constants' | ||
|
||
const wp = new Wpapi({ endpoint: WP_API }) | ||
|
||
/* | ||
* frontpage | ||
*/ | ||
export const getFrontpage = (loading) => { | ||
return function (dispatch) { | ||
dispatch(receivePost(GET_FRONTPAGE, '', '', '', loading = true)) | ||
if (WP_PAGE_ON_FRONT !== '0') { | ||
wp.pages().id(WP_PAGE_ON_FRONT).embed().then((res) => { | ||
dispatch(receivePost(GET_FRONTPAGE, res.id, res.title.rendered, res.content.rendered, loading = false)) | ||
}).catch((err) => { | ||
console.log(err) | ||
}) | ||
} else { | ||
const notFrontpage = { | ||
id: '', | ||
title: 'Frontpage', | ||
content: 'No static Frontpage is selected.' | ||
} | ||
dispatch(receivePost(GET_FRONTPAGE, notFrontpage.id, notFrontpage.title, notFrontpage.content, loading = false)) | ||
} | ||
} | ||
} | ||
|
||
/* | ||
* page | ||
*/ | ||
export const getPage = (route, loading) => { | ||
return function (dispatch) { | ||
dispatch(receivePost(GET_PAGE, '', '', '', loading = true)) | ||
return wp.pages().slug(route.path).embed().then((res) => { | ||
dispatch(receivePost(GET_PAGE, res[0].id, res[0].title.rendered, res[0].content.rendered, loading = false)) | ||
}).catch((err) => { | ||
console.log(err) | ||
}) | ||
} | ||
} | ||
|
||
/* | ||
* single | ||
*/ | ||
export const getSingle = (params, loading) => { | ||
return function (dispatch) { | ||
dispatch(receivePost(GET_SINGLE, '', '', '', loading = true)) | ||
return wp.posts().id(params.id).embed().then((res) => { | ||
dispatch(receivePost(GET_SINGLE, res.id, res.title.rendered, res.content.rendered, loading = false)) | ||
}).catch((err) => { | ||
console.log(err) | ||
}) | ||
} | ||
} | ||
|
||
function receivePost (type, id, title, content, loading) { | ||
return { | ||
type: type, | ||
payload: { | ||
id: id, | ||
title: title, | ||
content: content, | ||
loading: loading | ||
} | ||
} | ||
} | ||
|
||
/* | ||
* archive | ||
*/ | ||
export const getArchive = (loading, pageNum = 1, totalPages, posts) => { | ||
return function (dispatch) { | ||
dispatch(receiveArchive(loading = true, pageNum, totalPages, posts)) | ||
return wp.posts().page(pageNum).perPage(WP_POSTS_PER_PAGE).embed().then((res) => { | ||
const totalPages = res._paging.totalPages | ||
dispatch(receiveArchive(loading = false, pageNum, totalPages, res)) | ||
}).catch((err) => { | ||
console.log(err) | ||
}) | ||
} | ||
} | ||
|
||
function receiveArchive (loading, pageNum, totalPages, posts) { | ||
return { | ||
type: GET_ARCHIVES, | ||
payload: { | ||
pageNum: pageNum, | ||
totalPages: totalPages, | ||
posts: posts, | ||
loading: loading | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from 'react' | ||
import { createDevTools } from 'redux-devtools' | ||
import LogMonitor from 'redux-devtools-log-monitor' | ||
import DockMonitor from 'redux-devtools-dock-monitor' | ||
|
||
export default createDevTools( | ||
<DockMonitor toggleVisibilityKey='ctrl-h' changePositionKey='ctrl-q'> | ||
<LogMonitor theme='tomorrow' preserveScrollTop={false} /> | ||
</DockMonitor> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import React from 'react' | ||
|
||
const Footer = (props) => { | ||
const Footer = () => { | ||
return ( | ||
<footer /> | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react' | ||
|
||
const Loader = () => { | ||
return ( | ||
<div> | ||
Loading... | ||
</div> | ||
) | ||
} | ||
|
||
export default Loader |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from 'react' | ||
|
||
const Post = ({ id, title, content }) => { | ||
return ( | ||
<article key={id}> | ||
<h2>{title}</h2> | ||
<div dangerouslySetInnerHTML={{__html: content}} /> | ||
</article> | ||
) | ||
} | ||
|
||
export default Post |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React from 'react' | ||
import { Link } from 'react-router' | ||
|
||
const PostsList = ({ id, title, date }) => { | ||
const url = `archives/${id}` | ||
return ( | ||
<Link to={url} key={id}> | ||
<h2>{title.rendered}</h2> | ||
<p>{date}</p> | ||
</Link> | ||
) | ||
} | ||
|
||
export default PostsList |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,13 @@ | ||
export const WP_PARAMS = global.WP_PARAMETERS | ||
const WP_PARAMS = global.WP_PARAMETERS | ||
|
||
export const WP_URL = WP_PARAMS.API | ||
export const WP_SITE_TITLE = WP_PARAMS.SITE_TITLE | ||
export const WP_SITE_DESCRIPTION = WP_PARAMS.SITE_DESCRIPTION | ||
export const WP_API = WP_PARAMS.API | ||
export const WP_PAGE_ON_FRONT = WP_PARAMS.PAGE_ON_FRONT | ||
export const WP_POSTS_PER_PAGE = WP_PARAMS.POSTS_PER_PAGE | ||
|
||
export const GET_FRONTPAGE = 'GET_FRONTPAGE' | ||
export const GET_PAGE = 'GET_PAGE' | ||
export const GET_ARCHIVES = 'GET_ARCHIVES' | ||
export const GET_SINGLE = 'GET_SINGLE' |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React, { Component } from 'react' | ||
import { connect } from 'react-redux' | ||
import { getArchive } from '../actions' | ||
import { WP_SITE_TITLE } from '../constants' | ||
import PostsList from '../components/PostsList' | ||
import Loader from '../components/Loader' | ||
|
||
class Archive extends Component { | ||
componentWillMount () { | ||
const { | ||
getArchive, | ||
pageNum = 1, | ||
loading = true, | ||
totalPages, | ||
posts | ||
} = this.props | ||
|
||
getArchive(loading, pageNum, totalPages, posts) | ||
} | ||
|
||
render () { | ||
const { posts, loading } = this.props | ||
let list = posts.map((post) => { | ||
return ( | ||
<PostsList key={post.id} {...post} /> | ||
) | ||
}) | ||
|
||
document.title = 'Archive | ' + WP_SITE_TITLE | ||
|
||
return ( | ||
<div> | ||
{loading ? <Loader /> : list} | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
function mapStateToProps (state) { | ||
return { | ||
posts: state.archive.posts, | ||
pageNum: state.archive.pageNum, | ||
totalPages: state.archive.totalPages, | ||
loading: state.archive.loading | ||
} | ||
} | ||
|
||
export default connect(mapStateToProps, {getArchive})(Archive) |
Oops, something went wrong.