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.

123 lines
3.0KB

  1. import React from "react";
  2. import KBColumn from "./components/KBColumn";
  3. import "./App.css";
  4. import Header from "./components/Header";
  5. import Column from "./types/Column";
  6. import TaskPassback from "./types/TaskPassback";
  7. type State = {
  8. columns: Column[];
  9. columnIterator: number;
  10. taskIterator: number;
  11. };
  12. class App extends React.Component<{}, State> {
  13. constructor(props: any) {
  14. super(props);
  15. this.deleteColumn = this.deleteColumn.bind(this);
  16. this.addColumn = this.addColumn.bind(this);
  17. this.addTask = this.addTask.bind(this);
  18. this.state = {
  19. taskIterator: 1,
  20. columnIterator: 3,
  21. columns: [
  22. {
  23. id: 1,
  24. name: "Harry",
  25. color: "green",
  26. tasks: [],
  27. },
  28. {
  29. id: 2,
  30. name: "Potter",
  31. color: "red",
  32. tasks: [],
  33. },
  34. ],
  35. };
  36. }
  37. deleteColumn(id: number) {
  38. const { columns } = { ...this.state };
  39. const filteredColumns = columns.filter((column) => column.id !== id);
  40. this.setState({ columns: filteredColumns });
  41. console.log(this.state.columns);
  42. }
  43. addColumn() {
  44. let columnId = this.state.columnIterator;
  45. this.setState({ columnIterator: columnId + 1 });
  46. this.state.columns.push({
  47. id: columnId,
  48. name: "tempName" + columnId,
  49. color: "#404552",
  50. tasks: [],
  51. });
  52. }
  53. addTask(taskInstance?: TaskPassback) {
  54. console.log(taskInstance);
  55. if (this.state.columns.length > 0) {
  56. let taskId = this.state.taskIterator;
  57. let index = -2;
  58. if (taskInstance !== undefined) {
  59. this.setState({ taskIterator: taskId + 1 });
  60. console.log(this.state.columns)
  61. console.log(taskInstance.column)
  62. let indexObj = this.state.columns.find(
  63. (o) => o.id === taskInstance.column
  64. );
  65. if (indexObj) {
  66. index = this.state.columns.indexOf(indexObj);
  67. }
  68. else{
  69. alert("Clifford")
  70. }
  71. if (index >= 0) {
  72. this.state.columns[index].tasks.push({
  73. id: taskId,
  74. title: taskInstance.title,
  75. description: taskInstance.description,
  76. priority: taskInstance.priority,
  77. });
  78. }
  79. else{
  80. alert("Error finding that column. Check it hasn't already been deleted!" + index)
  81. }
  82. }
  83. else{
  84. alert("Oh god, oh heck")
  85. }
  86. } else {
  87. alert("You might want to consider adding a column!");
  88. }
  89. }
  90. render() {
  91. return (
  92. <div className="App">
  93. <Header
  94. addColumn={this.addColumn}
  95. addTask={this.addTask}
  96. columns={this.state.columns}
  97. />
  98. <div className="panel">
  99. {this.state.columns.map((column, index) => (
  100. <KBColumn
  101. color={column.color}
  102. title={column.name}
  103. key={index}
  104. onDelete={this.deleteColumn}
  105. id={column.id}
  106. tasks={column.tasks}
  107. />
  108. ))}
  109. </div>
  110. </div>
  111. );
  112. }
  113. }
  114. export default App;