Skip to content
This repository was archived by the owner on Sep 25, 2025. It is now read-only.

feat(client): add total to paginatedPage and clear the extra queries - #2294

Closed
Sboonny wants to merge 0 commit into
freeCodeCamp:mainfrom
Sboonny:feat/hide-hasmore-button-when-there-is-no-events
Closed

Sboonny wants to merge 0 commit into
freeCodeCamp:mainfrom
Sboonny:feat/hide-hasmore-button-when-there-is-no-events

Conversation

@Sboonny

@Sboonny Sboonny commented Jan 27, 2023

Copy link
Copy Markdown
Member
  • I have read Chapter's contributing guidelines.
  • My pull request has a descriptive title (not a vague title like Update README.md).
  • My pull request targets the main branch of Chapter.

I am trying to observe the data, and hide the data based on if there is more data or not, and when it's complete and there is no more data, we can hide the buttons, instead of running the function again to findout if there is data left.

@ghost

ghost commented Jan 27, 2023 •

Copy link
Copy Markdown
👇 Click on the image for a new way to code review
  • Make big changes easier — review code in small groups of related files

  • Know where to start — see the whole change at a glance

  • Take a code tour — explore the change with an interactive tour

  • Make comments and review — all fully sync’ed with github

    Try it now!

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map Legend

Comment thread client/src/pages/_app.tsx
Comment on lines -57 to -65
cache: new InMemoryCache({
typePolicies: {
Query: {
fields: {
paginatedEvents: offsetLimitPagination(),
},
},
},
}),

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

needed to delete this, because the data doesn't exist?

in policies.d.ts

export declare type FieldReadFunction<TExisting = any, TReadResult = TExisting, TOptions extends FieldFunctionOptions = FieldFunctionOptions> = (existing: SafeReadonly<TExisting> | undefined, options: TOptions) => TReadResult | undefined;

Comment thread client/src/modules/home/index.tsx Outdated
variables: { offset: data?.paginatedEventsWithTotal.length },
});
setHasMore(res.data.paginatedEvents.length > 0);
setHasMore(res.data.paginatedEventsWithTotal.length > 0);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I have to many possibilities, while knowing the values are always 2 and 7. BTW, did you know, you can't mutate them, I didn't.

const total = data?.paginatedEventsWithTotal.map(({total})=> total).reduce(Number)
      setHasMore(res.data.paginatedEventsWithTotal.length < total)
      setHasMore(res.data.paginatedEventsWithTotal.length > total);
      setHasMore(res.data.paginatedEventsWithTotal.length + 2 < total)
      setHasMore(res.data.paginatedEventsWithTotal.length + 2 > total)
      setHasMore(res.data.paginatedEventsWithTotal.length += 2 < total)
      setHasMore(res.data.paginatedEventsWithTotal.length += 2 < total)
      ```

Comment thread client/src/modules/home/index.tsx Outdated
Comment on lines +69 to +72
const lookIfDataExist =
res.data.paginatedEventsWithTotal.length ===
data?.paginatedEventsWithTotal.length;
setHasMore(lookIfDataExist);

@Sboonny Sboonny Jan 31, 2023 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

If the total is odd, it will hide the odd number, although people won't know, it is still a bug, and maybe it doesn't work if the events are even, but I have no idea how to fix it.

Comment thread client/src/modules/home/index.tsx Resolved
@Sboonny Sboonny changed the title feat(client) observe the data of the query to fetch or hide the button feat(client): add total to paginatedPage and clear the extra queries Jan 31, 2023
@Sboonny
Sboonny marked this pull request as ready for review January 31, 2023 16:58
@Sboonny
Sboonny requested a review from a team January 31, 2023 16:58
Comment thread client/src/modules/home/index.tsx Resolved
@Sboonny
Sboonny marked this pull request as draft February 4, 2023 17:25
@Sboonny
Sboonny force-pushed the feat/hide-hasmore-button-when-there-is-no-events branch from c9b03c2 to 5115d4b Compare February 5, 2023 07:43
@Sboonny Sboonny closed this Feb 5, 2023
@Sboonny
Sboonny force-pushed the feat/hide-hasmore-button-when-there-is-no-events branch from 5115d4b to f82f9e1 Compare February 5, 2023 07:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant