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

task solution 01 #1415

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

Conversation

OlhaLishenko
Copy link

No description provided.

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

Hey there! 👋 Thanks for the submission! There are a couple of things we need to address before merging. The href attribute is hardcoded to #tab-1, but it should be dynamically set to #tab-id for each tab. Also, comparing objects directly ( activeTab === tab) can lead to issues. The checklist suggests comparing objects using their unique identifiers instead. Comparing by id would be more reliable. Keep up the great work! 💪


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

src/App.jsx Outdated
<div className="section">
<h1 className="title">Selected tab is Tab 1</h1>
export const App = () => {
const [activeTab, setActiveTab] = useState(tabs[0]);

Choose a reason for hiding this comment

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

It's good that you're initializing the activeTab state with the first tab. However, comparing objects directly (as you might be doing in the TabElement component) can lead to issues. The checklist suggests comparing objects using their unique identifiers instead. Please, make sure you compare tabs by id instead of the whole object.

GOOD EXAMPLE:
if (cat.id === selectedCat.id) {

{tabs.map(tab => (
<li
className={cn({
'is-active': activeTab === tab,

Choose a reason for hiding this comment

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

Comparing objects directly ( activeTab === tab) can lead to issues. The checklist suggests comparing objects using their unique identifiers instead. Comparing by id would be more reliable.

GOOD EXAMPLE:
if (cat.id === selectedCat.id) {

data-cy="Tab"
key={tab.id}
>
<a href="#tab-1" data-cy="TabLink" onClick={() => setActiveTab(tab)}>

Choose a reason for hiding this comment

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

The href attribute is hardcoded to #tab-1. According to the task description, it should be dynamically set to #tab-id for each tab.

  1. Add a link with data-cy="TabLink" and a href to #tab-id inside every <li> (see the markup).

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

Okay, here's the review decision. I'm approving this pull request so you can move forward, but please pay close attention to the following feedback to improve your code. Remember, the goal is to learn and build robust applications!

Here's a breakdown of the key points:

  • href Attribute in TabElement.jsx: The href attribute needs to be dynamically set to #tab-id for each tab. Currently, it appears to be hardcoded based on activeTabId. It should be: href={#${tab.id}}. This is important for proper navigation and tab selection.

  • Object Comparison in TabElement.jsx: Avoid direct object comparison (tab === activeTabId). This can be unreliable in JavaScript/React due to how object references work. Instead, compare the unique identifiers (IDs) of the objects. For example: tab.id === activeTabId.id. This is crucial for accurate tab activation logic.

    GOOD EXAMPLE:
    ```tsx
    if (cat.id === selectedCat.id) {
    
  • onTabSelected Function Call: The onTabSelected function should only be called when the user selects a non-active tab. Add a condition to check if the tab is already active before calling the function. This aligns with the task description's requirements and prevents unnecessary state updates.

  • Initialization of activeTabId in App.jsx: Initializing the activeTabId state variable with the id of the first tab can prevent potential errors (like trying to access .title on an undefined value) when the component initially renders. This ensures a smoother user experience and avoids unexpected crashes.

While these points need attention, your code is generally well-structured. Addressing these issues will make your application more robust and easier to maintain. Keep up the good work!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

<div className="section">
<h1 className="title">Selected tab is Tab 1</h1>
export const App = () => {
const [activeTabId, setactiveTabId] = useState('');

Choose a reason for hiding this comment

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

It's a good practice to initialize the activeTabId state variable with the id of the first tab to prevent the title from being undefined initially. This will ensure that activeTabId.title does not cause an error when the component first renders.

{tabs.map(tab => (
<li
className={cn({
'is-active': tab === activeTabId,

Choose a reason for hiding this comment

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

To avoid potential bugs, you should compare objects using their unique identifiers (id). The checklist suggests this approach.

GOOD EXAMPLE:
```tsx
if (cat.id === selectedCat.id) {

key={tab.id}
>
<a
href={`#${activeTabId.id}`}

Choose a reason for hiding this comment

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

The href attribute should be dynamically set to #tab-id for each tab, not the active tab's ID. This is a requirement from task description.

It should be: href={#${tab.id}}

<a
href={`#${activeTabId.id}`}
data-cy="TabLink"
onClick={() => onTabSelected(tab)}

Choose a reason for hiding this comment

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

Call onTabSelected only when the user selects a non-active tab. This is a requirement from task description. Add a condition to check if the tab is already active before calling onTabSelected.

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.

2 participants