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

#NEED HELP #5

Open
eliasbnk opened this issue Jun 2, 2021 · 2 comments
Open

#NEED HELP #5

eliasbnk opened this issue Jun 2, 2021 · 2 comments

Comments

@eliasbnk
Copy link
Owner

eliasbnk commented Jun 2, 2021

@jacobvr IDK what this means?

I know that these 2 lines are causing the trouble:

let bookCount = filteredElements.length + 1;
            handleNotStartedBookCount(bookCount);

in this code:

export const NotStartedBooks = ({ booksList, editBookStatus, addNewBook }) => {
  const { query, handleNotStartedBookCount } = useBooksContext();
  if (booksList === undefined) return <AddNewBook />;
  return (
    <>
      <div style={{ marginTop: 200 }} />
      <div>
        <AddNewBook addNewBook={addNewBook} />
      </div>

      {booksList
        .filter((book) => book.status === 'not started')
        .reduce((filteredElements, curr) => {
          if (
            curr.title.toLowerCase().includes(query) ||
            curr.author.toLowerCase().includes(query)
          ) {
            let bookCount = filteredElements.length + 1;
            handleNotStartedBookCount(bookCount);
            return filteredElements.concat([
              <div
                key={`books-to-read-page-${curr?.id}`}
                style={{ marginTop: 25, paddingBottom: 15 }}
              >
                <Book
                  book={curr}
                  editBookStatus={editBookStatus}
                  buttonActionOne={'reading'}
                  buttonActionTwo={'completed'}
                />
              </div>,
            ]);
          }
          return filteredElements;
        }, [])}
    </>
  );
};

The Error:
Screen Shot 2021-06-02 at 1 02 05 AM

@eliasbnk
Copy link
Owner Author

eliasbnk commented Jun 2, 2021

Screen Shot 2021-06-02 at 1 08 33 AM
Screen Shot 2021-06-02 at 1 08 28 AM
Screen Shot 2021-06-02 at 1 08 20 AM

I somehow need to calculate the length of the filtered array and set the count in the navbar before the components are opened as it adds this ugliness when the user first opens the site.

@eliasbnk
Copy link
Owner Author

eliasbnk commented Jun 2, 2021

only the first tab is calculated upon the first render, then after you cycle through the tabs it calculates the count forthose too.

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

No branches or pull requests

1 participant