Guest User

Untitled

a guest
Jun 22nd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import { withRouter } from 'react-router';
  3.  
  4. import ArchiveContainer from 'app/components/ArchiveContainer';
  5. import GlobalFooter from 'app/components/Layout/GlobalFooter';
  6.  
  7. import { getServerPosts, getPostsSuccess, getPostsFail } from 'app/actions/archive';
  8.  
  9. // getServerPosts function from app/actions/archive
  10. export function getServerPosts(queryVars, source) {
  11. const params = {
  12. per_page: PAGING.postsPerPage,
  13. category_names: queryVars.category || null,
  14. tag_names: queryVars.tag || null,
  15. search: queryVars.searchString || null,
  16. page: queryVars.paged || 1,
  17. };
  18.  
  19. const cancelToken = source ? { cancelToken: source.token } : {};
  20.  
  21. return axios.get(
  22. 'wp-json/sujin/v1/posts/',
  23. { params },
  24. { ...cancelToken },
  25. );
  26. }
  27.  
  28. class Archive extends Component {
  29. static serverFetch(url) {
  30. const arrUrl = url.split('/').filter(v => v);
  31.  
  32. const queryVars = {
  33. category: arrUrl[0] === 'category' ? arrUrl[1] : null,
  34. tag: arrUrl[0] === 'tag' ? arrUrl[1] : null,
  35. searchString: arrUrl[0] === 'search' ? arrUrl[1] : null,
  36. paged: arrUrl[3] || null,
  37. };
  38.  
  39. return getServerPosts(queryVars)
  40. .then(response => getPostsSuccess(response))
  41. .catch(error => getPostsFail(error));
  42. }
  43.  
  44. render() {
  45. return (
  46. <section className="template-archive">
  47. <main className="page-wrapper">
  48. <ArchiveContainer push={this.props.history.push} params={this.props.match.params} />
  49. </main>
  50.  
  51. <GlobalFooter />
  52. </section>
  53. );
  54. }
  55. }
  56.  
  57. export default withRouter(Archive);
Add Comment
Please, Sign In to add comment