Me learning react like an absolute chungus
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

246 lines
6.2KB

  1. import React from "react";
  2. import Modal from "./Modal";
  3. import Column from "../types/Column";
  4. import TaskPassback from "../types/TaskPassback";
  5. import Priority from "../types/Priority";
  6. import ColumnPassback from "../types/ColumnPassback"
  7. type HeaderProps = {
  8. addColumn: (columnInstance?: ColumnPassback) => void;
  9. addTask: (taskInstance?: TaskPassback) => void;
  10. columns: Column[];
  11. };
  12. type State = {
  13. showTask: boolean;
  14. taskTitle: string;
  15. taskDesc: string;
  16. taskPrio: Priority;
  17. taskColumnNumber: number;
  18. showColumn: boolean;
  19. columnTitle: string;
  20. columnColor: string;
  21. };
  22. class Header extends React.Component<HeaderProps, State> {
  23. constructor(props: HeaderProps) {
  24. super(props);
  25. this.showTaskModal = this.showTaskModal.bind(this);
  26. this.hideModal = this.hideModal.bind(this);
  27. this.handleInputChange = this.handleInputChange.bind(this);
  28. this.handleSelectChange = this.handleSelectChange.bind(this);
  29. this.showColumnModal = this.showColumnModal.bind(true);
  30. this.hideColumnModal = this.hideColumnModal.bind(this);
  31. this.state = {
  32. showTask: false,
  33. showColumn: false,
  34. taskTitle: "",
  35. taskDesc: "",
  36. taskPrio: "normal",
  37. taskColumnNumber: -1,
  38. columnTitle: "",
  39. columnColor: "#00CC00",
  40. };
  41. }
  42. showTaskModal = () => {
  43. if (this.props.columns.length > 0){
  44. let {showTask, taskColumnNumber} = {...this.state}
  45. showTask = true;
  46. taskColumnNumber = this.props.columns[0].id
  47. this.setState({ showTask, taskColumnNumber});
  48. }
  49. else{
  50. alert("Add a column please!")
  51. }
  52. };
  53. showColumnModal = () => {
  54. let {showColumn} = {...this.state}
  55. showColumn = true;
  56. this.setState({showColumn})
  57. }
  58. hideModal = () => {
  59. this.setState({ showTask: false });
  60. };
  61. hideColumnModal = () => {
  62. this.setState({showColumn: false})
  63. }
  64. handleInputChange(event: React.ChangeEvent<HTMLInputElement>) {
  65. const target = event.target.id;
  66. if (target === "titleInput") {
  67. this.setState({ taskTitle: event.target.value });
  68. }
  69. if (target === "descInput") {
  70. this.setState({ taskDesc: event.target.value });
  71. }
  72. if (target === "columnTitle"){
  73. this.setState({columnTitle: event.target.value})
  74. }
  75. if (target === "columnColor"){
  76. this.setState({columnColor: event.target.value})
  77. }
  78. }
  79. handleSelectChange(event: React.ChangeEvent<HTMLSelectElement>) {
  80. if (event.target.id === "prioritySelect") {
  81. const selectedValue = event.target.value as Priority;
  82. this.setState({ taskPrio: selectedValue });
  83. }
  84. if (event.target.id === "columnSelect") {
  85. const selectedValue = parseInt(event.target.value);
  86. this.setState({ taskColumnNumber: selectedValue });
  87. }
  88. }
  89. render() {
  90. return (
  91. <div className="header" style={{ height: 60 }}>
  92. <h1
  93. style={{
  94. float: "left",
  95. margin: 0,
  96. padding: 0,
  97. verticalAlign: "center",
  98. }}
  99. >
  100. Kango Bango
  101. </h1>
  102. <Modal show={this.state.showTask} handleClose={this.hideModal}>
  103. <h3> Add Task</h3>
  104. <p>{this.props.columns[0] && this.props.columns[0].id}</p>
  105. <select
  106. value={this.state.taskColumnNumber}
  107. onChange={this.handleSelectChange}
  108. id="columnSelect"
  109. >
  110. {this.props.columns.map((column) => (
  111. <option value={column.id}>{column.name}</option>
  112. ))}
  113. ;
  114. </select>
  115. <label>
  116. {" "}
  117. Title:
  118. <input
  119. type="text"
  120. id="titleInput"
  121. value={this.state.taskTitle}
  122. onChange={this.handleInputChange}
  123. />
  124. </label>
  125. <br />
  126. <label>
  127. {" "}
  128. Description:
  129. <input
  130. type="textarea"
  131. id="descInput"
  132. value={this.state.taskDesc}
  133. onChange={this.handleInputChange}
  134. />
  135. </label>
  136. <br />
  137. <label>
  138. {" "}
  139. Priority:
  140. <select
  141. value={this.state.taskPrio}
  142. onChange={this.handleSelectChange}
  143. id="prioritySelect"
  144. >
  145. <option value="normal">Normal</option>
  146. <option value="important">Important</option>
  147. <option value="urgent">Urgent</option>
  148. </select>
  149. </label>
  150. <br />
  151. <button
  152. onClick={() =>
  153. this.props.addTask({
  154. title: this.state.taskTitle,
  155. description: this.state.taskDesc,
  156. priority: this.state.taskPrio,
  157. column: this.state.taskColumnNumber,
  158. }
  159. )
  160. }
  161. >
  162. Add Task
  163. </button>
  164. <button
  165. onClick={() => {
  166. this.hideModal();
  167. }}
  168. >
  169. Close
  170. </button>
  171. </Modal>
  172. <Modal show={this.state.showColumn} handleClose={this.hideModal}>
  173. <p> NP Love is a danger - Priscilla </p>
  174. <label>
  175. {" "}
  176. Title:
  177. <input
  178. type="text"
  179. id="columnTitle"
  180. value={this.state.columnTitle}
  181. onChange={this.handleInputChange}
  182. />
  183. </label>
  184. <br />
  185. <label>
  186. {" "}
  187. Title:
  188. <input
  189. type="text"
  190. id="columnColor"
  191. value={this.state.columnColor}
  192. onChange={this.handleInputChange}
  193. />
  194. </label>
  195. <br />
  196. <button onClick={() =>
  197. this.props.addColumn({
  198. title: this.state.columnTitle,
  199. color: this.state.columnColor,
  200. })
  201. }
  202. >NP Dancing - Vicky Vale</button>
  203. <button
  204. onClick={() => {
  205. this.hideColumnModal();
  206. }}
  207. >
  208. Close
  209. </button>
  210. </Modal>
  211. <button onClick={this.showTaskModal}> Add task </button>
  212. <button onClick={this.showColumnModal}> Add column </button>
  213. </div>
  214. );
  215. }
  216. }
  217. export default Header;