Added column adding

This commit is contained in:
James McKenzie 2021-04-27 15:24:45 +12:00
parent 98d2764b1a
commit 41d7cf2c6f
4 changed files with 138 additions and 57 deletions

View File

@ -3,11 +3,12 @@ import KBColumn from "./components/KBColumn";
import "./App.css"; import "./App.css";
import Header from "./components/Header"; import Header from "./components/Header";
import Task from "./types/Task"; import Task from "./types/Task";
import { isThisTypeNode } from "typescript";
type TaskPassback = { type TaskPassback = {
title: string; title: string;
description: string; description: string;
priority: "normal" | "important" | "urgent"; priority: "normal" | "important" | "urgent";
column: number;
}; };
type Column = { type Column = {
@ -59,6 +60,7 @@ class App extends React.Component<{}, State> {
addColumn() { addColumn() {
let columnId = this.state.columnIterator; let columnId = this.state.columnIterator;
this.setState({ columnIterator: columnId + 1 }); this.setState({ columnIterator: columnId + 1 });
this.state.columns.push({ this.state.columns.push({
id: columnId, id: columnId,
name: "tempName" + columnId, name: "tempName" + columnId,
@ -68,17 +70,27 @@ class App extends React.Component<{}, State> {
} }
addTask(taskInstance?: TaskPassback) { addTask(taskInstance?: TaskPassback) {
console.log(taskInstance);
if (this.state.columns.length > 0) { if (this.state.columns.length > 0) {
let taskId = this.state.taskIterator; let taskId = this.state.taskIterator;
let index = -1;
if (taskInstance !== undefined) { if (taskInstance !== undefined) {
this.setState({ taskIterator: taskId + 1 }); this.setState({ taskIterator: taskId + 1 });
this.state.columns[0].tasks.push({ let indexObj = this.state.columns.find(
id: taskId, (o) => o.id === taskInstance.column
title: taskInstance.title, );
description: taskInstance.description, if (indexObj) {
priority: taskInstance.priority, index = this.state.columns.indexOf(indexObj);
}); }
if (index >= 0) {
this.state.columns[index].tasks.push({
id: taskId,
title: taskInstance.title,
description: taskInstance.description,
priority: taskInstance.priority,
});
}
} }
} else { } else {
alert("You might want to consider adding a column!"); alert("You might want to consider adding a column!");
@ -88,7 +100,11 @@ class App extends React.Component<{}, State> {
render() { render() {
return ( return (
<div className="App"> <div className="App">
<Header addColumn={this.addColumn} addTask={this.addTask} /> <Header
addColumn={this.addColumn}
addTask={this.addTask}
columns={this.state.columns}
/>
<div className="panel"> <div className="panel">
{this.state.columns.map((column, index) => ( {this.state.columns.map((column, index) => (
<KBColumn <KBColumn

View File

@ -1,17 +1,26 @@
import React from "react"; import React from "react";
import Modal from "./Modal"; import Modal from "./Modal";
import { Component } from "react"; import { Component } from "react";
import Task from "../types/Task";
type TaskPassback = { type TaskPassback = {
title: string; title: string;
description: string; description: string;
priority: priority; priority: priority;
column: number;
};
type Column = {
id: number;
name: string;
color: string;
tasks: Task[];
}; };
type priority = "normal" | "important" | "urgent"; type priority = "normal" | "important" | "urgent";
type HeaderProps = { type HeaderProps = {
addColumn: () => void; addColumn: () => void;
addTask: (taskInstance?: TaskPassback) => void; addTask: (taskInstance?: TaskPassback) => void;
columns: Column[];
}; };
type State = { type State = {
@ -19,6 +28,7 @@ type State = {
titleVar: string; titleVar: string;
descVar: string; descVar: string;
prioVar: priority; prioVar: priority;
columnNumber: number;
}; };
class Header extends React.Component<HeaderProps, State> { class Header extends React.Component<HeaderProps, State> {
@ -34,6 +44,7 @@ class Header extends React.Component<HeaderProps, State> {
titleVar: "", titleVar: "",
descVar: "", descVar: "",
prioVar: "normal", prioVar: "normal",
columnNumber: props.columns[0].id,
}; };
} }
@ -48,18 +59,23 @@ class Header extends React.Component<HeaderProps, State> {
handleInputChange(event: React.ChangeEvent<HTMLInputElement>) { handleInputChange(event: React.ChangeEvent<HTMLInputElement>) {
const target = event.target.id; const target = event.target.id;
if (target === "titleInput") { if (target === "titleInput") {
let hold = this.state.titleVar;
this.setState({ titleVar: event.target.value }); this.setState({ titleVar: event.target.value });
} }
if (target === "descInput") { if (target === "descInput") {
let hold = this.state.descVar;
this.setState({ descVar: event.target.value }); this.setState({ descVar: event.target.value });
} }
} }
handleSelectChange(event: React.ChangeEvent<HTMLSelectElement>) { handleSelectChange(event: React.ChangeEvent<HTMLSelectElement>) {
const selectedValue = event.target.value as priority; if (event.target.id === "prioritySelect") {
this.setState({ prioVar: selectedValue }); const selectedValue = event.target.value as priority;
this.setState({ prioVar: selectedValue });
}
if (event.target.id === "columnSelect") {
const selectedValue = parseInt(event.target.value);
this.setState({ columnNumber: selectedValue });
}
} }
render() { render() {
@ -76,6 +92,18 @@ class Header extends React.Component<HeaderProps, State> {
Kango Bango Kango Bango
</h1> </h1>
<Modal show={this.state.show} handleClose={this.hideModal}> <Modal show={this.state.show} handleClose={this.hideModal}>
<h3> Add Task</h3>
<p>{this.props.columns.length}</p>
<select
value={this.state.columnNumber}
onChange={this.handleSelectChange}
id="columnSelect"
>
{this.props.columns.map((column) => (
<option value={column.id}>{column.name}</option>
))}
;
</select>
<label> <label>
{" "} {" "}
Title: Title:
@ -91,7 +119,7 @@ class Header extends React.Component<HeaderProps, State> {
{" "} {" "}
Description: Description:
<input <input
type="text" type="textarea"
id="descInput" id="descInput"
value={this.state.descVar} value={this.state.descVar}
onChange={this.handleInputChange} onChange={this.handleInputChange}
@ -105,24 +133,32 @@ class Header extends React.Component<HeaderProps, State> {
<select <select
value={this.state.prioVar} value={this.state.prioVar}
onChange={this.handleSelectChange} onChange={this.handleSelectChange}
id="prioritySelect"
> >
<option value="normal">Normal</option> <option value="normal">Normal</option>
<option value="important">Important</option> <option value="important">Important</option>
<option value="urgent">Urgent</option> <option value="urgent">Urgent</option>
</select> </select>
</label> </label>
<br />
<button <button
onClick={() => onClick={() =>
this.props.addTask({ this.props.addTask({
title: this.state.titleVar, title: this.state.titleVar,
description: this.state.descVar, description: this.state.descVar,
priority: this.state.prioVar, priority: this.state.prioVar,
column: this.state.columnNumber,
}) })
} }
> >
{" "} Add Task
AHHHHH{" "} </button>
<button
onClick={() => {
this.hideModal();
}}
>
Close
</button> </button>
</Modal> </Modal>
<button onClick={this.showModal}> Add task </button> <button onClick={this.showModal}> Add task </button>

View File

@ -1,24 +1,20 @@
import './modal.css'; import "./modal.css";
type ModalProps = { type ModalProps = {
handleClose: () => void, handleClose: () => void;
show: boolean, show: boolean;
children: any children: any;
};
} const Modal = (props: ModalProps) => {
const Modal = ( props: ModalProps ) => { const showHideClassName = props.show
const showHideClassName = props.show ? "modal display-block" : "modal display-none"; ? "modal display-block"
: "modal display-none";
return ( return (
<div className={showHideClassName}> <div className={showHideClassName}>
<section className="modal-main"> <section className="modal-main">{props.children}</section>
{props.children}
<button type="button" onClick={props.handleClose}>
Close
</button>
</section>
</div> </div>
); );
}; };
export default Modal; export default Modal;

View File

@ -1,26 +1,59 @@
.modal { .modal {
position: fixed; position: fixed;
top: 0; top: 0;
left: 0; left: 0;
width:100%; width: 100%;
height: 100%; height: 100%;
background: rgba(0, 0, 0, 0.6); color: black;
} background: rgba(0, 0, 0, 0.5);
}
.modal-main {
position:fixed; .modal-main label {
background: white; float: left;
width: 80%; margin-left: 20%;
height: auto; }
top:50%; .modal-main input {
left:50%; display: block;
transform: translate(-50%,-50%); float: right;
} }
select {
.display-block { background-color: red;
display: block; text-align: right;
} margin-left: auto;
}
.display-none { .modal-main button {
display: none; margin: 0 auto;
} float: left;
display: block;
transform: translate(-50%);
margin-left: 0;
background-color: dodgerblue;
}
.modal-main button:first-of-type {
clear: left;
display: block;
margin-left: 50%;
margin-right: 0;
text-align: center;
background-color: green;
}
.modal-main {
position: fixed;
text-align: center;
background: white;
width: 50%;
height: auto;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.display-block {
display: block;
}
.display-none {
display: none;
}