Advertisement
dfghgfhplkjbv

src/components/AllJobs/AllJobs.js

Feb 22nd, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.19 KB | None | 0 0
  1. import React, { Component } from 'react'
  2. import styles from './AllJobs.module.scss'
  3. import posed, { PoseGroup } from 'react-pose'
  4. import shuffle from 'src/shuffle'
  5. import { Link } from 'gatsby'
  6. import { stripLeadingSlash } from 'history/PathUtils'
  7. import search from 'src/img/search.png'
  8.  
  9. const categories = [
  10. // { id: 1, title: 'Experience level' },
  11. // { id: 2, title: 'Experience level' },
  12. { id: 3, title: 'Experience level' },
  13. ]
  14.  
  15. const Item = posed.div({
  16. flip: {
  17. scale: 1,
  18. transition: {
  19. scale: {
  20. type: 'spring',
  21. velocity: 3,
  22. },
  23. default: {
  24. type: 'spring',
  25. },
  26. },
  27. // transition: { type: 'spring', stiffness: 100 },
  28. },
  29. })
  30.  
  31. class AllJobs extends Component {
  32. state = {
  33. searchQuery: '',
  34. preparedJobs: this.props.jobs.filter(({ node: slug }) => slug !== '_'),
  35. }
  36.  
  37. handleTagClick = (tagTitle) => {
  38. this.setState(
  39. {
  40. preparedJobs: this.props.jobs.filter(
  41. ({
  42. node: {
  43. tag: { title },
  44. },
  45. }) => title === tagTitle,
  46. ),
  47. },
  48. () =>
  49. this.setState({
  50. preparedJobs: shuffle(
  51. this.props.jobs.filter(
  52. ({
  53. node: {
  54. tag: { title },
  55. },
  56. }) => title === tagTitle,
  57. ),
  58. ),
  59. }),
  60. )
  61. }
  62.  
  63. handleExperienceChange = (event) => {
  64. const selectedExperience = event.target.value
  65. const filteredJobs = this.props.jobs.filter(
  66. ({
  67. node: {
  68. experienceLevel: { title: experience },
  69. },
  70. }) => selectedExperience === experience,
  71. )
  72. this.setState({ preparedJobs: filteredJobs })
  73. }
  74.  
  75. handleClearFiltersClick = () => {
  76. this.setState({ preparedJobs: this.props.jobs })
  77. }
  78.  
  79. handleSearchKeyWordChange = (event) => {
  80. this.setState({ searchQuery: event.target.value }, () => {
  81. if (this.state.searchQuery.length >= 3) {
  82. this.searchByKeyWord(this.state.searchQuery)
  83. }
  84. })
  85. }
  86.  
  87. handleSubmit = (event) => {
  88. event.preventDefault()
  89. this.searchByKeyWord(this.state.searchQuery)
  90. }
  91.  
  92. searchByKeyWord = (query) => {
  93. const result = this.state.preparedJobs.filter(({ node: { title } }) => {
  94. if (title.toLocaleLowerCase().indexOf(query.toLocaleLowerCase()) >= 0) {
  95. return true
  96. }
  97. return false
  98. })
  99. this.setState({ preparedJobs: result })
  100. }
  101.  
  102. render() {
  103. const { preparedJobs, searchQuery } = this.state
  104. const { jobTags, experienceLevels } = this.props
  105. return (
  106. <>
  107. <div className={styles.cover} />
  108. <div className={styles.root}>
  109. <div className={styles.inner}>
  110. <div className={styles.categoriesInnerContainer}>
  111. <h1>Select job categories: </h1>
  112. <div className={styles.tags}>
  113. {jobTags.map(({ node: { id, title } }) => (
  114. <button className={styles.tag} key={id} onClick={() => this.handleTagClick(title)}>
  115. {title}
  116. </button>
  117. ))}
  118. </div>
  119. <form className={styles.filtersForm} onSubmit={this.handleSubmit}>
  120. <select className={styles.level} onChange={this.handleExperienceChange}>
  121. {experienceLevels.map(({ node: { id, title } }) => (
  122. <option key={id} value={title}>
  123. {title}
  124. </option>
  125. ))}
  126. </select>
  127. {categories.map((item) => (
  128. <select className={styles.level} key={item.id}>
  129. <option value="0">{item.title}</option>
  130. </select>
  131. ))}
  132. <input
  133. className={styles.search}
  134. value={searchQuery}
  135. onChange={this.handleSearchKeyWordChange}
  136. placeholder={'Search..'}
  137. />
  138. <img src={search} alt="" className={styles.loopa} />
  139. <button className={styles.clear} onClick={this.handleClearFiltersClick}>
  140. Clear filters
  141. </button>
  142. </form>
  143. </div>
  144. </div>
  145. <div className={styles.jobsContainer}>
  146. <div className={styles.listContainer}>
  147. <div className={styles.total}>
  148. <h3>NYC TECH JOBS AND STARTUP JOBS</h3>
  149. <span>{preparedJobs.length}</span>
  150. </div>
  151. <div className={styles.listJobs}>
  152. <PoseGroup>
  153. {preparedJobs.map(
  154. ({
  155. node: {
  156. title,
  157. description,
  158. locationDescription,
  159. companyLogo: { url: companyLogo },
  160. slug,
  161. id,
  162. },
  163. }) => (
  164. <Item key={id}>
  165. <Link to={`/job/${slug}`} key={title} className={styles.jobLink}>
  166. <div className={styles.oneJob}>
  167. <div className={styles.companyLogo}>
  168. <img src={companyLogo} alt="" />
  169. </div>
  170. <div className={styles.jobInfo}>
  171. <div className={styles.title}>{title}</div>
  172. <div>
  173. <div className={styles.location}>{locationDescription}</div>
  174. <div className={styles.description}>
  175. {description.length >= 245 ? `${description.substring(0, 245)}...` : description}
  176. </div>
  177. </div>
  178. </div>
  179. </div>
  180. </Link>
  181. </Item>
  182. ),
  183. )}
  184. </PoseGroup>
  185. </div>
  186. </div>
  187. </div>
  188. </div>
  189. </>
  190. )
  191. }
  192. }
  193.  
  194. export default AllJobs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement