Skip to content

Commit

Permalink
add number of tasks in task group
Browse files Browse the repository at this point in the history
  • Loading branch information
fivaz committed May 30, 2024
1 parent 7c2091d commit 3cf2edf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 23 deletions.
7 changes: 1 addition & 6 deletions src/lib/components/dashboard/Dashboard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@
import { auth } from '$lib/firebase';
import { Dialog, TransitionChild, TransitionRoot } from '@rgossiaux/svelte-headlessui';
import { Bars3, XMark } from '@steeze-ui/heroicons';
import {
CalendarDays,
Goal,
ListChecks,
Tags,
} from '@steeze-ui/lucide-icons';
import { CalendarDays, Goal, ListChecks, Tags } from '@steeze-ui/lucide-icons';
import { Icon } from '@steeze-ui/svelte-icon';
import { clsx } from 'clsx';
import { onAuthStateChanged } from 'firebase/auth';
Expand Down
19 changes: 14 additions & 5 deletions src/lib/task/time-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@ import { DATE } from '$lib/consts';
import { type AnyTask, getDurationInMinutes } from '$lib/task/utils';
import { parse, set } from 'date-fns';

export function getNumberOfTasks(tasks: AnyTask[]) {
if (tasks.length === 0) {
return '';
}
if (tasks.length === 1) {
return '(1 task)';
}
return `(${tasks.length} tasks)`;
}
export function getTotalDuration(tasks: AnyTask[]): string {
const totalDurationInMinutes = tasks.reduce((sum, task) => sum + getDurationInMinutes(task), 0);
return convertMinutesToTime(totalDurationInMinutes);
}

export function getTaskDate(task: AnyTask) {
const dateString = 'date' in task ? task.date : task.deadline;

Expand Down Expand Up @@ -30,11 +44,6 @@ export function convertMinutesToTime(time: number): string {
return `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}`;
}

export function getTotalDuration(tasks: AnyTask[]): string {
const totalDurationInMinutes = tasks.reduce((sum, task) => sum + getDurationInMinutes(task), 0);
return convertMinutesToTime(totalDurationInMinutes);
}

export function getCurrentRoundedDate() {
return roundTo15(new Date());
}
Expand Down
14 changes: 2 additions & 12 deletions src/routes/dashboard/tasks/task-list/TaskList.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import type { AnyTask } from '$lib/task/utils';
import { getTotalDuration } from '$lib/task/time-utils';
import { getNumberOfTasks, getTotalDuration } from '$lib/task/time-utils';
import { Clipboard, ClipboardCopy, ClipboardList } from '@steeze-ui/lucide-icons';
import { Icon } from '@steeze-ui/svelte-icon';
import { clsx } from 'clsx';
Expand All @@ -15,16 +15,6 @@
export let userId: string;
$: isDroppable = label !== GROUPS.Recurring && label !== GROUPS.Overdue;
function getNumberOfTasks() {
if (tasks.length === 0) {
return '';
}
if (tasks.length === 1) {
return '(1 task)';
}
return `(${tasks.length} tasks)`;
}
</script>

<!--recurring and overdue list shouldn't be droppable-->
Expand All @@ -37,7 +27,7 @@
<Icon class="h-5 w-5" src={Clipboard} />
{/if}
<div>{label}</div>
<div>{getNumberOfTasks()}</div>
<div>{getNumberOfTasks(tasks)}</div>
</div>
<div>{getTotalDuration(tasks)}</div>
</div>
Expand Down

0 comments on commit 3cf2edf

Please sign in to comment.