Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ITG-95] Update styles of task list and task form according to the design #24

Merged
merged 10 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bode/bode/resources/tasks/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class Tasks(MethodView):
@blueprint.response(200, TaskSchema(many=True))
def get(self):
return Task.query.all()
return Task.query.order_by(Task.is_done, Task.due_date).all()

@blueprint.arguments(TaskInputSchema)
@blueprint.response(201, TaskSchema)
Expand Down
3 changes: 3 additions & 0 deletions cabra/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<link rel="icon" type="image/svg+xml" href="/src/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Cabra</title>
<style>
@import url("https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700;800;900&display=swap");
</style>
</head>
<body>
<div id="root"></div>
Expand Down
17 changes: 12 additions & 5 deletions cabra/src/pages/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
import "twin.macro";

import CreateTaskForm from "./components/CreateTaskForm";
import Layout from "./components/Layout";
import RandomGoat from "./components/RandomGoat";
import { Link } from "react-router-dom";
import NavigationButton from "./components/NavigationButton";
import { PlusIcon } from "@heroicons/react/solid";
import TasksList from "./components/TasksList";
import { routeHelpers } from "../routes";

export default function HomePage() {
return (
<Layout>
<div tw="w-[90%] max-w-xl space-y-6 relative z-10">
<CreateTaskForm />
<div tw="w-[90%] max-w-2xl space-y-6 relative z-10">
<div tw="w-full flex justify-end">
<Link to={routeHelpers.task.new}>
<NavigationButton tw="bg-secondary text-stone-50">
<PlusIcon width={20} height={20} /> Add new task
</NavigationButton>
</Link>
</div>
<TasksList />
</div>
<RandomGoat />
</Layout>
);
}
28 changes: 28 additions & 0 deletions cabra/src/pages/TaskCreate.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import "twin.macro";

import { ArrowLeftIcon } from "@heroicons/react/solid";
import CreateTaskForm from "./components/CreateTaskForm";
import Layout from "./components/Layout";
import NavigationButton from "./components/NavigationButton";
import { useNavigate } from "react-router-dom";

export default function TaskCreate() {
const navigate = useNavigate();
return (
<Layout>
<div tw="w-[90%] max-w-2xl p-4 rounded-xl bg-primary shadow-2xl">
<div tw="flex justify-between items-end mb-4">
<h1 tw="text-2xl text-stone-50 font-bold ">Create new task</h1>
<NavigationButton
tw="text-stone-50 bg-secondary"
onClick={() => navigate(-1)}
>
<ArrowLeftIcon height={20} width={20} />
Go Back
</NavigationButton>
</div>
<CreateTaskForm />
</div>
</Layout>
);
}
2 changes: 1 addition & 1 deletion cabra/src/pages/TaskDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function TaskDetailsPage() {
return (
<Layout>
<NavigationButton
tw="text-stone-50 bg-blue-800"
tw="text-stone-50 bg-secondary"
onClick={() => navigate(-1)}
>
<ArrowLeftIcon height={20} width={20} /> Go Back
Expand Down
6 changes: 3 additions & 3 deletions cabra/src/pages/TaskEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ export default function TaskEditPage() {
if (isLoading || !data) return <Layout>Loading</Layout>;
return (
<Layout>
<div tw="w-[90%] max-w-xl">
<div tw="w-[90%] max-w-2xl p-4 bg-primary rounded-xl">
<div tw="flex justify-between items-end mb-4">
<h1 tw="text-2xl text-stone-50 font-bold ">Edit task</h1>
<NavigationButton
tw="text-stone-50 bg-blue-800"
tw="text-stone-50 bg-secondary"
onClick={() => navigate(-1)}
>
<ArrowLeftIcon height={20} width={20} />
Expand All @@ -52,7 +52,7 @@ export default function TaskEditPage() {
<TaskForm task={data.data} onSubmit={editTask.mutateAsync} />
<div tw="grid gap-4">
<div tw="w-full">
<Label>subtasks:</Label>
<Label>Subtasks:</Label>
<SubtasksListEdit parentId={id} />
</div>
</div>
Expand Down
7 changes: 0 additions & 7 deletions cabra/src/pages/components/AddDependenceButton.tsx

This file was deleted.

58 changes: 50 additions & 8 deletions cabra/src/pages/components/CheckBox.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,57 @@
import tw, { styled } from "twin.macro";
import tw, { TwStyle, styled } from "twin.macro";

import { CheckCircleIcon } from "@heroicons/react/outline";
import { InputHTMLAttributes } from "react";

const StyledCheckboxInput = styled.input(
tw`flex items-center gap-2 p-2 rounded checked:bg-blue-500 checked:border-blue-500`
);

type Props = Omit<InputHTMLAttributes<HTMLInputElement>, "type"> & {
type Props = Omit<
InputHTMLAttributes<HTMLInputElement>,
"type" | "id" | "size"
> & {
className?: string;
id: string;
size?: Size;
};
type Size = "sm" | "base" | "lg";

const StyledInput = styled.input(tw`absolute h-0 w-0 opacity-0`);

const labelSizes: Record<Size, TwStyle> = {
sm: tw`w-7 h-7`,
base: tw`w-9 h-9`,
lg: tw`w-11 h-11`,
};

const iconSizes: Record<Size, { height: number; width: number }> = {
sm: { height: 20, width: 20 },
base: { height: 24, width: 24 },
lg: { height: 28, width: 28 },
};

export default function Checkbox(props: Props) {
return <StyledCheckboxInput {...props} type="checkbox" />;
const Label = styled.label<{ size: Size }>`
${tw`select-none`}

.checkmark {
${tw`place-items-center rounded grid cursor-pointer`}
${tw`bg-slate-300 text-slate-400 transition-all shadow-xl hover:opacity-60`}
${({ size }) => labelSizes[size]}
}

input:checked ~ .checkmark {
${tw`bg-success text-green-900`}
}

input:focus ~ .checkmark {
${tw`ring-2`}
}
`;

export default function Checkbox({ id, size = "base", ...props }: Props) {
return (
<Label id={id} size={size}>
<StyledInput {...props} id={id} type="checkbox" />
<span className="checkmark">
<CheckCircleIcon {...iconSizes[size]} />
</span>
</Label>
);
}
8 changes: 7 additions & 1 deletion cabra/src/pages/components/CreateTaskForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { useMutation, useQueryClient } from "react-query";

import { ITask } from "../../types/task";
import TaskForm from "./TaskForm";
import { routeHelpers } from "../../routes";
import { useNavigate } from "react-router-dom";

const emptyTask: Omit<ITask, "id"> = {
description: "",
Expand All @@ -13,9 +15,13 @@ const emptyTask: Omit<ITask, "id"> = {
};

export default function CreateTaskForm() {
const navigate = useNavigate();
const client = useQueryClient();
const addTask = useMutation(createTask, {
onSuccess: () => client.invalidateQueries(getTasks.cacheKey),
onSuccess: () => {
client.invalidateQueries(getTasks.cacheKey);
navigate(routeHelpers.tasks);
},
});

return <TaskForm onSubmit={addTask.mutateAsync} task={emptyTask} />;
Expand Down
2 changes: 1 addition & 1 deletion cabra/src/pages/components/MiniTaskDelete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function MiniTaskDelete({
taskId,
}: Props) {
return (
<div tw="rounded-xl w-full bg-white shadow-2xl text-blue-800 p-1.5">
<div tw="rounded-xl w-full bg-tertiary shadow-2xl text-black p-1.5">
<p tw="flex items-center text-sm">
{title}
<NavigationButton
Expand Down
2 changes: 1 addition & 1 deletion cabra/src/pages/components/NavigationButton.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import tw, { styled } from "twin.macro";

const NavigationButton = styled.button(
tw`flex items-center gap-2 font-bold p-2 rounded transform transition-transform hover:scale-105`
tw`flex items-center gap-2 font-bold p-2 shadow-xl rounded transform transition-transform hover:scale-105`
);

export default NavigationButton;
7 changes: 6 additions & 1 deletion cabra/src/pages/components/SubtasksList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ const Subtask = ({ subtask, parentId }: Props) => {
<div tw="rounded-xl bg-tertiary text-secondary p-1.5 grid">
<p tw="font-medium text-xs">{subtask.title}</p>
<p tw="place-self-end">
<Checkbox checked={subtask.isDone} onChange={handleIsDoneChange} />
<Checkbox
id={subtask.id}
checked={subtask.isDone}
onChange={handleIsDoneChange}
size="sm"
/>
</p>
{errorMessage && (
<p tw="flex items-center text-orange-500 pt-1">&nbsp;{errorMessage}</p>
Expand Down
60 changes: 32 additions & 28 deletions cabra/src/pages/components/SubtasksListEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ import { createTask, deleteTask, getTask, getTasks } from "../../api/tasks";
import tw, { styled } from "twin.macro";
import { useMutation, useQuery, useQueryClient } from "react-query";

import AddDependenceButton from "./AddDependenceButton";
import { ITask } from "../../types/task";
import { ITaskRelation } from "../../types/taskRelation";
import MiniTaskDelete from "./MiniTaskDelete";
import { PlusIcon } from "@heroicons/react/solid";

const Container = styled.div(tw`text-gray-50 w-full space-y-4`);
const fieldStyles = tw`w-full px-4 py-2 rounded-xl text-blue-800 placeholder:text-blue-800/60 font-size[small]`;
const Container = styled.div(tw`text-gray-50 w-full space-y-2`);
const AddSubtaskButton = styled.button(
tw`bg-secondary p-2 text-white font-semibold`,
tw`rounded shadow-2xl flex gap-2 transition-transform transform hover:scale-105`
);
const SubtaskInput = styled.input(
tw`form-input w-full px-4 py-2 rounded-lg shadow-2xl bg-tertiary text-black placeholder:text-primary/60`
);

const emptyTask: Omit<ITask, "id"> = {
description: "",
Expand Down Expand Up @@ -77,33 +83,31 @@ export default function SubtasksListEdit({ parentId }: Props) {

return (
<div>
<Container>
{subtasks.map((relatedTask) => (
<MiniTaskDelete
key={relatedTask.relationId}
title={relatedTask.task.title}
onClickDelete={removeTask.mutateAsync}
taskId={relatedTask.task.id}
/>
))}
</Container>
<form onSubmit={handleSubmitSubtask}>
<div tw="rounded-xl w-full text-blue-800 p-1.5">
<p tw="flex items-center">
<input
css={[tw`form-input`, fieldStyles]}
id="subtask"
type="text"
value={val}
maxLength={80}
required
onChange={(event) => setVal(event.target.value)}
/>
</p>
<p tw="flex items-center">
<AddDependenceButton type="submit">+add</AddDependenceButton>
</p>
<div tw="w-full flex gap-4 mb-4">
<SubtaskInput
id="subtask"
maxLength={80}
onChange={(event) => setVal(event.target.value)}
placeholder="Subtask name"
required
type="text"
value={val}
/>
<AddSubtaskButton type="submit">
<PlusIcon width={24} height={24} /> Add
</AddSubtaskButton>
</div>
<Container>
{subtasks.map((relatedTask) => (
<MiniTaskDelete
key={relatedTask.relationId}
title={relatedTask.task.title}
onClickDelete={removeTask.mutateAsync}
taskId={relatedTask.task.id}
/>
))}
</Container>
</form>
</div>
);
Expand Down
65 changes: 0 additions & 65 deletions cabra/src/pages/components/Task.tsx

This file was deleted.

Loading