Last active
May 24, 2020 00:11
-
-
Save david-mart/5ba523c33b99ee0641332e297421f439 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 TaskDetails = ({ id }) => { | |
const [updateTask] = useMutation(UPDATE_TASK); | |
const { data = {} } = useQuery(GET_TASK, { variables: { id } }); | |
const { task = { comments: [] } }: { task: ITask } = data; | |
const onUpdate = (key) => (value) => { | |
updateTask({ variables: { task: { [key]: value }, id } }); | |
}; | |
return ( | |
<div> | |
<Typography.Text strong editable={{ onChange: onUpdate('name') }}> | |
{task.name} | |
</Typography.Text> | |
<Typography.Text editable={{ onChange: onUpdate('notes') }}> | |
{task.notes} | |
</Typography.Text> | |
</div> | |
); | |
}; | |
const TaskListItem = ({ notes, name }: ITask) => ( | |
<div> | |
<Typography.Title level={4}>{name}</Typography.Title> | |
<Typography.Text>{notes}</Typography.Text> | |
</div> | |
); | |
const TaskList = () => { | |
const { data = {} } = useQuery(GET_TASKS); | |
const { tasks = [] } = data; | |
const [activeTask, setActiveTask] = useState(null); | |
return ( | |
<div> | |
{tasks.map((task: ITask) => ( | |
<div | |
key={task.id} | |
onClick={() => { | |
setActiveTask(task.id); | |
}} | |
> | |
<TaskListItem {...task} /> | |
</div> | |
))} | |
{activeTask && <TaskDetails id={activeTask} />} | |
</div> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment