Last active
November 16, 2019 22:09
-
-
Save nickredmark/a88e67d579516f2b5b53ada3146197aa to your computer and use it in GitHub Desktop.
Lane.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
const Lane = ({ | |
getId, | |
id, | |
data, | |
sort, | |
index, | |
onSetCardTitle, | |
onSetLaneTitle, | |
onCreateCard | |
}) => { | |
const lane = data[id]; | |
const cards = sort(getSet(data, id, "cards")); | |
const [editing, setEditing] = useState(); | |
const [laneTitle, setLaneTitle] = useState(lane.title); | |
const newCardTitle = useRef(null); | |
return ( | |
<div className="lane"> | |
{editing ? ( | |
<form | |
onSubmit={e => { | |
e.preventDefault(); | |
onSetLaneTitle(laneTitle); | |
setEditing(false); | |
}} | |
> | |
<input | |
autoFocus | |
value={laneTitle} | |
onChange={e => setLaneTitle(e.target.value)} | |
placeholder="lane title" | |
/> | |
</form> | |
) : ( | |
<div | |
onDoubleClick={e => { | |
setLaneTitle(lane.title); | |
setEditing(true); | |
}} | |
className="lane-title" | |
> | |
{lane.title || "No title"} | |
</div> | |
)} | |
<div | |
className="cards" | |
> | |
{(cards || []).map((card, i) => { | |
const id = getId(card); | |
return ( | |
<Card | |
key={id} | |
id={id} | |
data={data} | |
getId={getId} | |
index={i} | |
onSetTitle={onSetCardTitle} | |
/> | |
); | |
})} | |
</div> | |
<div className="new-card"> | |
<form | |
onSubmit={e => { | |
e.preventDefault(); | |
onCreateCard(id, newCardTitle.current.value); | |
newCardTitle.current.value = ""; | |
}} | |
> | |
<input ref={newCardTitle} placeholder="new card" /> | |
</form> | |
</div> | |
</div> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment