Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. import React from "react"
  2. import axios from "axios"
  3. import ReactHtmlParser from "react-html-parser"
  4. // import { Link } from "react-router-dom"
  5.  
  6. class Page extends React.Component {
  7. constructor(props) {
  8. super(props)
  9. this.state = {
  10. slug: {},
  11. data: [],
  12. loading: true
  13. }
  14. }
  15.  
  16. componentDidMount() {
  17. const url = "api link"
  18.  
  19. axios
  20. .get(url)
  21. .then(response => {
  22. this.setState({
  23. slug: this.props.match.params.page_slug,
  24. data: response.data,
  25. loading: false
  26. })
  27. })
  28. .catch(error => {
  29. console.log(error)
  30. })
  31. }
  32.  
  33. render() {
  34. let content
  35. let title
  36.  
  37. if (this.state.loading) {
  38. content = (
  39. <div>
  40. <div className="modal is-active">
  41. <div className="modal-background has-background-primary" />
  42. <div className="modal-content has-text-centered">
  43. <p classname="image is-48x48">
  44. <img src={process.env.PUBLIC_URL + "/img/loader.gif"} alt="" />
  45. </p>
  46. </div>
  47. </div>
  48. </div>
  49. );
  50. } else {
  51. content = this.state.data.map((response, index) => {
  52. if (response.slug === this.state.slug) {
  53. title = response.title.rendered
  54. return (
  55. <div key={index}>{ReactHtmlParser(response.content.rendered)}</div>
  56. )
  57. }
  58.  
  59. })
  60. }
  61.  
  62. return (
  63. <div>
  64. <div>
  65. <section
  66. className="hero is-small is-bold has-background-black has-text-centered"
  67. style={{ paddingTop: "4rem", paddingBottom: "4rem" }}
  68. >
  69. <div className="hero-body">
  70. <div className="container">
  71. <h1 className="title is-1" style={{ color: "#FFD581" }}>
  72. {title}
  73. </h1>
  74. </div>
  75. </div>
  76. </section>
  77. <div className="section" style={{ margin: "-1.5rem 0 0 0" }}>
  78. <div className="columns">
  79. <div className="column">
  80. <div
  81. className="card has-background-dark has-text-white"
  82. style={{ height: "100%" }}
  83. >
  84. <div className="card-content">
  85. <div className="content blackpages">{content}</div>
  86. </div>
  87. </div>
  88. </div>
  89. </div>
  90. </div>
  91. </div>
  92. </div>
  93. )
  94. }
  95. }
  96.  
  97. export default Page
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement