-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
commited unworking code #804
Open
OPTIMISTIXX
wants to merge
13
commits into
mate-academy:master
Choose a base branch
from
OPTIMISTIXX:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2cd1e0c
commited unworking code
OPTIMISTIXX b33eb2e
.
OPTIMISTIXX 1c01159
m
OPTIMISTIXX 102ba00
send my code for checking
OPTIMISTIXX 16385a2
update my reducer
OPTIMISTIXX 662beda
created todo app
OPTIMISTIXX 0a8ea20
send my code for checking mistake
OPTIMISTIXX 043ed29
fixed my todo-app
OPTIMISTIXX 669bbeb
shortened my code
OPTIMISTIXX 9403f13
refactored my code
OPTIMISTIXX 4aff763
remove dot inside button tag
OPTIMISTIXX f4e3ac8
shortened Main.tsx
OPTIMISTIXX 7aff48a
fixed small bugs
OPTIMISTIXX File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,18 @@ | ||
/* eslint-disable jsx-a11y/control-has-associated-label */ | ||
import React from 'react'; | ||
import { Footer } from './components/Footer'; | ||
import { Header } from './components/Header'; | ||
import { Main } from './components/Main'; | ||
import { Provider } from './contexts/TodosContext'; | ||
|
||
export const App: React.FC = () => { | ||
return ( | ||
<div className="todoapp"> | ||
<header className="header"> | ||
<h1>todos</h1> | ||
|
||
<form> | ||
<input | ||
type="text" | ||
data-cy="createTodo" | ||
className="new-todo" | ||
placeholder="What needs to be done?" | ||
/> | ||
</form> | ||
</header> | ||
|
||
<section className="main"> | ||
<input | ||
type="checkbox" | ||
id="toggle-all" | ||
className="toggle-all" | ||
data-cy="toggleAll" | ||
/> | ||
<label htmlFor="toggle-all">Mark all as complete</label> | ||
|
||
<ul className="todo-list" data-cy="todoList"> | ||
<li> | ||
<div className="view"> | ||
<input type="checkbox" className="toggle" id="toggle-view" /> | ||
<label htmlFor="toggle-view">asdfghj</label> | ||
<button type="button" className="destroy" data-cy="deleteTodo" /> | ||
</div> | ||
<input type="text" className="edit" /> | ||
</li> | ||
|
||
<li className="completed"> | ||
<div className="view"> | ||
<input type="checkbox" className="toggle" id="toggle-completed" /> | ||
<label htmlFor="toggle-completed">qwertyuio</label> | ||
<button type="button" className="destroy" data-cy="deleteTodo" /> | ||
</div> | ||
<input type="text" className="edit" /> | ||
</li> | ||
|
||
<li className="editing"> | ||
<div className="view"> | ||
<input type="checkbox" className="toggle" id="toggle-editing" /> | ||
<label htmlFor="toggle-editing">zxcvbnm</label> | ||
<button type="button" className="destroy" data-cy="deleteTodo" /> | ||
</div> | ||
<input type="text" className="edit" /> | ||
</li> | ||
|
||
<li> | ||
<div className="view"> | ||
<input type="checkbox" className="toggle" id="toggle-view2" /> | ||
<label htmlFor="toggle-view2">1234567890</label> | ||
<button type="button" className="destroy" data-cy="deleteTodo" /> | ||
</div> | ||
<input type="text" className="edit" /> | ||
</li> | ||
</ul> | ||
</section> | ||
|
||
<footer className="footer"> | ||
<span className="todo-count" data-cy="todosCounter"> | ||
3 items left | ||
</span> | ||
|
||
<ul className="filters"> | ||
<li> | ||
<a href="#/" className="selected">All</a> | ||
</li> | ||
|
||
<li> | ||
<a href="#/active">Active</a> | ||
</li> | ||
|
||
<li> | ||
<a href="#/completed">Completed</a> | ||
</li> | ||
</ul> | ||
|
||
<button type="button" className="clear-completed"> | ||
Clear completed | ||
</button> | ||
</footer> | ||
</div> | ||
<Provider> | ||
<div className="todoapp"> | ||
<Header /> | ||
<Main /> | ||
<Footer /> | ||
</div> | ||
</Provider> | ||
); | ||
}; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from 'react'; | ||
import { TodosContext } from '../contexts/TodosContext'; | ||
|
||
export const Footer = () => { | ||
const { todoList } = React.useContext(TodosContext); | ||
|
||
return ( | ||
<footer className="footer"> | ||
<span className="todo-count" data-cy="todosCounter"> | ||
{todoList.length} | ||
<span> items left</span> | ||
</span> | ||
|
||
<ul className="filters"> | ||
<li> | ||
<a href="#/" className="selected">All</a> | ||
</li> | ||
|
||
<li> | ||
<a href="#/active">Active</a> | ||
</li> | ||
|
||
<li> | ||
<a href="#/completed">Completed</a> | ||
</li> | ||
</ul> | ||
|
||
<button type="button" className="clear-completed"> | ||
Clear completed | ||
</button> | ||
</footer> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React, { useState } from 'react'; | ||
import { TodosContext } from '../contexts/TodosContext'; | ||
|
||
export const Header = () => { | ||
const [input, setInput] = useState(''); | ||
const { addItem } = React.useContext(TodosContext); | ||
|
||
const handleSubmit = () => { | ||
addItem(input); | ||
}; | ||
|
||
return ( | ||
<header className="header"> | ||
<h1>todos</h1> | ||
|
||
<form onSubmit={handleSubmit}> | ||
<input | ||
type="text" | ||
data-cy="createTodo" | ||
className="new-todo" | ||
placeholder="What needs to be done?" | ||
value={input} | ||
onChange={e => setInput(e.target.value)} | ||
/> | ||
</form> | ||
</header> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Todos } from './Todos'; | ||
|
||
export const Main = () => { | ||
return ( | ||
<section className="main"> | ||
<input | ||
type="checkbox" | ||
id="toggle-all" | ||
className="toggle-all" | ||
data-cy="toggleAll" | ||
/> | ||
<label htmlFor="toggle-all">Mark all as complete</label> | ||
<Todos /> | ||
</section> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react'; | ||
import { TodosContext } from '../contexts/TodosContext'; | ||
|
||
export const Todos = () => { | ||
const { todoList, | ||
removeItem, | ||
markAsCompleted | ||
} = React.useContext(TodosContext); | ||
|
||
return ( | ||
<ul className="todo-list" data-cy="todoList"> | ||
{todoList.map((todoItem) => ( | ||
<li | ||
className={`item ${todoItem.completed ? 'completed' : ''}`} | ||
key={todoItem.id} | ||
> | ||
<div className="view"> | ||
<input type="checkbox" className="toggle" id="toggle-completed" /> | ||
<label htmlFor="toggle-completed">{todoItem}</label> | ||
<button type="button" className="destroy" data-cy="deleteTodo"> | ||
. | ||
</button> | ||
</div> | ||
<input type="text" className="edit" /> | ||
</li> | ||
))} | ||
</ul> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import React, { useReducer } from 'react'; | ||
|
||
export type State = { | ||
todoList: { id: number; completed: boolean; title: string }[]; | ||
}; | ||
|
||
type Props = { | ||
children: React.ReactNode; | ||
}; | ||
|
||
type Action = | ||
{ type: 'ADD_TODO_ITEM', todoItemTitle: string } | | ||
{ type: 'REMOVE_TODO_ITEM', todoItemId: number } | | ||
{ type: 'TOGGLE_COMPLETED', todoItemId: number }; | ||
|
||
export type AddItem = { | ||
(todoItemTitle: string): void | ||
}; | ||
|
||
const initialState: State = { | ||
todoList: [], | ||
}; | ||
|
||
export const reducer = (state: State, action: Action) => { | ||
switch (action.type) { | ||
case 'ADD_TODO_ITEM': | ||
return { | ||
todoList: [ | ||
...state.todoList, | ||
{ | ||
id: new Date().valueOf(), | ||
completed: false, | ||
title: action.todoItemTitle, | ||
}, | ||
], | ||
}; | ||
case 'REMOVE_TODO_ITEM': { | ||
const filteredItems = state.todoList.filter((todoItem) => { | ||
return todoItem.id !== action.todoItemId; | ||
}); | ||
|
||
return { | ||
todoList: filteredItems, | ||
}; | ||
} | ||
|
||
case 'TOGGLE_COMPLETED': { | ||
const updatedTodoList = state.todoList.map((todoItem) => { | ||
return todoItem.id === action.todoItemId | ||
? { ...todoItem, completed: !todoItem.completed } | ||
: todoItem; | ||
}); | ||
|
||
return { todoList: updatedTodoList }; | ||
} | ||
|
||
default: return state; | ||
} | ||
}; | ||
|
||
export const TodosContext = React.createContext(initialState); | ||
|
||
export const Provider: React.FC<Props> = ({ children }) => { | ||
const [state, dispatch] = useReducer(reducer, initialState); | ||
|
||
const value = { | ||
todoList: state.todoList, | ||
addItem: (todoItemTitle: string) => { | ||
dispatch({ type: 'ADD_TODO_ITEM', todoItemTitle }); | ||
}, | ||
removeItem: ((todoItemId: number) => { | ||
dispatch({ type: 'REMOVE_TODO_ITEM', todoItemId }); | ||
}), | ||
markAsCompleted: ((todoItemId: number) => { | ||
dispatch({ type: 'TOGGLE_COMPLETED', todoItemId }); | ||
}), | ||
}; | ||
|
||
return ( | ||
<TodosContext.Provider value={value}> | ||
{children} | ||
</TodosContext.Provider> | ||
); | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
u don't use these 2 functions in this component