From 5e9607170b252d35e9ea04e76bd5c75ce415f2f4 Mon Sep 17 00:00:00 2001 From: Jithin7777 <133039735+Jithin7777@users.noreply.github.com> Date: Wed, 12 Mar 2025 12:03:36 +0530 Subject: [PATCH] feature1 --- src/App.js | 249 +++++++++++------------------------------------------ 1 file changed, 51 insertions(+), 198 deletions(-) diff --git a/src/App.js b/src/App.js index e7c05b5..b108ed9 100644 --- a/src/App.js +++ b/src/App.js @@ -1,199 +1,52 @@ -import { - Button, - Container, - Text, - Title, - Modal, - TextInput, - Group, - Card, - ActionIcon, - Code, -} from '@mantine/core'; -import { useState, useRef, useEffect } from 'react'; -import { MoonStars, Sun, Trash } from 'tabler-icons-react'; - -import { - MantineProvider, - ColorSchemeProvider, - ColorScheme, -} from '@mantine/core'; -import { useColorScheme } from '@mantine/hooks'; -import { useHotkeys, useLocalStorage } from '@mantine/hooks'; - -export default function App() { - const [tasks, setTasks] = useState([]); - const [opened, setOpened] = useState(false); - - const preferredColorScheme = useColorScheme(); - const [colorScheme, setColorScheme] = useLocalStorage({ - key: 'mantine-color-scheme', - defaultValue: 'light', - getInitialValueInEffect: true, - }); - const toggleColorScheme = value => - setColorScheme(value || (colorScheme === 'dark' ? 'light' : 'dark')); - - useHotkeys([['mod+J', () => toggleColorScheme()]]); - - const taskTitle = useRef(''); - const taskSummary = useRef(''); - - function createTask() { - setTasks([ - ...tasks, - { - title: taskTitle.current.value, - summary: taskSummary.current.value, - }, - ]); - - saveTasks([ - ...tasks, - { - title: taskTitle.current.value, - summary: taskSummary.current.value, - }, - ]); - } - - function deleteTask(index) { - var clonedTasks = [...tasks]; - - clonedTasks.splice(index, 1); - - setTasks(clonedTasks); - - saveTasks([...clonedTasks]); - } - - function loadTasks() { - let loadedTasks = localStorage.getItem('tasks'); - - let tasks = JSON.parse(loadedTasks); - - if (tasks) { - setTasks(tasks); - } - } - - function saveTasks(tasks) { - localStorage.setItem('tasks', JSON.stringify(tasks)); - } - - useEffect(() => { - loadTasks(); - }, []); - - return ( - - -
- { - setOpened(false); - }} - centered> - - - - - - - - - - ({ - fontFamily: `Greycliff CF, ${theme.fontFamily}`, - fontWeight: 900, - })}> - My Tasks - - toggleColorScheme()} - size='lg'> - {colorScheme === 'dark' ? ( - - ) : ( - - )} - - - {tasks.length > 0 ? ( - tasks.map((task, index) => { - if (task.title) { - return ( - - - {task.title} - { - deleteTask(index); - }} - color={'red'} - variant={'transparent'}> - - - - - {task.summary - ? task.summary - : 'No summary was provided for this task'} - - - ); - } - }) - ) : ( - - You have no tasks - - )} - - -
-
-
- ); +import React, { useState } from "react"; + +function App() { + // State to manage tasks + const [tasks, setTasks] = useState([]); + const [newTask, setNewTask] = useState(""); + + // Add task function + const addTask = () => { + if (newTask.trim() === "") return; + setTasks([...tasks, newTask]); + setNewTask(""); + }; + + // Remove task function + const removeTask = (index) => { + const updatedTasks = tasks.filter((_, i) => i !== index); + setTasks(updatedTasks); + }; + + return ( +
+

To-Do List

+ + {/* Input & Add Button */} +
+ setNewTask(e.target.value)} + /> + +
+ + {/* Task List */} + +
+ ); } + +export default App;