Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.69 KB | None | 0 0
  1. import React, { Component } from "react";
  2. import { View, Text, TouchableOpacity } from "react-native";
  3. import styled from "styled-components";
  4. import Search from "react-native-search-box";
  5. import Accordion from "react-native-collapsible/Accordion";
  6.  
  7. import IconButton from "../../_elements/IconButton";
  8. import SingleJob from "../../_elements/SingleJob";
  9. import AccordionHeader from "../components/AccordionHeader";
  10.  
  11. const JOBS = [
  12. {
  13. id: 1,
  14. plannedDate: "21/04/2018" /* here timestimp will be shown */,
  15. description: "Inspection-D20",
  16. plannedDuration: "80min",
  17. urgent: true,
  18. state: "new",
  19. priority: ""
  20. },
  21. {
  22. id: 2,
  23. plannedDate: "09/11/2017" /* here timestimp will be shown */,
  24. description: "Inspection-C24",
  25. plannedDuration: "120min",
  26. urgent: true,
  27. state: "finished",
  28. priority: "PrioA"
  29. },
  30. {
  31. id: 3,
  32. plannedDate: "09/03/2018" /* here timestimp will be shown */,
  33. description: "Inspection-C26",
  34. plannedDuration: "160min",
  35. urgent: false,
  36. state: "unfinished",
  37. priority: "PrioB"
  38. },
  39. {
  40. id: 4,
  41. plannedDate: "09/01/2018" /* here timestimp will be shown */,
  42. description: "Inspection-C28",
  43. plannedDuration: "140min",
  44. urgent: false,
  45. state: "unfinished",
  46. priority: "PrioC"
  47. },
  48. {
  49. id: 5,
  50. plannedDate: "09/11/2017" /* here timestimp will be shown */,
  51. description: "Inspection-C241",
  52. plannedDuration: "120min",
  53. urgent: true,
  54. state: "finished",
  55. priority: "PrioA"
  56. },
  57. {
  58. id: 6,
  59. plannedDate: "09/11/2017" /* here timestimp will be shown */,
  60. description: "Inspection-C242",
  61. plannedDuration: "120min",
  62. urgent: true,
  63. state: "finished",
  64. priority: "PrioA"
  65. }
  66. ];
  67.  
  68. function groupJobsByPriority(originalJobs) {
  69. // find all unique priorities
  70. const uniquePrioritiesMap = {};
  71. originalJobs.forEach(job => {
  72. if (!uniquePrioritiesMap[job.priority]) {
  73. uniquePrioritiesMap[job.priority] = true;
  74. }
  75. });
  76. const uniquePriorities = Object.keys(uniquePrioritiesMap).filter(
  77. p => p !== "undefined"
  78. );
  79.  
  80. // generate grouped array
  81. const groupedByPrioJobs = uniquePriorities.map(priority => {
  82. return {
  83. priority,
  84. jobs: originalJobs.filter(job => job.priority === priority)
  85. };
  86. });
  87. return groupedByPrioJobs;
  88. }
  89.  
  90. const Container = styled.View`
  91. flex: 1;
  92. background: white;
  93. `;
  94.  
  95. const Row = styled.View`
  96. flex: 1;
  97. `;
  98.  
  99. const ContainerList = styled.View`
  100. flex: 6;
  101. `;
  102.  
  103. const ButtonContainer = styled.View`
  104. flex-direction: row;
  105. flex: 1;
  106. align-items: center;
  107. justify-content: center;
  108. `;
  109.  
  110. const WrapperElement = styled.View`
  111. flex: 1;
  112. `;
  113.  
  114. export default class JobListScreen extends Component {
  115. constructor(props) {
  116. super(props);
  117. this.state = {
  118. jobSections: []
  119. };
  120. }
  121.  
  122. componentDidMount() {
  123. this.setState({ jobSections: groupJobsByPriority(JOBS) });
  124. }
  125.  
  126. renderHeader(content, index, isActive) {
  127. return (
  128. <AccordionHeader
  129. title={content.priority === "" ? "Keine" : content.priority}
  130. name=""
  131. source={
  132. isActive
  133. ? require("../resources/arrowdown.png")
  134. : require("../resources/inversedarrow.png")
  135. }
  136. />
  137. );
  138. }
  139.  
  140. renderContent(section) {
  141. return section.jobs.map((job, i) => (
  142. <SingleJob
  143. key={i}
  144. source={require("../resources/urgent.png")}
  145. title={job.description}
  146. date={job.plannedDate}
  147. duration={job.plannedDuration}
  148. recording
  149. />
  150. ));
  151. }
  152.  
  153. render() {
  154. return (
  155. <Container>
  156. <Row>
  157. <Search
  158. ref="search_box"
  159. backgroundColor="white"
  160. titleCancelColor="black"
  161. inputHeight={40}
  162. />
  163. </Row>
  164. <Row>
  165. <ButtonContainer>
  166. <IconButton
  167. text="past due"
  168. source={require("../resources/pastdue.png")}
  169. orientation="row"
  170. />
  171. <IconButton
  172. text="open"
  173. source={require("../resources/open.png")}
  174. orientation="row"
  175. />
  176. <IconButton
  177. text="urgent"
  178. source={require("../resources/urgent.png")}
  179. orientation="row"
  180. />
  181. </ButtonContainer>
  182. </Row>
  183. <ContainerList>
  184. <Accordion
  185. sections={this.state.jobSections}
  186. renderHeader={this.renderHeader}
  187. renderContent={this.renderContent}
  188. touchableComponent={TouchableOpacity}
  189. />
  190. </ContainerList>
  191. </Container>
  192. );
  193. }
  194. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement