Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes: Ran prettier, Label are connected to inputs for better , Pro… #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"trailingComma": "all",
"tabWidth": 2,
"singleQuote": true,
"jsxBracketSameLine": true,
"printWidth": 100,
"bracketSpacing": true
}
27,458 changes: 27,458 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
"eject": "react-scripts eject",
"format": "prettier --write src/**/*.{js,jsx,ts,tsx,css,md,json} --config ./.prettierrc",
"lint": "eslint src --ext .js,.jsx,.ts,.tsx",
"lint:fix": "eslint --fix src --ext .js,.jsx,.ts,.tsx"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
"react-app/jest",
"prettier"
]
},
"browserslist": {
Expand All @@ -47,6 +51,8 @@
]
},
"devDependencies": {
"@types/styled-components": "^5.1.26"
"@types/styled-components": "^5.1.26",
"eslint-config-prettier": "^8.8.0",
"prettier": "^2.8.7"
}
}
16 changes: 8 additions & 8 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import GlobalStyle from './global'
import GlobalStyle from './global';
import ContextProviders from './contextProviders';

import { BrowserRouter, Routes, Route } from 'react-router-dom';
Expand All @@ -9,20 +9,20 @@ import Home from './Pages/Home';
import CategoriePage from './Pages/Categorie';
import ProtectedRoute from './Routes/Route';


function App() {
return (
<ContextProviders>
<BrowserRouter>
<Routes>
<Route path="/" element={<ProtectedRoute priv={true}><Home/></ProtectedRoute>} />
<Route path="/login" element={<ProtectedRoute priv={false}><Login/></ProtectedRoute>} />
<Route path='/categorie/:name' element = {<ProtectedRoute priv={true}><CategoriePage/></ProtectedRoute>}></Route>
</Routes>
<Route index path="/login" element={<Login />} />
<Route element={<ProtectedRoute />}>
<Route path="/" element={<Home />} />
<Route path="/categorie/:name" element={<CategoriePage />} />
</Route>
</Routes>
</BrowserRouter>
<GlobalStyle/>
<GlobalStyle />
</ContextProviders>

);
}

Expand Down
131 changes: 62 additions & 69 deletions src/Components/AddModal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,73 +1,66 @@
import React, { useContext, useState } from "react";
import * as S from "./styles"
import { AddContext } from "../../Contexts/addContext";
import { AddType } from "../../Contexts/addType";
import { TaskListContext } from "../../Contexts/taskListContext";
import { TaskProps, TaskListType } from "../../Contexts/taskType";
import { CategoriesContext } from "../../Contexts/categoriesContext";
import { CategorieContextType } from "../../Contexts/categoriesType";
import { ActionMeta, InputActionMeta } from "react-select";
import Select from "react-select/dist/declarations/src/Select";


const AddModal:React.FC =()=>{
const{ addTask } = useContext(TaskListContext) as TaskListType;
const{categList} = useContext(CategoriesContext) as CategorieContextType;
const{ setShowAdd,} = useContext(AddContext) as AddType;


const [taskName, setTaskName ]= useState("");
const [taskCat, setTaskCat] = useState(categList.findIndex((cat)=>cat.name == "None"));

function handleTyping(event: React.ChangeEvent<HTMLInputElement>){
setTaskName(event.target.value);
};

function handleCancel(){
setShowAdd(false);
import React, { useContext, useState } from 'react';
import * as S from './styles';
import { AddContext } from '../../Contexts/addContext';
import { AddType } from '../../Contexts/addType';
import { TaskListContext } from '../../Contexts/taskListContext';
import { TaskProps, TaskListType } from '../../Contexts/taskType';
import { CategoriesContext } from '../../Contexts/categoriesContext';
import { CategorieContextType } from '../../Contexts/categoriesType';

const AddModal: React.FC = () => {
const { addTask } = useContext(TaskListContext) as TaskListType;
const { categList } = useContext(CategoriesContext) as CategorieContextType;
const { setShowAdd } = useContext(AddContext) as AddType;

const [taskName, setTaskName] = useState('');
const [taskCat, setTaskCat] = useState(categList.findIndex((cat) => cat.name === 'None'));

function handleTyping(event: React.ChangeEvent<HTMLInputElement>) {
setTaskName(event.target.value);
}

function handleCancel() {
setShowAdd(false);
}

function handleAdd() {
const newTask: TaskProps = {
id: Math.random(),
title: taskName,
categorie: categList[taskCat].name,
color: categList[taskCat].color,
done: false,
};

function handleAdd(){
const newTask:TaskProps ={
id: Math.random(),
title: taskName,
categorie: categList[taskCat].name,
color: categList[taskCat].color,
done: false,
}

setShowAdd(false);

addTask(newTask);

}

var e= document.getElementById("select") as HTMLSelectElement;

function handleChange(){
setTaskCat(Number(e.options[(e.selectedIndex)].value));
}





return(
<S.Background>
<S.Container>
<S.Text>Insert name</S.Text>
<S.TitleInput placeholder="Task name" onChange={handleTyping} value={taskName}/>
<S.Text>Select a categorie</S.Text>
<S.Select id="select" onChange={handleChange}>
{categList.map((cat)=><option value={cat.id}>{cat.name}</option>)}
</S.Select>
<S.Buttons>
<S.CancelButton onClick={handleCancel} >Cancel</S.CancelButton>
<S.DeletButton onClick={handleAdd}>Add</S.DeletButton>
</S.Buttons>
</S.Container>
</S.Background>
)
setShowAdd(false);

addTask(newTask);
}

var e = document.getElementById('select') as HTMLSelectElement;

function handleChange() {
setTaskCat(Number(e.options[e.selectedIndex].value));
}

return (
<S.Background>
<S.Container>
<S.Text>Insert name</S.Text>
<S.TitleInput placeholder="Task name" onChange={handleTyping} value={taskName} />
<S.Text>Select a categorie</S.Text>
<S.Select id="select" onChange={handleChange}>
{categList.map((cat) => (
<option value={cat.id}>{cat.name}</option>
))}
</S.Select>
<S.Buttons>
<S.CancelButton onClick={handleCancel}>Cancel</S.CancelButton>
<S.DeletButton onClick={handleAdd}>Add</S.DeletButton>
</S.Buttons>
</S.Container>
</S.Background>
);
};

export default AddModal;
export default AddModal;
Loading