Skip to content

Commit

Permalink
feat: add tomorrow filter for tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
paolojulian committed Sep 15, 2024
1 parent 2cd655f commit 57f2d86
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
4 changes: 4 additions & 0 deletions components/tasks/TaskFilters/TaskFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ const TASK_FILTERS: TabItem<TaskFilterTypes>[] = [
key: 'Today',
value: 'Today',
},
{
key: 'Tomorrow',
value: 'Tomorrow',
},
{
key: 'All',
value: 'All',
Expand Down
23 changes: 22 additions & 1 deletion components/tasks/TaskList/EmptyTaskList/EmptyTaskList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ function RenderEmptyText({ filterType }: { filterType: TaskFilterTypes }) {
switch (filterType) {
case 'Completed':
return <NoCompletedTasks />;
case 'Tomorrow':
return <NoTasksTomorrow />;
case 'Scheduled':
return <NoScheduledTasks />;
case 'Today':
Expand Down Expand Up @@ -74,7 +76,26 @@ function NoTasksToday() {
variant="body-md"
style={{ textAlign: 'center', color: colors.v2.grayLight, maxWidth: 300 }}
>
You can now relax or add additional hustles.
You're all clear for today! Enjoy your free time or feel free to plan ahead.
</ThemedText>
</Stack>

<TapToCreateTask />
</Stack>
);
}

function NoTasksTomorrow() {
return (
<Stack style={{ alignItems: 'center', gap: 24 }}>
<Stack style={{ alignItems: 'center', gap: 8 }}>
<ThemedText variant="header-md">No Task Due Tomorrow</ThemedText>
<ThemedText
variant="body-md"
style={{ textAlign: 'center', color: colors.v2.grayLight, maxWidth: 300 }}
>
Looks like you're all set for tomorrow! Feel free to kick back and relax, or get a head
start on future tasks.
</ThemedText>
</Stack>

Expand Down
2 changes: 1 addition & 1 deletion hooks/services/task/task.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export enum TaskQueryKeys {
tasksDueTomorrow = 'task-due-tomorrow',
}

export type TaskFilterTypes = 'Today' | 'All' | 'Scheduled' | 'Completed';
export type TaskFilterTypes = 'Today' | 'Tomorrow' | 'All' | 'Scheduled' | 'Completed';

export type TaskQueryFilters = {
filterType: TaskFilterTypes;
Expand Down
17 changes: 16 additions & 1 deletion hooks/services/task/useTasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ function buildQuery(filters: TaskQueryFilters) {
AND is_completed = 0
ORDER BY reminder_date ASC
`;
case 'Tomorrow':
return /* sql */ `
SELECT * FROM task
WHERE reminder_date BETWEEN $startOfDayEpoch AND $endOfDayEpoch
AND is_completed = 0
ORDER BY reminder_date ASC
`;
case 'All':
return /* sql */ `
SELECT * FROM task
Expand All @@ -55,9 +62,17 @@ function buildQuery(filters: TaskQueryFilters) {
}

function buildVariables(filters: TaskQueryFilters): SQLiteBindParams {
const today = dayjs();
if (filters.filterType === 'Today') {
return {
$end: convertDateToEpoch(dayjs().endOf('day').toDate()),
$end: convertDateToEpoch(today.endOf('day').toDate()),
};
}

if (filters.filterType === 'Tomorrow') {
return {
$startOfDayEpoch: convertDateToEpoch(today.add(1, 'day').startOf('day').toDate()),
$endOfDayEpoch: convertDateToEpoch(today.add(1, 'day').endOf('day').toDate()),
};
}

Expand Down

0 comments on commit 57f2d86

Please sign in to comment.