Commit 98c2977c by Sakilesh J

fix the changes

parent 7cd34a85
export interface TodoListItems {
id: number;
task: string;
isCompleted: boolean;
}
export interface ItemMethods {
onDelete: (id: number) => void;
updateTask: (id: number, task: string, isCompleted: boolean) => void;
}
\ No newline at end of file
...@@ -6,35 +6,35 @@ import styles from "./form.module.css" ...@@ -6,35 +6,35 @@ import styles from "./form.module.css"
interface FormProps { interface FormProps {
handleSubmit: (data: any) => Promise<void>; onPost: (input: string) => void;
} }
const FormComponent: React.FC<FormProps> = ({ handleSubmit }) => { const FormComponent: React.FC<FormProps> = ({ onPost }) => {
const [input, setinput] = useState('') const [input, setinput] = useState('')
const [isError, setisError] = useState(false) const [isError, setisError] = useState(false)
const onSubmit = (e: React.SyntheticEvent) => {
const handleSubmit = (e: React.SyntheticEvent) => {
e.preventDefault(); e.preventDefault();
console.log(e)
if (input === '') { if (input === '') {
setisError(true) setisError(true)
return return
} }
handleSubmit(input) onPost(input)
} }
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => { const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setinput(e.target.value) setinput(e.target.value)
if (isError) { if (isError) {
setisError(false) setisError(false)
} }
} }
return ( return (
<form className={styles.form} onSubmit={onSubmit}> <form className={styles.form} onSubmit={handleSubmit}>
<div className={styles.iwrapper}> <div className={styles.inputWrapper}>
<Input placeholder="Enter Item..." <Input placeholder="Enter Item..."
onChange={handleChange} ErrorMessage={isError ? "Enter the Field" : undefined} /> onChange={handleChange} ErrorMessage={isError ? "Enter the Field" : undefined} />
</div> </div>
<div className={styles.bwrapper}> <div className={styles.buttonWrapper}>
<Button size="sm" > <Button size="sm" >
Submit Submit
</Button> </Button>
......
.form { .form {
display: flex; display: flex;
padding: 20px; padding: 17px;
width: 100%; width: 100%;
flex-wrap: wrap; flex-wrap: wrap;
gap: 15px; gap: 15px;
background-color: white; background-color: white;
} }
.iwrapper { .inputWrapper {
min-width: 80%; min-width: 80%;
max-height: 50px; max-height: min-content;
flex: 1; flex: 1;
} }
.iwrapper>input { .inputWrapper>input {
width: 100%; width: 100%;
} }
.bwrapper>button { .buttonWrapper>button {
min-width: 100%; min-width: 100%;
} }
.bwrapper { .buttonWrapper {
min-width: auto; min-width: auto;
flex: 1; flex: 1;
} }
\ No newline at end of file
...@@ -2,7 +2,7 @@ import { Meta, StoryObj } from "@storybook/react"; ...@@ -2,7 +2,7 @@ import { Meta, StoryObj } from "@storybook/react";
import FormComponent from "./FormComponent"; import FormComponent from "./FormComponent";
import { fn } from "@storybook/test"; import { fn } from "@storybook/test";
const meta: Meta<typeof FormComponent> = { const meta: Meta<typeof FormComponent> = {
title: "Top-Level/Form", title: "Top-Level",
component: FormComponent, component: FormComponent,
} }
...@@ -12,6 +12,6 @@ type story = StoryObj<typeof meta> ...@@ -12,6 +12,6 @@ type story = StoryObj<typeof meta>
export const Form: story = { export const Form: story = {
args: { args: {
handleSubmit: fn() onPost: fn()
} }
} }
\ No newline at end of file
...@@ -4,25 +4,25 @@ import styles from './item.module.css' ...@@ -4,25 +4,25 @@ import styles from './item.module.css'
import Input from '@/components/base/input/Input'; import Input from '@/components/base/input/Input';
import closeIcon from '@/public/icons/red-x-10333.svg'; import closeIcon from '@/public/icons/red-x-10333.svg';
import Image from 'next/image'; import Image from 'next/image';
export interface ItemProps { import { ItemMethods } from '@/Types/todoTypes';
interface ItemProps extends ItemMethods {
id: number; id: number;
task: string; task: string;
isCompleted: boolean; isCompleted: boolean;
onClose: (id: number) => void;
updateTask: (id: number, task: string, isCompleted: boolean) => void;
} }
const Item: React.FC<ItemProps> = ({ task, isCompleted, onClose, updateTask, id }) => { const Item: React.FC<ItemProps> = ({ task, isCompleted, onDelete, updateTask, id }) => {
const [isChecked, setisChecked] = useState(isCompleted) const [isChecked, setisChecked] = useState(isCompleted)
useEffect(() => { useEffect(() => {
setisChecked(isCompleted) setisChecked(isCompleted)
}, [isCompleted]) }, [isCompleted])
const handleChange = async () => { const handleChange = async () => {
const res: any = await updateTask(id, task, !isCompleted) await updateTask(id, task, !isCompleted)
if (res) { setisChecked(!isChecked)
setisChecked(!isChecked)
}
} }
const handleItem = (e: React.ChangeEvent<HTMLInputElement>) => { const handleItem = (e: React.ChangeEvent<HTMLInputElement>) => {
...@@ -30,22 +30,16 @@ const Item: React.FC<ItemProps> = ({ task, isCompleted, onClose, updateTask, id ...@@ -30,22 +30,16 @@ const Item: React.FC<ItemProps> = ({ task, isCompleted, onClose, updateTask, id
} }
const handleClose = () => { const handleClose = () => {
onClose(id) onDelete(id)
} }
return ( return (
<div className={styles.items}> <div className={styles.item}>
<input type='checkbox' checked={isChecked} onChange={handleChange} className={styles.checkbox} /> <input type='checkbox' checked={isChecked} onChange={handleChange} className={styles.checkbox} />
<Input placeholder='Enter item...' defaultValue={task} onBlur={handleItem} style={{ <Input id="Todo-input" placeholder='Enter item...' defaultValue={task} onBlur={handleItem} style={{
border: 'none', textDecoration: isChecked ? 'line-through' : 'none'
boxShadow: 'none',
padding: 0,
color: 'gray',
fontSize: '18px',
textDecoration: isChecked ? 'line-through' : ''
}} /> }} />
<div className={styles.actions} onClick={handleClose} > <div className={styles.actions} onClick={handleClose} >
<Image src={closeIcon} alt="" width={22} height={22} className={styles.closeIcon} /> <Image src={closeIcon} alt="" width={22} height={22} className={styles.closeIcon} />
</div> </div>
</div> </div>
......
.items { .item {
display: flex; display: flex;
border-bottom: .01px solid rgb(236, 231, 231); border-bottom: .01px solid rgb(236, 231, 231);
padding: 10px 20px; padding: 10px 20px;
...@@ -15,6 +15,14 @@ ...@@ -15,6 +15,14 @@
/* outline: 1px solid black; */ /* outline: 1px solid black; */
} }
.item>div>input {
border: none;
box-shadow: none;
padding: 0;
color: gray;
font-size: 18px;
}
.actions { .actions {
margin-left: auto; margin-left: auto;
min-width: 1.3rem; min-width: 1.3rem;
...@@ -25,7 +33,6 @@ ...@@ -25,7 +33,6 @@
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
/* padding-top: 3px; */
} }
.actions:hover { .actions:hover {
......
...@@ -4,13 +4,6 @@ import { fn } from "@storybook/test"; ...@@ -4,13 +4,6 @@ import { fn } from "@storybook/test";
const meta: Meta<typeof Item> = { const meta: Meta<typeof Item> = {
title: "Top-Level", title: "Top-Level",
component: Item, component: Item,
argTypes: {
id: {
control: {
type: 'text'
}
}
}
} }
...@@ -19,12 +12,11 @@ export default meta; ...@@ -19,12 +12,11 @@ export default meta;
type story = StoryObj<typeof meta> type story = StoryObj<typeof meta>
export const Item_: story = { export const Item_: story = {
args: { args: {
id: '1', id: 1,
isCompleted: true, isCompleted: true,
task: 'Buy groceries', task: 'Buy groceries',
onComplete: fn(), onDelete: fn(),
onChange: fn(), updateTask: fn()
onClose: fn()
}, },
} }
......
...@@ -11,10 +11,6 @@ export default meta; ...@@ -11,10 +11,6 @@ export default meta;
type Story = StoryObj<typeof meta>; type Story = StoryObj<typeof meta>;
// interface TemplateProps {
// variant: 'primary' | 'light' | 'dark';
// }
const Template = () => { const Template = () => {
return ( return (
<div > <div >
......
...@@ -19,35 +19,7 @@ export default function Button({ ...@@ -19,35 +19,7 @@ export default function Button({
children, children,
...rest ...rest
}: ButtonProps) { }: ButtonProps) {
// const classNames = cn(
// 'inline-flex items-center font-medium uppercase focus:outline-none',
// {
// /** backgrounds */
// 'bg-gray-200': disabled,
// 'bg-primary text-light shadow-primary':
// !disabled && !outline && variant === 'primary',
// 'bg-light text-dark shadow-light':
// !disabled && !outline && variant === 'light',
// 'bg-dark text-light shadow-dark':
// !disabled && !outline && variant === 'dark',
// /** outline */
// 'text-primary border-current border shadow-primary':
// !disabled && outline && variant === 'primary',
// 'text-light border-current border shadow-light':
// !disabled && outline && variant === 'light',
// 'text-dark border-current border shadow-dark':
// !disabled && outline && variant === 'dark',
// /** text */
// 'text-gray-400': disabled,
// /* size */
// 'text-sm px-8 py-3': size === 'sm',
// 'text-base px-9 py-3': size === 'md',
// /** block */
// 'w-full justify-center': block,
// /** hover, focus & active */
// 'hover:shadow-xl focus:shadow-glow active:translate-y-0.5': !disabled
// }
// );
const classNames = `${style.btn} ${size === 'sm' ? style.sm : style.md}` const classNames = `${style.btn} ${size === 'sm' ? style.sm : style.md}`
return typeof href === 'string' ? ( return typeof href === 'string' ? (
......
...@@ -4,9 +4,6 @@ import Heading from "./Heading"; ...@@ -4,9 +4,6 @@ import Heading from "./Heading";
const meta: Meta<typeof Heading> = { const meta: Meta<typeof Heading> = {
title: "Basic/Header", title: "Basic/Header",
component: Heading, component: Heading,
argTypes: {
count: { count: 'number' }
},
} }
export default meta; export default meta;
......
import React from 'react' import React from 'react'
import styles from "./heading.module.css" import styles from "./heading.module.css"
interface HeadingProps { interface HeadingProps {
count: number; count?: number;
} }
const Heading: React.FC<HeadingProps> = ({ count }) => { const Heading: React.FC<HeadingProps> = ({ count }) => {
return ( return (
<div className={styles.heading}>You have {count != 0 ? count : "no"} Todos</div> <React.Fragment>
{
count != undefined &&
<div className={styles.heading}>You have {count != 0 ? count : "no"} Todos</div>
}
</React.Fragment>
) )
} }
......
import { Meta, StoryObj } from "@storybook/react"; import { Meta, StoryObj } from "@storybook/react";
import Input from "./Input"; import Input from "./Input";
import { fn } from "@storybook/test"; import { fn } from "@storybook/test";
import React from "react";
const meta: Meta<typeof Input> = { const meta: Meta<typeof Input> = {
title: "Basic",
component: Input, component: Input,
title: "Basic/Input",
tags: ["autodocs"]
} }
export default meta export default meta
type story = StoryObj<typeof meta>; type story = StoryObj<typeof meta>;
export const Primary: story = { export const Input_: story = {
args: { args: {
placeholder: 'Enter the value...', placeholder: 'Enter the value...',
onChange: fn(), onChange: fn(),
}, },
render: (args) => { render: (args) => {
return <> return <React.Fragment>
<p>Without Error</p> <p>Without Error</p>
<Input {...args} /> <Input {...args} />
<p>With Error</p> <p>With Error</p>
<Input {...args} ErrorMessage="Enter the Fields" /> <Input {...args} ErrorMessage="Enter the Fields" />
</> </React.Fragment>
} }
} }
...@@ -6,9 +6,8 @@ interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> { ...@@ -6,9 +6,8 @@ interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {
const Input: React.FC<InputProps> = ({ ErrorMessage, ...props }) => { const Input: React.FC<InputProps> = ({ ErrorMessage, ...props }) => {
return ( return (
<> <div className={styles.Container}>
<input {...props} className={`${ErrorMessage
<input {...props} className={`${styles.input} ${ErrorMessage
&& styles.inputError}`} /> && styles.inputError}`} />
{ {
ErrorMessage && ErrorMessage &&
...@@ -16,7 +15,7 @@ const Input: React.FC<InputProps> = ({ ErrorMessage, ...props }) => { ...@@ -16,7 +15,7 @@ const Input: React.FC<InputProps> = ({ ErrorMessage, ...props }) => {
{ErrorMessage} {ErrorMessage}
</div> </div>
} }
</> </div>
) )
} }
......
.input { .Container input {
padding: 15px 20px; padding: 15px 20px;
border-radius: 5px; border-radius: 5px;
border: 2px solid #d2d2d2; border: 2px solid #d2d2d2;
...@@ -8,47 +8,24 @@ ...@@ -8,47 +8,24 @@
width: 100%; width: 100%;
} }
.input::placeholder { .Container input::placeholder {
font-size: 15px; font-size: 15px;
} }
.input:focus { .Container input:focus {
outline: none; outline: none;
border: 2px solid rgb(189, 189, 189); border: 2px solid rgb(189, 189, 189);
} }
.strike {
text-decoration: line-through;
}
.error { .error {
color: red; color: red;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
padding: 10px; margin-top: 2px;
font-size: 13px; font-size: 13px;
} }
.inputError { .Container .inputError {
border: 1px solid red; border: 1px solid red;
}
.invisible {
padding-inline: 0px;
border: none;
font-size: 16px;
color: gray;
background-color: transparent;
box-shadow: none;
padding-block: 10px;
}
.invisible::placeholder {
font-size: 18px;
}
.invisible:focus {
outline: none;
border: none;
} }
\ No newline at end of file
import Item from "@/components/Top-Level/Item/Item"; import Item from "@/components/Top-Level/Item/Item";
import styles from "./list.module.css"; import styles from "./list.module.css";
interface ListItemProps { import { ItemMethods, TodoListItems } from "@/Types/todoTypes";
data: { interface ListItemProps extends ItemMethods {
id: number; data: TodoListItems[];
task: string;
isCompleted: boolean;
}[];
onClose: (id: number) => void;
updateTask: (id: number, task: string, isCompleted: boolean) => void;
} }
const ListItem: React.FC<ListItemProps> = ({ data, updateTask, onClose }) => { const ListItem: React.FC<ListItemProps> = ({ data, updateTask, onDelete }) => {
return ( return (
<div className={styles.list}> <div className={styles.list}>
{ {
...@@ -19,7 +14,7 @@ const ListItem: React.FC<ListItemProps> = ({ data, updateTask, onClose }) => { ...@@ -19,7 +14,7 @@ const ListItem: React.FC<ListItemProps> = ({ data, updateTask, onClose }) => {
key={item.id} key={item.id}
{...item} {...item}
updateTask={updateTask} updateTask={updateTask}
onClose={onClose} onDelete={onDelete}
/> />
) )
}) })
......
...@@ -17,22 +17,17 @@ type Story = StoryObj<typeof meta>; ...@@ -17,22 +17,17 @@ type Story = StoryObj<typeof meta>;
export const List_: Story = { export const List_: Story = {
args: { args: {
data: List_data, data: List_data,
onChange: fn(), onDelete: fn(),
onClose: fn(), updateTask: fn()
onComplete: fn()
} }
}; };
export const Todos: Story = { export const Todos: Story = {
args: { args: {
data: List_data, data: List_data,
onChange: fn(), onDelete: fn(),
onClose: fn(), updateTask: fn()
onComplete: fn()
}, },
// parameters: {
// layout: 'centered',
// },
render: (args) => ( render: (args) => (
<div style={{ <div style={{
display: 'flex', display: 'flex',
...@@ -49,7 +44,7 @@ export const Todos: Story = { ...@@ -49,7 +44,7 @@ export const Todos: Story = {
}}> }}>
<Heading count={args.data.length} /> <Heading count={args.data.length} />
<List {...args} /> <List {...args} />
<FormComponent handleSubmit={fn()} /> <FormComponent onPost={fn()} />
</div> </div>
</div> </div>
) )
......
...@@ -11,11 +11,3 @@ export interface ISocialLink { ...@@ -11,11 +11,3 @@ export interface ISocialLink {
url: string; url: string;
label?: string; label?: string;
} }
export interface TodoListItems {
id: number;
task: string;
isCompleted: boolean;
}
\ No newline at end of file
{ {
"tasks": [ "tasks": [
{ {
"id": 1, "task": "new todo",
"task": "clg",
"isCompleted": false
},
{
"id": 2,
"task": "new",
"isCompleted": true
},
{
"task": "jake",
"isCompleted": true, "isCompleted": true,
"id": 3 "id": 1
}, },
{ {
"task": "items", "task": "new element",
"isCompleted": false, "isCompleted": false,
"id": 5 "id": 2
}, },
{ {
"task": "another items", "task": "Nothing",
"isCompleted": false, "isCompleted": false,
"id": 6 "id": 3
} }
] ]
} }
\ No newline at end of file
...@@ -2,7 +2,6 @@ import { Axios } from "./Instance"; ...@@ -2,7 +2,6 @@ import { Axios } from "./Instance";
export default async function getall() { export default async function getall() {
try { try {
const res = await Axios.get(''); const res = await Axios.get('');
return await res.data return await res.data
} catch (error) { } catch (error) {
......
"use client" "use client"
import style from "./todoapp.module.css" import React from "react";
import { useState, useEffect } from "react"; import { useState, useEffect } from "react";
import style from "./todoapp.module.css"
import Heading from "@/components/base/Heading/Heading"; import Heading from "@/components/base/Heading/Heading";
import List from "@/components/layout/List/List"; import List from "@/components/layout/List/List";
import FormComponent from "@/components/Top-Level/Form/FormComponent"; import FormComponent from "@/components/Top-Level/Form/FormComponent";
import { TodoListItems } from "@/components/types"; import { TodoListItems } from "@/components/types";
import AddTask, { UpdateTask, DeleteTask } from "@/lib/Operation"; import AddTask, { UpdateTask, DeleteTask } from "@/lib/TodoOperations";
import getall from "@/lib/getall"; import getall from "@/lib/getall";
interface StateTodo { interface StateTodo {
data?: TodoListItems[], data?: TodoListItems[],
...@@ -52,45 +53,34 @@ const Todo = () => { ...@@ -52,45 +53,34 @@ const Todo = () => {
setrefresh(!refresh) setrefresh(!refresh)
} }
} }
const handleAdd = async (task: string) => { const handlePost = async (task: string) => {
const result = await AddTask(task) const result = await AddTask(task)
if (result) { if (result) {
setrefresh(!refresh) setrefresh(!refresh)
} }
} }
if (TodoList.isLoading) {
return (<Wrapper>
<div className={style.loading} />
</Wrapper>)
}
if (TodoList.isError) {
return (
<Wrapper>
<h2 className={style.notFound}>Something went wrong</h2>
</Wrapper>
)
}
return (
<Wrapper>
{
TodoList.data &&
(
<>
<Heading count={TodoList.data.length} />
{
TodoList.data.length !== 0 &&
<List data={TodoList.data} onClose={handleDelete} updateTask={UpdateTask} />
}
<FormComponent handleSubmit={handleAdd} />
</>
)
}
return (
<div className={style.container}>
<div className={style.todoWrapper}>
{TodoList.isLoading && <div className={style.loading} />}
{TodoList.isError && <h2 className={style.notFound}>Something went wrong</h2>}
{
!TodoList.isError && !TodoList.isLoading && TodoList.data &&
(
<React.Fragment>
<Heading count={TodoList.data.length} />
{
TodoList.data.length !== 0 &&
<List data={TodoList.data} onDelete={handleDelete} updateTask={UpdateTask} />
}
<FormComponent onPost={handlePost} />
</React.Fragment>
)
}
</div>
</div>
</Wrapper>
); );
} }
...@@ -100,17 +90,3 @@ export default Todo; ...@@ -100,17 +90,3 @@ export default Todo;
type WrapperProps = {
children: React.ReactNode;
}
const Wrapper: React.FC<WrapperProps> = ({ children }) => {
return (
<div className={style.container}>
<div className={style.todoWrapper}>
{children}
</div>
</div>
)
}
\ No newline at end of file
export const List_data = [ export const List_data = [
{ {
id: " 1", id: 1,
task: "Buy the Groceries", task: "Buy the Groceries",
isCompleted: true isCompleted: true
}, },
{ {
id: " 2", id: 2,
task: "Buy the food", task: "Buy the food",
isCompleted: false isCompleted: false
}, },
{ {
id: "3", id: 3,
task: "pay the rent", task: "pay the rent",
isCompleted: false isCompleted: false
}, },
{ {
id: " 4", id: 4,
task: "savings the money", task: "savings the money",
isCompleted: true isCompleted: true
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment