Split out into separate classes
This commit is contained in:
@ -1,9 +0,0 @@
|
||||
import * as React from 'react';
|
||||
import * as ReactDOM from 'react-dom';
|
||||
import App from './App';
|
||||
|
||||
it('renders without crashing', () => {
|
||||
const div = document.createElement('div');
|
||||
ReactDOM.render(<App />, div);
|
||||
ReactDOM.unmountComponentAtNode(div);
|
||||
});
|
168
src/App.tsx
168
src/App.tsx
@ -1,147 +1,37 @@
|
||||
import React, { useState } from "react";
|
||||
import { DragDropContext, Draggable, Droppable } from "react-beautiful-dnd";
|
||||
import uuid from "uuid/v4";
|
||||
// import * as vscode from 'vscode';
|
||||
import Board from './Board';
|
||||
import Header from './Header';
|
||||
import React, { useEffect, useState } from "react";
|
||||
|
||||
const itemsFromBackend = [
|
||||
{ id: uuid(), content: "First task" },
|
||||
{ id: uuid(), content: "Second task" },
|
||||
{ id: uuid(), content: "Third task" },
|
||||
{ id: uuid(), content: "Fourth task" },
|
||||
{ id: uuid(), content: "Fifth task" }
|
||||
];
|
||||
function App(props) {
|
||||
// const [cwd, setCwd] = useState('initialcwd');
|
||||
// const [index, setIndex] = useState({});
|
||||
// const [tasks, setTasks] = useState([]);
|
||||
|
||||
const columnsFromBackend = {
|
||||
[uuid()]: {
|
||||
name: "Requested",
|
||||
items: itemsFromBackend
|
||||
},
|
||||
[uuid()]: {
|
||||
name: "To do",
|
||||
items: []
|
||||
},
|
||||
[uuid()]: {
|
||||
name: "In Progress",
|
||||
items: []
|
||||
},
|
||||
[uuid()]: {
|
||||
name: "Done",
|
||||
items: []
|
||||
}
|
||||
};
|
||||
// useEffect(() => {
|
||||
// // process.chdir(vscode!.workspace.workspaceFolders[0].uri.fsPath);
|
||||
// import('@basementuniverse/kanbn/src/main').then(kanbn => {
|
||||
// vscode.postMessage({
|
||||
// command: 'error',
|
||||
// text: 'hello!'
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
// console.log(vscode!.workspace.workspaceFolders[0].uri.fsPath);
|
||||
|
||||
const onDragEnd = (result, columns, setColumns) => {
|
||||
if (!result.destination) return;
|
||||
const { source, destination } = result;
|
||||
// window.addEventListener('message', event => {
|
||||
// const message = event.data; // The JSON data our extension sent
|
||||
// switch (message.command) {
|
||||
// case 'test':
|
||||
// setCwd(message.cwd);
|
||||
// break;
|
||||
// }
|
||||
// });
|
||||
|
||||
if (source.droppableId !== destination.droppableId) {
|
||||
const sourceColumn = columns[source.droppableId];
|
||||
const destColumn = columns[destination.droppableId];
|
||||
const sourceItems = [...sourceColumn.items];
|
||||
const destItems = [...destColumn.items];
|
||||
const [removed] = sourceItems.splice(source.index, 1);
|
||||
destItems.splice(destination.index, 0, removed);
|
||||
setColumns({
|
||||
...columns,
|
||||
[source.droppableId]: {
|
||||
...sourceColumn,
|
||||
items: sourceItems
|
||||
},
|
||||
[destination.droppableId]: {
|
||||
...destColumn,
|
||||
items: destItems
|
||||
}
|
||||
});
|
||||
} else {
|
||||
const column = columns[source.droppableId];
|
||||
const copiedItems = [...column.items];
|
||||
const [removed] = copiedItems.splice(source.index, 1);
|
||||
copiedItems.splice(destination.index, 0, removed);
|
||||
setColumns({
|
||||
...columns,
|
||||
[source.droppableId]: {
|
||||
...column,
|
||||
items: copiedItems
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
function App() {
|
||||
const [columns, setColumns] = useState(columnsFromBackend);
|
||||
return (
|
||||
<div style={{ display: "flex", justifyContent: "center", height: "100%" }}>
|
||||
<DragDropContext
|
||||
onDragEnd={result => onDragEnd(result, columns, setColumns)}
|
||||
>
|
||||
{Object.entries(columns).map(([columnId, column], index) => {
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
alignItems: "center"
|
||||
}}
|
||||
key={columnId}
|
||||
>
|
||||
<h2>{column.name}</h2>
|
||||
<div style={{ margin: 8 }}>
|
||||
<Droppable droppableId={columnId} key={columnId}>
|
||||
{(provided, snapshot) => {
|
||||
return (
|
||||
<div
|
||||
{...provided.droppableProps}
|
||||
ref={provided.innerRef}
|
||||
style={{
|
||||
background: snapshot.isDraggingOver
|
||||
? "lightblue"
|
||||
: "lightgrey",
|
||||
padding: 4,
|
||||
width: 250,
|
||||
minHeight: 500
|
||||
}}
|
||||
>
|
||||
{column.items.map((item, index) => {
|
||||
return (
|
||||
<Draggable
|
||||
key={item.id}
|
||||
draggableId={item.id}
|
||||
index={index}
|
||||
>
|
||||
{(provided, snapshot) => {
|
||||
return (
|
||||
<div
|
||||
ref={provided.innerRef}
|
||||
{...provided.draggableProps}
|
||||
{...provided.dragHandleProps}
|
||||
style={{
|
||||
userSelect: "none",
|
||||
padding: 16,
|
||||
margin: "0 0 8px 0",
|
||||
minHeight: "50px",
|
||||
backgroundColor: snapshot.isDragging
|
||||
? "#263B4A"
|
||||
: "#456C86",
|
||||
color: "white",
|
||||
...provided.draggableProps.style
|
||||
}}
|
||||
>
|
||||
{item.content}
|
||||
</div>
|
||||
);
|
||||
}}
|
||||
</Draggable>
|
||||
);
|
||||
})}
|
||||
{provided.placeholder}
|
||||
</div>
|
||||
);
|
||||
}}
|
||||
</Droppable>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</DragDropContext>
|
||||
<div>
|
||||
<Header />
|
||||
<Board />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
149
src/Board.tsx
Normal file
149
src/Board.tsx
Normal file
@ -0,0 +1,149 @@
|
||||
import React, { useState } from "react";
|
||||
import { DragDropContext, Draggable, Droppable } from "react-beautiful-dnd";
|
||||
import uuid from "uuid/v4";
|
||||
|
||||
const itemsFromBackend = [
|
||||
{ id: uuid(), content: "First task" },
|
||||
{ id: uuid(), content: "Second task" },
|
||||
{ id: uuid(), content: "Third task" },
|
||||
{ id: uuid(), content: "Fourth task" },
|
||||
{ id: uuid(), content: "Fifth task" }
|
||||
];
|
||||
|
||||
const columnsFromBackend = {
|
||||
[uuid()]: {
|
||||
name: "Requested",
|
||||
items: itemsFromBackend
|
||||
},
|
||||
[uuid()]: {
|
||||
name: "To do",
|
||||
items: []
|
||||
},
|
||||
[uuid()]: {
|
||||
name: "In Progress",
|
||||
items: []
|
||||
},
|
||||
[uuid()]: {
|
||||
name: "Done",
|
||||
items: []
|
||||
}
|
||||
};
|
||||
|
||||
const onDragEnd = (result, columns, setColumns) => {
|
||||
if (!result.destination) return;
|
||||
const { source, destination } = result;
|
||||
|
||||
if (source.droppableId !== destination.droppableId) {
|
||||
const sourceColumn = columns[source.droppableId];
|
||||
const destColumn = columns[destination.droppableId];
|
||||
const sourceItems = [...sourceColumn.items];
|
||||
const destItems = [...destColumn.items];
|
||||
const [removed] = sourceItems.splice(source.index, 1);
|
||||
destItems.splice(destination.index, 0, removed);
|
||||
setColumns({
|
||||
...columns,
|
||||
[source.droppableId]: {
|
||||
...sourceColumn,
|
||||
items: sourceItems
|
||||
},
|
||||
[destination.droppableId]: {
|
||||
...destColumn,
|
||||
items: destItems
|
||||
}
|
||||
});
|
||||
} else {
|
||||
const column = columns[source.droppableId];
|
||||
const copiedItems = [...column.items];
|
||||
const [removed] = copiedItems.splice(source.index, 1);
|
||||
copiedItems.splice(destination.index, 0, removed);
|
||||
setColumns({
|
||||
...columns,
|
||||
[source.droppableId]: {
|
||||
...column,
|
||||
items: copiedItems
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
function Board() {
|
||||
const [columns, setColumns] = useState(columnsFromBackend);
|
||||
return (
|
||||
<div style={{ display: "flex", justifyContent: "center", height: "100%" }}>
|
||||
<DragDropContext
|
||||
onDragEnd={result => onDragEnd(result, columns, setColumns)}
|
||||
>
|
||||
{Object.entries(columns).map(([columnId, column], index) => {
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
alignItems: "center"
|
||||
}}
|
||||
key={columnId}
|
||||
>
|
||||
<h2>{column.name}</h2>
|
||||
<div style={{ margin: 8 }}>
|
||||
<Droppable droppableId={columnId} key={columnId}>
|
||||
{(provided, snapshot) => {
|
||||
return (
|
||||
<div
|
||||
{...provided.droppableProps}
|
||||
ref={provided.innerRef}
|
||||
style={{
|
||||
background: snapshot.isDraggingOver
|
||||
? "lightblue"
|
||||
: "lightgrey",
|
||||
padding: 4,
|
||||
width: 250,
|
||||
minHeight: 500
|
||||
}}
|
||||
>
|
||||
{column.items.map((item, index) => {
|
||||
return (
|
||||
<Draggable
|
||||
key={item.id}
|
||||
draggableId={item.id}
|
||||
index={index}
|
||||
>
|
||||
{(provided, snapshot) => {
|
||||
return (
|
||||
<div
|
||||
ref={provided.innerRef}
|
||||
{...provided.draggableProps}
|
||||
{...provided.dragHandleProps}
|
||||
style={{
|
||||
userSelect: "none",
|
||||
padding: 16,
|
||||
margin: "0 0 8px 0",
|
||||
minHeight: "50px",
|
||||
backgroundColor: snapshot.isDragging
|
||||
? "#263B4A"
|
||||
: "#456C86",
|
||||
color: "white",
|
||||
...provided.draggableProps.style
|
||||
}}
|
||||
>
|
||||
{item.content}
|
||||
</div>
|
||||
);
|
||||
}}
|
||||
</Draggable>
|
||||
);
|
||||
})}
|
||||
{provided.placeholder}
|
||||
</div>
|
||||
);
|
||||
}}
|
||||
</Droppable>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</DragDropContext>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default Board;
|
11
src/Header.tsx
Normal file
11
src/Header.tsx
Normal file
@ -0,0 +1,11 @@
|
||||
import React, { useState } from "react";
|
||||
|
||||
function Header() {
|
||||
return (
|
||||
<div>
|
||||
Header
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default Header;
|
Reference in New Issue
Block a user