Advertisement
Guest User

src/pages/search.js

a guest
Jul 23rd, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.64 KB | None | 0 0
  1. import React, { useContext } from "react"
  2. import {
  3. Tv,
  4. AlignJustify,
  5. BookOpen,
  6. Clipboard,
  7. Play,
  8. User,
  9. } from "react-feather"
  10. import { Box, Flex, Heading, Text } from "rebass"
  11. import { Link } from "gatsby"
  12. import styled from "styled-components"
  13. import { SearchContext } from "src/features/SearchContext"
  14. import { Helmet } from "src/features/Helmet"
  15. import { Layout } from "src/ui/Layout"
  16. import { Container } from "src/ui/Container"
  17. import { Search } from "src/ui/Search"
  18.  
  19. const SearchPage = () => {
  20. const { searchResults } = useContext(SearchContext)
  21. const isDataPresent = Boolean(searchResults && searchResults.length > 0)
  22. return (
  23. <>
  24. <Helmet title={"Search page"}></Helmet>
  25. <Layout hideSearch={true}>
  26. <Box backgroundColor="black">
  27. <Hero
  28. py={["6", "6", "10", "10"]}
  29. px={[4, 4, 0, 0]}
  30. alignItems={"flex-start"}
  31. flexDirection={"column"}
  32. >
  33. <StyledHeading fontSize={[3, 4, 6]} as="h1" color="white">
  34. {title}
  35. </StyledHeading>
  36. <StyledSearch my={"2"} />
  37. </Hero>
  38. </Box>
  39. {isDataPresent && <Results searchResults={searchResults} />}
  40. {!isDataPresent && <NothingFound searchResults={searchResults} />}
  41. </Layout>
  42. </>
  43. )
  44. }
  45.  
  46. const Results = ({ searchResults }) => {
  47. return (
  48. <Container>
  49. <Flex py={"5"} alignItems={"center"} justifyContent={"space-between"}>
  50. <Heading as="h2" fontSize={[5, 5, 5, 6]}>
  51. Results:
  52. </Heading>
  53. <Count py={"1"} px={"3"} color="white" fontSize={"4"}>
  54. {searchResults.length}
  55. </Count>
  56. </Flex>
  57. <Box pb={"8"}>
  58. {searchResults.map(({ url, title, apiKey }) => (
  59. <Flex key={url} id={url} my={"7"}>
  60. <IconWrap
  61. flexDirection={"column"}
  62. alignItems={"center"}
  63. justifyContent={"center"}
  64. mr={"3"}
  65. ml={"-5px"}
  66. >
  67. {checkIcon(apiKey)}
  68. </IconWrap>
  69. <Flex flexDirection={"column"}>
  70. <StyledLink to={url}>{title}</StyledLink>
  71. <Text color="gray" fontSize={"2"}>
  72. {url}
  73. </Text>
  74. </Flex>
  75. </Flex>
  76. ))}
  77. </Box>
  78. <Flex alignItems={"flex-start"} flexDirection={"column"}></Flex>
  79. </Container>
  80. )
  81. }
  82.  
  83. const NothingFound = () => {
  84. return <Container py={"5"}>Nothing found</Container>
  85. }
  86.  
  87.  
  88. const Hero = styled(Flex)`
  89. margin: 0 auto;
  90. max-width: 740px;
  91. `
  92. const Icon = styled(Flex)`
  93. border: 2px solid red;
  94. border-radius: 3px;
  95. `
  96. const IconWrap = styled(Flex)`
  97. min-width: 60px;
  98. `
  99. const Description = styled(Text)`
  100. font-weight: 600;
  101. text-transform: uppercase;
  102. `
  103. const StyledSearch = styled(Search)`
  104. margin: 10px 0;
  105. min-width: 100%;
  106. input {
  107. height: 62px;
  108.  
  109. @media (max-width: ${({ theme }) => theme.breakpoints.m}) {
  110. height: 48px;
  111. }
  112. }
  113.  
  114. button {
  115. height: 100%;
  116. width: 93px;
  117. }
  118.  
  119. svg {
  120. height: 30px;
  121. width: 30px;
  122. }
  123. `
  124. const StyledHeading = styled(Heading)`
  125. line-height: 160%;
  126. font-weight: 600;
  127. `
  128. const StyledLink = styled(Link)`
  129. text-decoration: underline;
  130. font-weight: 500;
  131. font-size: 24px;
  132. margin-bottom: 8px;
  133. `
  134. const Count = styled(Box)`
  135. background: #000;
  136. border-radius: 2px;
  137. font-weight: 500;
  138. `
  139.  
  140. const title =
  141. "Harnessing the power of media to spread Kedushah in the world, with geshmake!"
  142.  
  143. const checkIcon = apiKey => {
  144. const icons = {
  145. artist: <User size={"16"} color="red" />,
  146. blog: <BookOpen size={"16"} color="red" />,
  147. channel: <Tv size={"16"} color="red" />,
  148. category: <Clipboard size={"16"} color="red" />,
  149. default: <AlignJustify size={"16"} color="red" />,
  150. playlist: <Play size={"16"} color="red" />,
  151. video: <Play size={"16"} color="red" />,
  152. }
  153. switch (true) {
  154. case apiKey.includes("Artist"):
  155. return (
  156. <>
  157. <Icon py={"1"} px={"2"} mb={"2"}>
  158. {icons.artist}
  159. </Icon>
  160. <Description fontSize={"1"}>{apiKey}</Description>
  161. </>
  162. )
  163. case apiKey.includes("Blog"):
  164. return (
  165. <>
  166. <Icon py={"1"} px={"2"} mb={"2"}>
  167. {icons.blog}
  168. </Icon>
  169. <Description fontSize={"1"}>{apiKey}</Description>
  170. </>
  171. )
  172. case apiKey.includes("Channel"):
  173. return (
  174. <>
  175. <Icon py={"1"} px={"2"} mb={"2"}>
  176. {icons.channel}
  177. </Icon>
  178. <Description fontSize={"1"}>{apiKey}</Description>
  179. </>
  180. )
  181. case apiKey.includes("Category"):
  182. return (
  183. <>
  184. <Icon py={"1"} px={"2"} mb={"2"}>
  185. {icons.category}
  186. </Icon>
  187. <Description fontSize={"1"}>{apiKey}</Description>
  188. </>
  189. )
  190. case apiKey.includes("Playlist"):
  191. return (
  192. <>
  193. <Icon py={"1"} px={"2"} mb={"2"}>
  194. {icons.playlist}
  195. </Icon>
  196. <Description fontSize={"1"}>{apiKey}</Description>
  197. </>
  198. )
  199. case apiKey.includes("Video"):
  200. return (
  201. <>
  202. <Icon py={"1"} px={"2"} mb={"2"}>
  203. {icons.video}
  204. </Icon>
  205. <Description fontSize={"1"}>{apiKey}</Description>
  206. </>
  207. )
  208. default:
  209. return (
  210. <>
  211. <Icon py={"1"} px={"2"} mb={"2"}>
  212. {icons.default}
  213. </Icon>
  214. <Description fontSize={"1"}>home</Description>
  215. </>
  216. )
  217. }
  218. }
  219.  
  220. export default SearchPage
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement