-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Solution #2682
base: master
Are you sure you want to change the base?
Solution #2682
Conversation
const [todos, setTodos] = useState<Todo[]>([]); | ||
const [isLoading, setIsLoading] = useState<boolean>(false); | ||
const [query, setQuery] = useState<string>(''); | ||
const [selectedTodoId, setSelectedTodoId] = useState<number | null>(null); |
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.
Якщо ми вказуємо конкретне значення в useState, то можно явно не прописувати його тип, він визначиться автоматично, наприклад,
const [query, setQuery] = useState('');
Він сам визначає, що це буде рядок.
Але якщо ми в useState прописуємо null, то тоді дійсно треба визначити, який тип там має бути
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.
Хороша робота, вітаю тебе ))
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.
Якщо ми вказуємо конкретне значення в useState, то можно явно не прописувати його тип, він визначиться автоматично, наприклад,
const [query, setQuery] = useState('');
Він сам визначає, що це буде рядок. Але якщо ми в useState прописуємо null, то тоді дійсно треба визначити, який тип там має бути
Good point
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.
Thank you for your hard work on this project! There are a few critical issues that need to be addressed before we can approve the pull request. The most significant issue is the consistent typo in the СompletedStatus
and SetStateСompletedStatus
imports, where a Cyrillic 'С' is used instead of the Latin 'C'. This could lead to runtime errors and should be corrected for proper functionality. Additionally, ensure that the value from event.target.value
is correctly cast to the CompletedStatus
type to prevent potential runtime errors. Lastly, consider changing the let flag = null;
to const
for better code clarity. Once these issues are resolved, your code will be in great shape! Keep up the great work! 😊
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review
button in the Reviewers tab.
src/App.tsx
Outdated
@@ -8,7 +8,39 @@ import { TodoFilter } from './components/TodoFilter'; | |||
import { TodoModal } from './components/TodoModal'; | |||
import { Loader } from './components/Loader'; | |||
|
|||
import { Todo } from './types/Todo'; | |||
import { getTodos } from './api'; | |||
import { СompletedStatus } from './types/СompletedStatus'; |
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.
There seems to be a typo in the import statement for СompletedStatus
. Ensure that the file name and path are correct. The character 'С' might be a Cyrillic letter instead of the Latin 'C'.
СompletedStatus.all, | ||
); | ||
|
||
let flag = null; |
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.
The variable flag
is declared with let
but is not reassigned. Consider using const
instead for better code clarity and to prevent accidental reassignment.
<span className="icon is-left"> | ||
<i className="fas fa-magnifying-glass" /> | ||
</span> | ||
import { SetStateСompletedStatus } from '../../types/SetStateСompletedStatus'; |
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.
There seems to be a typo in the import statement for SetStateСompletedStatus
. Ensure that the file name and path are correct. The character 'С' might be a Cyrillic letter instead of the Latin 'C'.
<i className="fas fa-magnifying-glass" /> | ||
</span> | ||
import { SetStateСompletedStatus } from '../../types/SetStateСompletedStatus'; | ||
import { СompletedStatus } from '../../types/СompletedStatus'; |
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.
There seems to be a typo in the import statement for СompletedStatus
. Ensure that the file name and path are correct. The character 'С' might be a Cyrillic letter instead of the Latin 'C'.
<span className="select"> | ||
<select | ||
onChange={event => | ||
setFilterStatus(event.target.value as СompletedStatus) |
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.
Ensure that the value from event.target.value
is correctly cast to the СompletedStatus
type. This is important to prevent runtime errors if the value does not match the expected enum type.
} | ||
|
||
useEffect(() => { | ||
getUser(userId).then(respons => { |
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.
There is a typo in the variable name respons
. It should be response
to correctly reflect the data being received from the getUser
function.
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.
Review Summary
Great job on addressing the previous issues! Your code is mostly well-structured and follows React best practices. Here are some important points to consider:
-
Typographical Corrections: Ensure that the imports for
CompletedStatus
andSetStateCompletedStatus
use the correct Latin 'C' instead of a Cyrillic 'С'. This is crucial to prevent runtime errors. -
Type Casting: Make sure that the value from
event.target.value
is correctly cast to theCompletedStatus
type to avoid potential runtime errors. -
Destructuring Safety: In the
TodoModal
component, ensure that thetodo
object is always found before destructuring. Consider adding a check to handle cases wheretodo
might beundefined
. -
Code Clarity: Consider changing
let flag = null;
toconst flag = null;
for better code clarity and to prevent unintended reassignment.
You've made significant progress, and your solution meets the task requirements. Keep up the good work and continue to refine your skills by addressing these issues in future projects. This decision is made to help you move forward with your learning journey. 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
CompletedStatus.all, | ||
); | ||
|
||
let flag = null; |
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.
Consider changing let flag = null;
to const flag = null;
for better code clarity and to prevent unintended reassignment.
<span className="icon is-left"> | ||
<i className="fas fa-magnifying-glass" /> | ||
</span> | ||
import { SetStateCompletedStatus } from '../../types/SetStateCompletedStatus'; |
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.
Ensure that the import SetStateCompletedStatus
uses the correct Latin 'C' instead of a Cyrillic 'С'. This could lead to runtime errors if not corrected.
onChange={event => | ||
setFilterStatus(event.target.value as CompletedStatus) |
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.
Ensure that the value from event.target.value
is correctly cast to the CompletedStatus
type. This is crucial to prevent potential runtime errors.
const [isLoading, setIsLoading] = useState<boolean>(true); | ||
const [user, setUser] = useState<User | null>(null); | ||
const todo = todos.find(innertodo => innertodo.id === selectedTodoId); | ||
const { id, title, userId, completed } = todo as Todo; |
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.
Ensure that the todo
object is always found before destructuring. Consider adding a check to handle cases where todo
might be undefined
to prevent potential runtime errors.
@@ -0,0 +1,4 @@ | |||
import { CompletedStatus } from './CompletedStatus'; |
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.
Ensure that the import CompletedStatus
uses the correct Latin 'C' instead of a Cyrillic 'С'. This could lead to runtime errors if not corrected.
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.
Good work 👍
Let's improve your solution slightly
const [todos, setTodos] = useState<Todo[]>([]); | ||
const [isLoading, setIsLoading] = useState<boolean>(false); | ||
const [query, setQuery] = useState<string>(''); | ||
const [selectedTodoId, setSelectedTodoId] = useState<number | null>(null); |
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.
Якщо ми вказуємо конкретне значення в useState, то можно явно не прописувати його тип, він визначиться автоматично, наприклад,
const [query, setQuery] = useState('');
Він сам визначає, що це буде рядок. Але якщо ми в useState прописуємо null, то тоді дійсно треба визначити, який тип там має бути
Good point
CompletedStatus.all, | ||
); | ||
|
||
let flag = null; |
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.
What flag is it? I hope it's Ukrainian 🎏
if (filterStatus !== CompletedStatus.all) { | ||
flag = filterStatus === CompletedStatus.completed ? true : false; | ||
} |
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.
This logic isn't obvious. It's better to create a function that incapsulates filter logic so you don't need to think about it in the component
setIsLoading(true); | ||
getTodos().then(response => { | ||
setTodos(response); | ||
setIsLoading(false); |
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.
You should remove the loading state in case of an error as well. In your case if an error occurs a user will see an infinite loader
</span> | ||
|
||
{query && ( | ||
<span className="icon is-right " style={{ pointerEvents: 'all' }}> |
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.
Avoid inline styles, use classes instead
return ( | ||
<tr | ||
key={id} | ||
data-cy="todo" |
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.
Create a todo component
<i | ||
className={cN( | ||
'far', | ||
selectedTodoId !== id ? 'fa-eye' : 'fa-eye-slash', |
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.
You compare selectedTodoId !== id
twice, create a variable
todos: Todo[]; | ||
selectedTodoId: number; |
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.
Just pass a selectedTodo
instead
const [isLoading, setIsLoading] = useState<boolean>(true); | ||
const [user, setUser] = useState<User | null>(null); | ||
const todo = todos.find(innertodo => innertodo.id === selectedTodoId); | ||
const { id, title, userId, completed } = todo as Todo; |
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.
Avoid using as
import { CompletedStatus } from './CompletedStatus'; | ||
import { Dispatch, SetStateAction } from 'react'; | ||
|
||
export type SetStateCompletedStatus = Dispatch<SetStateAction<CompletedStatus>>; |
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.
No need to create a type for this if you use it only once
https://save-v.github.io/react_dynamic-list-of-todos/