Advertisement
dfghgfhplkjbv

src/components/Home/Home.js

Feb 21st, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.86 KB | None | 0 0
  1. import React, { Component } from 'react'
  2. import { StaticQuery, graphql } from 'gatsby'
  3. import classNames from 'classnames'
  4. import { compareDesc } from 'date-fns'
  5. import Video from 'src/components/Video'
  6. import Audio from 'src/components/Audio'
  7. import Item from './Item'
  8. import ItemWithoutPreview from './ItemWithoutPreview'
  9. import styles from './Home.module.scss'
  10. import Ad from '../Ad'
  11. import OfflineContainer from 'src/components/OfflineContainer'
  12. import { isOnline, removeListeners } from 'src/utils'
  13.  
  14. class Home extends Component {
  15. state = {
  16. isOnline: true,
  17. }
  18.  
  19. componentDidMount() {
  20. isOnline(this)
  21. }
  22.  
  23. componentWillUnmount() {
  24. removeListeners()
  25. }
  26.  
  27. render() {
  28. const { className, interviews, channels, podcasts, news, articlesNumber, locale } = this.props
  29. const articles = [...interviews, ...news].sort((articlePrev, articleNext) =>
  30. compareDesc(articlePrev.publishDate, articleNext.publishDate),
  31. )
  32. const slicedArticles = articles.slice(0, articlesNumber)
  33. return (
  34. <div>
  35. <section className={classNames(className, styles.root)}>
  36. <div id="interviews" className={styles.interviews}>
  37. <div className={styles.interviewsWrapper}>
  38. {slicedArticles
  39. .slice(0, 2)
  40. .map((item) => (
  41. <ItemWithoutPreview layoutFlag={true} key={item.node.slug} {...item} locale={locale} isFullWidth />
  42. ))}
  43. </div>
  44. <div className={styles.calculator}>
  45. <Ad locale={locale} />
  46. </div>
  47. </div>
  48.  
  49. {channels &&
  50. locale !== 'en' && (
  51. <div id="video" className={styles.videoWrapper}>
  52. {!this.state.isOnline && <OfflineContainer locale={locale} />}
  53. <Video channels={channels} locale={locale} />
  54. </div>
  55. )}
  56.  
  57. {podcasts &&
  58. locale !== 'en' && (
  59. <div id="podcasts" className={styles.podcastsWrapper}>
  60. {!this.state.isOnline && <OfflineContainer locale={locale} />}
  61.  
  62. <Audio podcasts={podcasts} onChangeData={this.props.onChangeData} locale={locale} />
  63. </div>
  64. )}
  65.  
  66. <div className={styles.articles}>
  67. {slicedArticles.slice(2, 7).map((item, index) => {
  68. const lastItem = slicedArticles.slice(9).length
  69. return index === lastItem ? (
  70. <Item locale={locale} key={item.node.slug} {...item} />
  71. ) : (
  72. <ItemWithoutPreview key={item.node.slug} {...item} locale={locale} />
  73. )
  74. })}
  75. </div>
  76. </section>
  77. </div>
  78. )
  79. }
  80. }
  81.  
  82. Home.defaultProps = {
  83. articlesNumber: 6,
  84. }
  85.  
  86. export default (props) => (
  87. <StaticQuery
  88. query={graphql`
  89. query {
  90. configuration: markdownRemark(frontmatter: { templateKey: { eq: "Configuration" } }) {
  91. frontmatter {
  92. articlesNumber
  93. }
  94. }
  95. channels: allDatoCmsVideo {
  96. edges {
  97. node {
  98. videos {
  99. title
  100. videoId
  101. description
  102. duration
  103. publishDate
  104. }
  105. }
  106. }
  107. }
  108. podcasts: allDatoCmsPodcast {
  109. edges {
  110. node {
  111. title
  112. duration
  113. publishDate
  114. guest
  115. cover {
  116. url
  117. }
  118. podcast {
  119. url
  120. }
  121. slug
  122. }
  123. }
  124. }
  125. interviews: allDatoCmsInterview {
  126. edges {
  127. node {
  128. title
  129. description
  130. author
  131. photographer
  132. publishDate
  133. podcast {
  134. podcastTitle
  135. podcastGuest
  136. podcastCover {
  137. url
  138. }
  139. duration
  140. podcast {
  141. url
  142. }
  143. }
  144. image {
  145. url
  146. fluid(maxWidth: 1240, imgixParams: { fm: "jpg", auto: "compress" }) {
  147. ...GatsbyDatoCmsFluid
  148. }
  149. }
  150. summary {
  151. title
  152. description
  153. }
  154. bodyNode {
  155. childMarkdownRemark {
  156. html
  157. }
  158. }
  159. slug
  160. }
  161. }
  162. }
  163. }
  164. `}
  165. render={({ interviews: { edges }, channels, podcasts, configuration: { articlesNumber } }) => {
  166. return (
  167. <Home interviews={edges} channels={channels} articlesNumber={articlesNumber} podcasts={podcasts} {...props} />
  168. )
  169. }}
  170. />
  171. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement