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

chore: fix pagination in the files page #180

Merged
merged 2 commits into from Jul 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 3 additions & 11 deletions packages/website/pages/files.js
Expand Up @@ -136,8 +136,7 @@ export default function Files({ user }) {
const initialFiles = [];

const [selectedFiles, setSelectedFiles] = useState(/** @type string[] */ initialFiles)
const [isNextDisabled, setNextDisabled] = useState('')
const [size] = useState(25)
const [size] = useState(25 + 1)
const [befores, setBefores] = useState([new Date().toISOString()])
const queryClient = useQueryClient()
const queryParams = { before: befores[0], size }
Expand All @@ -151,14 +150,8 @@ export default function Files({ user }) {
}
)

const reachedEndOfPagination = data?.length === 0 && befores.length > 1
if (reachedEndOfPagination) {
setNextDisabled(befores[1])
setBefores(befores.slice(1))
}

/** @type {Upload[]} */
const uploads = data || []
const uploads = data?.length === size ? data.concat().splice(0, size - 1) : (data || [])

function handleDelete() {
if (!confirm('Are you sure? Deleted files cannot be recovered!')) return
Expand Down Expand Up @@ -278,13 +271,12 @@ export default function Files({ user }) {
← Previous
</Button>
</When>
<When condition={uploads.length >= size}>
<When condition={data?.length === size }>
<Button
className="black"
wrapperClassName="m-h-2 ml-auto"
onClick={handleNextClick}
id="uploads-next"
disabled={isNextDisabled === befores[0]}
>
Next →
</Button>
Expand Down