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

Solution #2682

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Solution #2682

wants to merge 2 commits into from

Conversation

save-v
Copy link

@save-v save-v commented Dec 13, 2024

const [todos, setTodos] = useState<Todo[]>([]);
const [isLoading, setIsLoading] = useState<boolean>(false);
const [query, setQuery] = useState<string>('');
const [selectedTodoId, setSelectedTodoId] = useState<number | null>(null);

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, то тоді дійсно треба визначити, який тип там має бути

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Хороша робота, вітаю тебе ))

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

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a 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';

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;

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';

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';

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)

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 => {

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.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a 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:

  1. Typographical Corrections: Ensure that the imports for CompletedStatus and SetStateCompletedStatus use the correct Latin 'C' instead of a Cyrillic 'С'. This is crucial to prevent runtime errors.

  2. Type Casting: Make sure that the value from event.target.value is correctly cast to the CompletedStatus type to avoid potential runtime errors.

  3. Destructuring Safety: In the TodoModal component, ensure that the todo object is always found before destructuring. Consider adding a check to handle cases where todo might be undefined.

  4. Code Clarity: Consider changing let flag = null; to const 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;

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';

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.

Comment on lines +20 to +21
onChange={event =>
setFilterStatus(event.target.value as CompletedStatus)

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;

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';

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.

Copy link

@BudnikOleksii BudnikOleksii left a 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);

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;

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 🎏

Comment on lines +25 to +27
if (filterStatus !== CompletedStatus.all) {
flag = filterStatus === CompletedStatus.completed ? true : false;
}

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);

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' }}>

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"

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',

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

Comment on lines +10 to +11
todos: Todo[];
selectedTodoId: number;

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;

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>>;

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants