Added hide

This commit is contained in:
Kasper Juul Hermansen 2022-04-25 10:50:01 +02:00
parent 9e88b973fb
commit 05c4818877
5 changed files with 81 additions and 40 deletions

View File

@ -2,5 +2,6 @@
<project version="4"> <project version="4">
<component name="PrettierConfiguration"> <component name="PrettierConfiguration">
<option name="myRunOnSave" value="true" /> <option name="myRunOnSave" value="true" />
<option name="myRunOnReformat" value="true" />
</component> </component>
</project> </project>

View File

@ -2,8 +2,14 @@ import { FC } from "react";
interface PageHeadingProps { interface PageHeadingProps {
title: string; title: string;
onClick?: () => void;
} }
export const PageHeading: FC<PageHeadingProps> = ({ title }) => ( export const PageHeading: FC<PageHeadingProps> = ({ title, onClick }) => (
<h3 className="font-bold text-xl tracking-wide">{title}</h3> <h3
className="font-bold text-xl tracking-wide hover:underline"
onClick={onClick}
>
{title}
</h3>
); );

View File

@ -1,3 +1,8 @@
export const ProjectsHeading = (props: { title: string }) => ( export const ProjectsHeading = (props: {
<h5 className="text-sm font-bold">{props.title}</h5> title: string;
onClick: () => void;
}) => (
<h5 className="text-sm font-bold hover:underline" onClick={props.onClick}>
{props.title}
</h5>
); );

View File

@ -2,13 +2,14 @@ import { Todo } from "@src/core/entities/todo";
import { TodoItem } from "@src/components/todos/todoItem"; import { TodoItem } from "@src/components/todos/todoItem";
import { AddTodo } from "@src/components/todos/addTodo"; import { AddTodo } from "@src/components/todos/addTodo";
import { useUpdateTodo } from "@src/presentation/hooks/socketHooks"; import { useUpdateTodo } from "@src/presentation/hooks/socketHooks";
import { useMemo } from "react"; import { useMemo, useState } from "react";
export const TodoList = (props: { export const TodoList = (props: {
todos: Todo[]; todos: Todo[];
hideDone: boolean; hideDone: boolean;
hideProject: boolean; hideProject: boolean;
project: string; project: string;
folded: boolean;
}) => { }) => {
const { updateTodo } = useUpdateTodo(); const { updateTodo } = useUpdateTodo();
@ -25,20 +26,23 @@ export const TodoList = (props: {
return ( return (
<> <>
<ul id="inbox"> {props.folded && <div>...</div>}
{todos.map((t, i) => ( <div className={`space-y-2 ${props.folded ? "hidden" : "block"}`}>
<li key={i}> <ul id="inbox">
<TodoItem {todos.map((t, i) => (
todo={t} <li key={i}>
updateTodo={(todo) => { <TodoItem
updateTodo(todo); todo={t}
}} updateTodo={(todo) => {
displayProject={!props.hideProject} updateTodo(todo);
/> }}
</li> displayProject={!props.hideProject}
))} />
</ul> </li>
<AddTodo project={props.project} /> ))}
</ul>
<AddTodo project={props.project} />
</div>
</> </>
); );
}; };

View File

@ -4,7 +4,46 @@ import { ProjectsHeading } from "@src/components/common/headings/projectsHeading
import { groupByProjects } from "@src/core/actions/utility/groupByProjects"; import { groupByProjects } from "@src/core/actions/utility/groupByProjects";
import { todosApi } from "@src/infrastructure/apis/todosApi"; import { todosApi } from "@src/infrastructure/apis/todosApi";
import { AddTodo } from "@src/components/todos/addTodo"; import { AddTodo } from "@src/components/todos/addTodo";
import { useMemo } from "react"; import { useMemo, useState } from "react";
function Inbox(props: { groupedTodos: any }) {
const [folded, setFolded] = useState(false);
return (
<div className="space-y-2">
<PageHeading
title="Inbox"
onClick={() => setFolded((folded) => !folded)}
/>
<TodoList
todos={props.groupedTodos["inbox"]}
hideDone
project={""}
hideProject={false}
folded={folded}
/>
</div>
);
}
function ProjectItem(props: { title: string; groupedTodos: any }) {
const [folded, setFolded] = useState(false);
return (
<div className="space-y-2">
<ProjectsHeading
title={props.title}
onClick={() => setFolded((folded) => !folded)}
/>
<TodoList
todos={props.groupedTodos[props.title]}
hideDone
project={props.title}
hideProject
folded={folded}
/>
</div>
);
}
const HomePage = () => { const HomePage = () => {
const { data, isLoading } = todosApi.useGetActiveTodosQuery(); const { data, isLoading } = todosApi.useGetActiveTodosQuery();
@ -32,28 +71,14 @@ const HomePage = () => {
return ( return (
<main className="py-8 px-14 space-y-6"> <main className="py-8 px-14 space-y-6">
<section className="space-y-8 mx-auto max-w-4xl"> <section className="space-y-8 mx-auto max-w-4xl">
{groupedTodos["inbox"] && ( {groupedTodos["inbox"] && <Inbox groupedTodos={groupedTodos} />}
<div className="space-y-2">
<PageHeading title="Inbox" />
<TodoList
todos={groupedTodos["inbox"]}
hideDone
project={""}
hideProject={false}
/>
</div>
)}
{sections && {sections &&
sections.map((section) => ( sections.map((section) => (
<div key={section} className="space-y-2"> <ProjectItem
<ProjectsHeading title={section} /> key={section}
<TodoList title={section}
todos={groupedTodos[section]} groupedTodos={groupedTodos}
hideDone />
project={section}
hideProject
/>
</div>
))} ))}
{onlyActiveTodos && onlyActiveTodos.length === 0 && ( {onlyActiveTodos && onlyActiveTodos.length === 0 && (
<div className="space-y-4"> <div className="space-y-4">