Last active
November 16, 2019 22:07
-
-
Save nickredmark/fc398fdcefb728cbae654a5231bc56ce to your computer and use it in GitHub Desktop.
Board.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const Board = ({ | |
id, | |
getId, | |
data, | |
onCreateLane, | |
onCreateCard | |
onSetBoardTitle, | |
onSetCardTitle, | |
onSetLaneTitle, | |
}) => { | |
const [editing, setEditing] = useState(false); | |
const [newBoardTitle, setNewBoardTitle] = useState(""); | |
const newLaneTitle = useRef(null); | |
const board = data[id]; | |
const lanes = getSet(data, id, "lanes"); | |
return ( | |
<div className="board"> | |
{editing ? ( | |
<form | |
onSubmit={e => { | |
e.preventDefault(); | |
onSetBoardTitle(newBoardTitle); | |
setEditing(false); | |
}} | |
> | |
<input | |
value={newBoardTitle} | |
onChange={e => setNewBoardTitle(e.target.value)} | |
placeholder="board title" | |
/> | |
</form> | |
) : ( | |
<h1 | |
onDoubleClick={e => { | |
setNewBoardTitle(board.title); | |
setEditing(true); | |
}} | |
className="board-title" | |
> | |
{(board && board.title) || id} | |
</h1> | |
)} | |
<div className="board-content"> | |
<div | |
className="lanes" | |
> | |
{lanes.map((lane, i) => { | |
const id = getId(lane); | |
return ( | |
<Lane | |
key={id} | |
getId={getId} | |
index={i} | |
id={id} | |
data={data} | |
sort={sort} | |
onSetLaneTitle={onSetLaneTitle} | |
onSetCardTitle={onSetCardTitle} | |
onCreateCard={onCreateCard} | |
/> | |
); | |
})} | |
{provided.placeholder} | |
</div> | |
<div className="new-lane"> | |
<form | |
onSubmit={e => { | |
e.preventDefault(); | |
onCreateLane(newLaneTitle.current.value); | |
newLaneTitle.current.value = ""; | |
}} | |
> | |
<input ref={newLaneTitle} placeholder="new lane" /> | |
</form> | |
</div> | |
</div> | |
</div> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment