Skip to content

Commit

Permalink
fix: lint and added README modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Molaryy committed Nov 25, 2023
1 parent 47fccdc commit f62b881
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 77 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ More than a normal promodoro app.
## Features :
### Done:
- Choice of your own work/pause time, it's set to 25 minutes to work and 5 minutes break time by default
- Create a todo
- Create and remove a todo
- Database CRUD operations for the todos

### In progress:
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Navbar from "./components/Navbar.tsx";
import TimerFormHandler from "./components/Form/TimerFormHandler.tsx";
import ListTodosContainer from "./components/Todos/ListTodosContainer.tsx";
import Navbar from './components/Navbar.tsx';
import TimerFormHandler from './components/Form/TimerFormHandler.tsx';
import ListTodosContainer from './components/Todos/ListTodosContainer.tsx';

function App() {

Expand Down
21 changes: 11 additions & 10 deletions frontend/src/components/Todos/GetTodo.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import '../../styles/ListTodos.scss';
import { Dispatch, FormEvent, SetStateAction, useState } from "react";
import axios from "axios";
import { Dispatch, FormEvent, SetStateAction, useState } from 'react';
import axios from 'axios';
import { ReceivedTodoApiType } from '../../types.ts';

const placeHolderRandom = () => {
const array = [
Expand Down Expand Up @@ -46,26 +47,26 @@ const GetTodo = (
}: {
todosLength: number;
setTodosLength: Dispatch<SetStateAction<number>>;
todos: any;
setTodos: Dispatch<SetStateAction<any>>
todos: ReceivedTodoApiType | undefined;
setTodos: Dispatch<SetStateAction<ReceivedTodoApiType | undefined>>
}
) => {
const [inputValue, setInputValue] = useState('');

const onSubmit = async (event: FormEvent) => {
event.preventDefault();

if (inputValue === '' || inputValue === undefined) {
if (inputValue === '' || inputValue === undefined || !todos) {
setInputValue('');
return;
}
const newTodo = {
"title": inputValue,
"description": "",
"startDate": "",
"endDate": ""
'title': inputValue,
'description': '',
'startDate': '',
'endDate': ''
};
const createdTodo = await axios.post("http://localhost:8080/todo", newTodo).then(res => res.data);
const createdTodo = await axios.post('http://localhost:8080/todo', newTodo).then(res => res.data);
setTodosLength(todosLength + 1);
const updatedTodos = { ...todos };
updatedTodos.todo = [...updatedTodos.todo, createdTodo.created];
Expand Down
67 changes: 5 additions & 62 deletions frontend/src/components/Todos/ListTodosContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import '../../styles/ListTodos.scss';
import { Dispatch, SetStateAction, useEffect, useState } from 'react';
import axios from "axios";
import GetTodo from "./GetTodo.tsx";
import { TodoType, ReceivedTodoApiType } from "../../types.ts";
import axios from 'axios';
import GetTodo from './GetTodo.tsx';
import { ReceivedTodoApiType } from '../../types.ts';
import TodoUnity from './TodoUnity.tsx';

const todoValues = {
pixelGap: 15,
Expand Down Expand Up @@ -32,65 +33,6 @@ const TodosListHeader = ({
);
};

const TodoUnity = (
{
settingsOpened,
index,
todo,
hideList,
openTodoSettings,
todos,
setTodos,
setTodosLength,
todosLength
}:{
settingsOpened: boolean[];
index: number;
todo: any;
hideList: boolean;
openTodoSettings: any;
todos: any;
setTodos: Dispatch<SetStateAction<any>>
setTodosLength: Dispatch<SetStateAction<number>>
todosLength: number
}) => {
const [deleteButtonIsClicked, setDeleteButtonIsClicked] = useState(false);

const removeTodo = async () => {
await axios.delete(`http://localhost:8080/todo/${todo.id}`);
setTodosLength(todosLength - 1)
todos.todo.forEach((t: TodoType) => {
console.log(t.id);
})
todos.todo = todos.todo.filter((t: TodoType) => t.id !== todo.id);
setTodos(todos);
}

return (
<div
className={'todo-text-element'}
style={{
overflow: 'hidden',
height: todo.title.length >= 50 ? '75px' : settingsOpened[index] ? '150px' : '50px',
display: hideList ? 'none' : '',
}}
onClick={() => {
console.log(deleteButtonIsClicked);
if (!deleteButtonIsClicked) {
openTodoSettings(index)
}
}}
>
<div
className={"todo-delete-button"}
onMouseOver={() => setDeleteButtonIsClicked(true)}
onClick={removeTodo}
onMouseLeave={() => setDeleteButtonIsClicked(false)}>x</div>
<p>{todo.title}</p>
</div>
)
};

const ListTodosContainer = () => {
const [heightBlurBg, setHeightBlurBg] = useState<number>(0);
const [hideList, setHideList] = useState<boolean>(false);
Expand Down Expand Up @@ -156,6 +98,7 @@ const ListTodosContainer = () => {
};
expandBlurBg();
}, [heightBlurBg, todosLength, todoClickedCount]);

const openTodoSettings = (key: number) => {
settingsOpened[key] = !settingsOpened[key];
setSettingsOpened(settingsOpened);
Expand Down
64 changes: 64 additions & 0 deletions frontend/src/components/Todos/TodoUnity.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { Dispatch, SetStateAction, useState } from 'react';
import axios from 'axios';
import { ReceivedTodoApiType, TodoType } from '../../types.ts';

const TodoUnity = (
{
settingsOpened,
index,
todo,
hideList,
openTodoSettings,
todos,
setTodos,
setTodosLength,
todosLength
}:{
settingsOpened: boolean[];
index: number;
todo: TodoType;
hideList: boolean;
openTodoSettings: (index: number) => void;
todos: ReceivedTodoApiType;
setTodos: Dispatch<SetStateAction<ReceivedTodoApiType | undefined>>
setTodosLength: Dispatch<SetStateAction<number>>
todosLength: number
}) => {
const [deleteButtonIsClicked, setDeleteButtonIsClicked] = useState(false);

const removeTodo = async () => {
await axios.delete(`http://localhost:8080/todo/${todo.id}`);
setTodosLength(todosLength - 1)
todos.todo.forEach((t: TodoType) => {
console.log(t.id);
})
todos.todo = todos.todo.filter((t: TodoType) => t.id !== todo.id);
setTodos(todos);
}

return (
<div
className={'todo-text-element'}
style={{
overflow: 'hidden',
height: todo.title.length >= 50 ? '75px' : settingsOpened[index] ? '150px' : '50px',
display: hideList ? 'none' : '',
}}
onClick={() => {
console.log(deleteButtonIsClicked);
if (!deleteButtonIsClicked) {
openTodoSettings(index)
}
}}
>
<div
className={'todo-delete-button'}
onMouseOver={() => setDeleteButtonIsClicked(true)}
onClick={removeTodo}
onMouseLeave={() => setDeleteButtonIsClicked(false)}>x</div>
<p>{todo.title}</p>
</div>
)
};

export default TodoUnity;
2 changes: 1 addition & 1 deletion frontend/src/lib/todos.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import axios from "axios";
import axios from 'axios';

class Todos {
public async getTodos() {
Expand Down

0 comments on commit f62b881

Please sign in to comment.