Skip to content

Commit

Permalink
refactor: delete ProjectStatus.ts, TaskStatus.ts, and TaskOrderBy.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
flsilva committed Jan 20, 2024
1 parent cf7e206 commit b71b7b6
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 51 deletions.
5 changes: 2 additions & 3 deletions src/app/app/projects/[projectId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { ProjectPageHeader } from '@/features/app/projects/ui/ProjectPageHeader'
import { ProjectPageSkeleton } from '@/features/app/projects/ui/ProjectPageSkeleton';
import { AddTask } from '@/features/app/tasks/ui/AddTask';
import { TaskList } from '@/features/app/tasks/ui/TaskList';
import { TaskStatus } from '@/features/app/tasks/data-access/TaskStatus';
import { TaskForm } from '@/features/app/tasks/ui/TaskForm';

interface ProjectPageProps {
Expand All @@ -18,15 +17,15 @@ export default function ProjectPage({ params: { projectId } }: ProjectPageProps)
<Suspense fallback={<ProjectPageSkeleton className="mt-8" ssrOnly="Loading project..." />}>
<ProjectPageHeader id={projectId} />
<NoTasksInProject id={projectId} />
<TaskList byProject={projectId} only={TaskStatus.Incomplete} />
<TaskList byProject={projectId} only="incomplete" />
<AddTask containerClassName="my-8" projectId={projectId}>
<TaskForm
className="rounded-md bg-gray-100 px-2 py-6 sm:px-6 mt-4"
projectId={projectId}
startOnEditingMode
/>
</AddTask>
<TaskList byProject={projectId} only={TaskStatus.Completed} />
<TaskList byProject={projectId} only="completed" />
</Suspense>
</>
);
Expand Down
3 changes: 1 addition & 2 deletions src/app/app/projects/active/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Suspense } from 'react';
import { ProjectList } from '@/features/app/projects/ui/ProjectList';
import { ProjectListSkeleton } from '@/features/app/projects/ui/ProjectListSkeleton';
import { ProjectsPageHeader } from '@/features/app/projects/ui/ProjectsPageHeader';
import { ProjectStatus } from '@/features/app/projects/data-access/ProjectStatus';

export default function ActiveProjectsPage() {
const empty = <p className="text-sm font-medium text-gray-600">No active projects.</p>;
Expand All @@ -12,7 +11,7 @@ export default function ActiveProjectsPage() {
<>
<ProjectsPageHeader archived={false} />
<Suspense fallback={<ProjectListSkeleton ssrOnly="Loading projects..." />}>
<ProjectList empty={empty} itemClassName="pl-2" only={ProjectStatus.Active} />
<ProjectList empty={empty} itemClassName="pl-2" only="active" />
</Suspense>
</>
);
Expand Down
3 changes: 1 addition & 2 deletions src/app/app/projects/archived/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Suspense } from 'react';
import { ProjectList } from '@/features/app/projects/ui/ProjectList';
import { ProjectListSkeleton } from '@/features/app/projects/ui/ProjectListSkeleton';
import { ProjectsPageHeader } from '@/features/app/projects/ui/ProjectsPageHeader';
import { ProjectStatus } from '@/features/app/projects/data-access/ProjectStatus';

export default function ArchivedProjectsPage() {
const empty = <p className="text-sm font-medium text-gray-600">No archived projects.</p>;
Expand All @@ -12,7 +11,7 @@ export default function ArchivedProjectsPage() {
<>
<ProjectsPageHeader archived={true} />
<Suspense fallback={<ProjectListSkeleton ssrOnly="Loading projects..." />}>
<ProjectList empty={empty} itemClassName="pl-2" only={ProjectStatus.Archived} />
<ProjectList empty={empty} itemClassName="pl-2" only="archived" />
</Suspense>
</>
);
Expand Down
14 changes: 2 additions & 12 deletions src/app/app/today/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,22 @@ import { subDays } from 'date-fns';
import { AddTask } from '@/features/app/tasks/ui/AddTask';
import { TaskList } from '@/features/app/tasks/ui/TaskList';
import { TaskForm } from '@/features/app/tasks/ui/TaskForm';
import { TaskStatus } from '@/features/app/tasks/data-access/TaskStatus';
import { TodayPageHeader } from '@/features/app/today/ui/TodayPageHeader';
import { TaskListSkeleton } from '@/features/app/tasks/ui/TaskListSkeleton';
import { ProjectStatus } from '@/features/app/projects/data-access/ProjectStatus';

export default function TodayPage() {
return (
<>
<TodayPageHeader />
<Suspense fallback={<TaskListSkeleton className="mt-3" ssrOnly="Loading tasks..." />}>
<TaskList
dueBy={subDays(new Date(), 1)}
only={TaskStatus.Incomplete}
onlyProject={ProjectStatus.Active}
>
<TaskList dueBy={subDays(new Date(), 1)} only="incomplete" onlyProject="active">
{({ list: listOverdue, tasks: tasksOverdue }) => (
<>
{tasksOverdue.length > 0 && <p className="mb-4 text-xs font-semibold">Overdue</p>}
{listOverdue}
{tasksOverdue.length > 0 && <p className="mt-8 mb-4 text-xs font-semibold">Today</p>}

<TaskList
dueOn={new Date()}
only={TaskStatus.Incomplete}
onlyProject={ProjectStatus.Active}
>
<TaskList dueOn={new Date()} only="incomplete" onlyProject="active">
{({ list: listDueToday, tasks: tasksDueToday }) => (
<>
{listDueToday}
Expand Down
4 changes: 0 additions & 4 deletions src/features/app/projects/data-access/ProjectStatus.ts

This file was deleted.

5 changes: 2 additions & 3 deletions src/features/app/projects/ui/ProjectList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { twMerge } from 'tailwind-merge';
import { ClassNamePropsOptional } from '@/features/shared/ui/ClassNameProps';
import { ErrorList } from '@/features/shared/ui/error/ErrorList';
import { ProjectListItem } from './ProjectListItem';
import { ProjectStatus } from '../data-access/ProjectStatus';
import { getProjects } from '../data-access/ProjectsDataAccess';

interface ProjectListProps extends ClassNamePropsOptional {
Expand All @@ -14,7 +13,7 @@ interface ProjectListProps extends ClassNamePropsOptional {
readonly empty?: React.ReactNode;
readonly itemClassName?: string;
readonly itemHref?: string;
readonly only?: ProjectStatus;
readonly only?: 'active' | 'archived';
}

/*
Expand All @@ -33,7 +32,7 @@ export const ProjectList = async ({
only,
}: ProjectListProps) => {
const { data: projects, errors } = await getProjects({
...(only && { isArchived: only === ProjectStatus.Archived }),
...(only && { isArchived: only === 'archived' }),
});

if (errors) return <ErrorList errors={errors} />;
Expand Down
3 changes: 1 addition & 2 deletions src/features/app/shared/ui/MainMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { twMerge } from 'tailwind-merge';
import { PlusSignalIcon } from '@/features/shared/ui/icon/PlusSignalIcon';
import { ProjectList } from '@/features/app/projects/ui/ProjectList';
import { ProjectListSkeleton } from '@/features/app/projects/ui/ProjectListSkeleton';
import { ProjectStatus } from '@/features/app/projects/data-access/ProjectStatus';
import { MainMenuLink } from './MainMenuLink';
import { ClassNamePropsOptional } from '@/features/shared/ui/ClassNameProps';
import { CalendarTodayIcon } from '@/features/shared/ui/icon/CalendarTodayIcon';
Expand Down Expand Up @@ -50,7 +49,7 @@ export const MainMenu = ({ className }: ClassNamePropsOptional) => {
activeItemClassName={activeClassName}
empty={noProjects}
itemClassName="pl-9"
only={ProjectStatus.Active}
only="active"
/>
</Suspense>
</nav>
Expand Down
6 changes: 0 additions & 6 deletions src/features/app/tasks/data-access/TaskOrderBy.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/features/app/tasks/data-access/TaskStatus.ts

This file was deleted.

23 changes: 10 additions & 13 deletions src/features/app/tasks/data-access/TasksDataAccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ import {
createServerSuccessResponse,
} from '@/features/shared/data-access/ServerResponse';
import { genericAwareOfInternalErrorMessage } from '@/features/shared/ui/error/errorMessages';
import { ProjectStatus } from '@/features/app/projects/data-access/ProjectStatus';
import { TaskStatus } from './TaskStatus';
import { TaskOrderBy } from './TaskOrderBy';

export type CreateTaskDto = z.infer<typeof createTaskSchema>;

Expand Down Expand Up @@ -128,9 +125,9 @@ export interface GetTasksParams {
readonly byProject?: string;
readonly dueBy?: Date;
readonly dueOn?: Date;
readonly only?: TaskStatus;
readonly onlyProject?: ProjectStatus;
readonly orderBy?: TaskOrderBy;
readonly only?: 'completed' | 'incomplete';
readonly onlyProject?: 'active' | 'archived';
readonly orderBy?: 'completedAtAsc' | 'completedAtDesc' | 'createdAtAsc' | 'createdAtDesc';
}

export const getTasks = async ({
Expand All @@ -152,21 +149,21 @@ export const getTasks = async ({
* Sensible default: order completed tasks by completedAt desc.
*/
let _orderBy = orderBy;
if (!_orderBy && only === TaskStatus.Completed) _orderBy = TaskOrderBy.CompletedAtDesc;
if (!_orderBy && only === 'completed') _orderBy = 'completedAtDesc';
/**/

let orderByQuery: { completedAt: 'asc' | 'desc' } | { createdAt: 'asc' | 'desc' };
switch (_orderBy) {
case TaskOrderBy.CompletedAtAsc:
case 'completedAtAsc':
orderByQuery = { completedAt: 'asc' };
break;
case TaskOrderBy.CompletedAtDesc:
case 'completedAtDesc':
orderByQuery = { completedAt: 'desc' };
break;
case TaskOrderBy.CreatedAtAsc:
case 'createdAtAsc':
orderByQuery = { createdAt: 'asc' };
break;
case TaskOrderBy.CreatedAtDesc:
case 'createdAtDesc':
orderByQuery = { createdAt: 'desc' };
break;
default:
Expand All @@ -184,10 +181,10 @@ export const getTasks = async ({
lte: zonedTimeToUtc(endOfDay(dueOn), timeZone),
},
}),
...(only && { completedAt: only === TaskStatus.Completed ? { not: null } : null }),
...(only && { completedAt: only === 'completed' ? { not: null } : null }),
...(byProject && { projectId: byProject }),
...(onlyProject && {
project: { archivedAt: onlyProject === ProjectStatus.Archived ? { not: null } : null },
project: { archivedAt: onlyProject === 'archived' ? { not: null } : null },
}),
},
orderBy: orderByQuery,
Expand Down

0 comments on commit b71b7b6

Please sign in to comment.