Skip to content

Commit

Permalink
feat: calculate if there are more galleries more accurately
Browse files Browse the repository at this point in the history
  • Loading branch information
CrescentKohana committed Mar 21, 2024
1 parent d5d0f1c commit a17da0a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
6 changes: 2 additions & 4 deletions app/library.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { LibraryLayout } from "../components/Filters/LayoutSelect"
import GalleryGrid, { GalleriesResult } from "../components/GalleryGrid"
import withAuth from "../components/HOC/WithAuth"
import { fetchLibrary } from "../lib/api/library"
import { RESULT_LIMIT } from "../lib/api/other"
import { Role } from "../lib/helpers"
import useCategories from "../lib/hooks/data/useCategories"
import useFavorites from "../lib/hooks/data/useFavorites"
Expand Down Expand Up @@ -41,9 +40,8 @@ function Library() {
keepPreviousData: true,
})

// This should actually be called "mightHaveMore", as in rare cases the data ends exactly on the offset
// which results one extra request being made. (results % offset === 0)
const hasMoreGalleries = gData && gData[gData.length - 1]?.Count === RESULT_LIMIT
const hasMoreGalleries =
gData && gData[gData.length - 1].TotalCount > gData.reduce((acc, galleryResult) => acc + galleryResult.Count, 0)

// TODO: Grid masonry when major browsers support it (https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout/Masonry_Layout)
return (
Expand Down
1 change: 1 addition & 0 deletions components/GalleryGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { LibraryLayout } from "./Filters/LayoutSelect"
export interface GalleriesResult {
Data: GalleryMeta[] | Record<string, GalleryMeta[]>
Count: number
TotalCount: number
}

interface GalleryProps {
Expand Down

0 comments on commit a17da0a

Please sign in to comment.