From 16de99f48b8180b752b190a0f428fc6b845de4e1 Mon Sep 17 00:00:00 2001 From: Ben Budnevich Date: Tue, 14 Jan 2020 01:36:59 -0500 Subject: [PATCH 1/2] feat(tile): make tiles editable --- src/components/Tile/Tile.stories.tsx | 2 +- src/components/Tile/Tile.tsx | 95 +++++++++++++++++++++++----- 2 files changed, 80 insertions(+), 17 deletions(-) diff --git a/src/components/Tile/Tile.stories.tsx b/src/components/Tile/Tile.stories.tsx index fb7b94b..c7e0d95 100644 --- a/src/components/Tile/Tile.stories.tsx +++ b/src/components/Tile/Tile.stories.tsx @@ -5,4 +5,4 @@ export default { title: 'Tile', }; -export const Default = () => ; +export const Default = () => ; diff --git a/src/components/Tile/Tile.tsx b/src/components/Tile/Tile.tsx index 44454d2..0be6d51 100644 --- a/src/components/Tile/Tile.tsx +++ b/src/components/Tile/Tile.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useState } from 'react'; import CardActions from '@material-ui/core/CardActions'; import Button from '@material-ui/core/Button'; import Grid from '@material-ui/core/Grid'; @@ -7,6 +7,9 @@ import Avatar from '@material-ui/core/Avatar'; import CardActionArea from '@material-ui/core/CardActionArea'; import Card from '@material-ui/core/Card'; import * as S from './Tile.styles'; +import Input from '@material-ui/core/Input'; +import { useTheme } from '@material-ui/core/styles'; +import FormControl from '@material-ui/core/FormControl'; interface Props { id: string; @@ -15,29 +18,89 @@ interface Props { } export default function Tile(props: Props) { + const theme = useTheme(); + const [isEditing, setIsEditing] = useState(false); + const [name, setName] = useState(props.name); + const [nextName, setNextName] = useState(name); + + const handleOnEditClick = () => { + setIsEditing(true); + }; + + const handleNameChange = (e: React.ChangeEvent) => { + setNextName(e.target.value); + }; + + const handleCancelClick = () => { + setName(name); + setNextName(name); + setIsEditing(false); + }; + + const handleConfirmClick = () => { + setName(nextName); + setIsEditing(false); + }; + const headerNode = ( {props.name ? props.name[0].toUpperCase() : ''}} - title={props.name} + title={ + isEditing ? ( + + + + ) : ( + name + ) + } /> ); return ( - - {props.link ? ( - - {headerNode} - - ) : ( - headerNode - )} - - - - + +
+ {props.link && !isEditing ? ( + + {headerNode} + + ) : ( + headerNode + )} + {isEditing ? ( + + + + + ) : ( + + + + + )} +
); From 4d57f8d64edd4abd95497c792e1a995e4e4e1723 Mon Sep 17 00:00:00 2001 From: Ben Budnevich Date: Tue, 14 Jan 2020 02:03:50 -0500 Subject: [PATCH 2/2] feat(boards): add ability to update a tile --- src/components/Boards/Boards.stories.tsx | 1 + src/components/Boards/Boards.tsx | 2 ++ src/components/Boards/BoardsContainer.tsx | 25 ++++++++++++++++++++--- src/components/Tile/Tile.tsx | 10 ++++++++- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/components/Boards/Boards.stories.tsx b/src/components/Boards/Boards.stories.tsx index c04cda2..6bb74a6 100644 --- a/src/components/Boards/Boards.stories.tsx +++ b/src/components/Boards/Boards.stories.tsx @@ -27,5 +27,6 @@ export const Default = () => ( }, ]} onAddBoard={noop} + onUpdateBoard={noop} /> ); diff --git a/src/components/Boards/Boards.tsx b/src/components/Boards/Boards.tsx index 0f6ce70..3df0b98 100644 --- a/src/components/Boards/Boards.tsx +++ b/src/components/Boards/Boards.tsx @@ -15,6 +15,7 @@ interface Props { name: string; }[]; onAddBoard: () => void; + onUpdateBoard: (args: { id: string; value: string }) => void; } export default function(props: Props) { @@ -37,6 +38,7 @@ export default function(props: Props) { id={board.id} name={board.name} link={`boards/${board.id}`} + onSubmit={props.onUpdateBoard} /> ))} diff --git a/src/components/Boards/BoardsContainer.tsx b/src/components/Boards/BoardsContainer.tsx index 036e20e..c38b62d 100644 --- a/src/components/Boards/BoardsContainer.tsx +++ b/src/components/Boards/BoardsContainer.tsx @@ -1,15 +1,18 @@ import React from 'react'; +import { useHistory } from 'react-router-dom'; + import Boards from './Boards'; import useGroups from '../../lib/hooks/useGroups'; import useUpdateGroups from '../../lib/hooks/useUpdateGroups'; import { GroupType } from '../../lib/types'; export default function BoardsContainer() { + const history = useHistory(); const { data, loading, error } = useGroups(); const updateBoard = useUpdateGroups(); - function onAddBoard() { - updateBoard({ + async function onAddBoard() { + const result = await updateBoard({ type: GroupType.Board, name: `Board - ${new Date().toLocaleDateString('en-US', { year: 'numeric', @@ -19,6 +22,16 @@ export default function BoardsContainer() { minute: 'numeric', })}`, }); + + history.push(`boards/${result.id}`); + } + + function onUpdateBoard({ id, value }: { id: string; value: string }) { + updateBoard({ + id, + type: GroupType.Board, + name: value, + }); } if (loading) { @@ -29,5 +42,11 @@ export default function BoardsContainer() { return
Error Loading Boards
; } - return ; + return ( + + ); } diff --git a/src/components/Tile/Tile.tsx b/src/components/Tile/Tile.tsx index 0be6d51..2875b3a 100644 --- a/src/components/Tile/Tile.tsx +++ b/src/components/Tile/Tile.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import CardActions from '@material-ui/core/CardActions'; import Button from '@material-ui/core/Button'; import Grid from '@material-ui/core/Grid'; @@ -15,6 +15,7 @@ interface Props { id: string; name: string; link?: string; + onSubmit?: (args: { id: string; value: string }) => void; } export default function Tile(props: Props) { @@ -23,6 +24,10 @@ export default function Tile(props: Props) { const [name, setName] = useState(props.name); const [nextName, setNextName] = useState(name); + useEffect(() => { + setName(props.name); + }, [props.name]); + const handleOnEditClick = () => { setIsEditing(true); }; @@ -38,6 +43,9 @@ export default function Tile(props: Props) { }; const handleConfirmClick = () => { + if (props.onSubmit) { + props.onSubmit({ id: props.id, value: nextName }); + } setName(nextName); setIsEditing(false); };