Skip to content

Commit

Permalink
Improves todo list and adds progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
wdevon99 committed Mar 10, 2024
1 parent ac6283a commit 1a55bfd
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 9 deletions.
6 changes: 5 additions & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/** @type {import('next').NextConfig} */
const nextConfig = {};
const nextConfig = {
images: {
domains: ["lh3.googleusercontent.com", "avatars.githubusercontent.com"],
},
};

export default nextConfig;
4 changes: 2 additions & 2 deletions src/components/atoms/CustomAvatar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ function CustomAvatar({ size = 'large', image, mainText, subText }: Props) {
type Props = {
size?: 'large' | 'small' | 'default' | number,
image: string,
mainText: string,
subText: string
mainText?: string,
subText?: string
}

export default CustomAvatar;
2 changes: 1 addition & 1 deletion src/components/molecules/AuthCard/styles.module.sass
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.container
padding: 0 120px
.button
margin-bottom: 10px
margin-bottom: 12px
.label
margin-top: 0
margin-bottom: 12px
Expand Down
29 changes: 25 additions & 4 deletions src/components/pages/Dashboard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
"use client"

import { useEffect, useState } from "react";
import { Button, Card, FloatButton, Form, Input, List, Modal, Skeleton, Tag, message } from "antd";
import { Button, Card, FloatButton, Form, Input, List, Modal, Progress, Skeleton, message } from "antd";
import { PlusOutlined, DeleteOutlined, ArrowLeftOutlined, UndoOutlined } from '@ant-design/icons';
import { useSession } from "next-auth/react";
import { useRouter } from "next/navigation";
import TextArea from "antd/es/input/TextArea";
import TodoService from "@services/TodoService";
import CustomAvatar from "@components/atoms/CustomAvatar";
import Colors from "@styles/variables.module.sass";
import styles from "./styles.module.sass";

export default function Dashboard() {
Expand Down Expand Up @@ -67,7 +69,7 @@ export default function Dashboard() {
const updatedTodo: Todo = await response.json();
const updatedTodos = todos?.map((todo: Todo) => todo._id.toString() === updatedTodo._id.toString() ? updatedTodo : todo);

messageApi.success(updatedTodo.isComplete ? "Completed todo! 🎉" : "Undo success");
messageApi.success(updatedTodo.isComplete ? "Completed todo 🎉" : "Undo success");

setTodos(updatedTodos);
};
Expand All @@ -81,8 +83,26 @@ export default function Dashboard() {
setTodos(filteredTodos);
};

const completedPercentage = () => {
if (!todos?.length) return 0;
const totalTodoCount = todos?.length;
const completedTodoCount = todos?.filter((todo: Todo) => todo.isComplete)?.length;

return Math.floor((completedTodoCount / totalTodoCount) * 100);
}

const getProgressBarColor = () => {
if (completedPercentage() === 100) return Colors.successColor;
if (completedPercentage() >= 50) return Colors.warningColor;
return Colors.errorColor;
}

const renderHeader = () => (
<>
<CustomAvatar
image={session?.user?.image}
size={60}
/>
<h1 className={styles.heading}>Hi {session?.user?.name?.split(' ')?.[0]} :)</h1>
<h2 className={styles.sub_heading}>Track your todos with ease.</h2>
</>
Expand Down Expand Up @@ -119,13 +139,14 @@ export default function Dashboard() {
title={<span className={todo.isComplete ? styles.completedTodoText : ''}>{todo?.todoTitle}</span>}
description={<span className={todo.isComplete ? styles.completedTodoText : ''}>{todo?.todoDescription}</span>}
/>
{todo.isComplete ? <Tag color="success">Completed</Tag> : null}

</Skeleton>
</List.Item>
)}
/>
</Card>
<Card style={{ width: CARD_WIDTH, marginTop: 20 }}>
<Progress percent={completedPercentage()} strokeColor={getProgressBarColor()} />
</Card>
<Modal
title="Add new todo"
open={isAddTodoModalOpen}
Expand Down
1 change: 0 additions & 1 deletion src/components/pages/Dashboard/styles.module.sass
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
.heading
font-size: 24px
margin-bottom: 5px
margin-top: 80px

.sub_heading
font-size: 14px
Expand Down
8 changes: 8 additions & 0 deletions src/styles/variables.module.sass
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
// ------ Colors ------
$primary-color: #292929
$primary-surface-color: #F9F9F9

$success-color: #52c41a
$warning-color: #faad14
$error-color: #ff4d4f

$secondary-surface-color: #FFF
$font-color-light: #FFF
$font-color-dark: #292929
Expand All @@ -13,3 +18,6 @@ $border-radius: 0.3rem
// ------ Exports ------
:export
primaryColor: $primary-color
successColor: $success-color
warningColor: $warning-color
errorColor: $error-color

0 comments on commit 1a55bfd

Please sign in to comment.