Skip to content

Instantly share code, notes, and snippets.

@nickredmark
Last active November 16, 2019 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickredmark/a88e67d579516f2b5b53ada3146197aa to your computer and use it in GitHub Desktop.
Save nickredmark/a88e67d579516f2b5b53ada3146197aa to your computer and use it in GitHub Desktop.
Lane.ts
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