Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 134
Fix tracks table loading one track at a time PAY-1868 PAY-1873#6049
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
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -12,18 +12,18 @@ import cn from 'classnames' | ||
| import { debounce, range } from 'lodash' | ||
| import moment from 'moment' | ||
| import { | ||
| useTable, | ||
| useSortBy, | ||
| useResizeColumns, | ||
| useFlexLayout, | ||
| Cell, | ||
| Row, | ||
| TableRowProps | ||
| TableRowProps, | ||
| useFlexLayout, | ||
| useResizeColumns, | ||
| useSortBy, | ||
| useTable | ||
| } from 'react-table' | ||
| import { | ||
| AutoSizer, | ||
| List, | ||
| InfiniteLoader, | ||
| List, | ||
| WindowScroller | ||
| } from 'react-virtualized' | ||
| @@ -131,10 +131,17 @@ export const Table = ({ | ||
| scrollRef, | ||
| showMoreLimit, | ||
| tableClassName, | ||
| totalRowCount = 9999, | ||
| totalRowCount, | ||
| useLocalSort = false, | ||
| wrapperClassName | ||
| }: TableProps) => { | ||
| useEffect(() => { | ||
| if (totalRowCount == null && isPaginated) { | ||
| console.error( | ||
| 'Programming error - need to specify the `totalRowCount` if using paginated Table component (i.e .if `isPaginated` is `true`)' | ||
| ) | ||
| } | ||
| }, [isPaginated, totalRowCount]) | ||
| const defaultColumn = useMemo( | ||
| () => ({ | ||
| // Default resizing column props | ||
| @@ -152,6 +159,9 @@ export const Table = ({ | ||
| // Pagination page | ||
| const [currentPage, setCurrentPage] = useState<number>(0) | ||
| const maxPage = useMemo(() => { | ||
| if (totalRowCount == null) { | ||
| return 0 | ||
| } | ||
| return Math.floor(totalRowCount / pageSize) | ||
| }, [pageSize, totalRowCount]) | ||
| @@ -518,20 +528,14 @@ export const Table = ({ | ||
| // TODO: This is supposed to return a promise that resolves when the row data has been fetched. | ||
| // It currently does not, but there are no issues with this currently so will fix if issues pop up | ||
| const loadMoreRows = useCallback( | ||
| async ({ | ||
| startIndex, | ||
| stopIndex | ||
| }: { | ||
| startIndex: number | ||
| stopIndex: number | ||
| }) => { | ||
| async ({ startIndex }: { startIndex: number }) => { | ||
| if (!debouncedFetchMore) return null | ||
| const offset = startIndex | ||
| const limit = stopIndex - startIndex + 1 | ||
| const limit = fetchBatchSize | ||
ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the | ||
| debouncedFetchMore(offset, limit) | ||
| return null | ||
| }, | ||
| [debouncedFetchMore] | ||
| [debouncedFetchMore, fetchBatchSize] | ||
| ) | ||
| const isRowLoaded = useCallback( | ||
| @@ -658,7 +662,7 @@ export const Table = ({ | ||
| <InfiniteLoader | ||
| isRowLoaded={isRowLoaded} | ||
| loadMoreRows={loadMoreRows} | ||
| rowCount={totalRowCount} | ||
| rowCount={totalRowCount == null ? rows.length : totalRowCount} | ||
| ||
| threshold={fetchThreshold} | ||
| minimumBatchSize={fetchBatchSize} | ||
| > | ||
| @@ -702,7 +706,9 @@ export const Table = ({ | ||
| ref={registerListChild} | ||
| overscanRowsCount={2} | ||
| rowCount={ | ||
| debouncedFetchMore ? totalRowCount : rows.length | ||
| debouncedFetchMore && totalRowCount != null | ||
ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto above comment | ||
| ? totalRowCount | ||
| : rows.length | ||
| } | ||
| rowHeight={64} | ||
| rowRenderer={renderRow} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -3,6 +3,7 @@ import { useContext } from 'react' | ||
| import { | ||
| CommonState, | ||
| ID, | ||
| Kind, | ||
| LibraryCategory, | ||
| Lineup, | ||
| QueueItem, | ||
| @@ -63,6 +64,7 @@ export type SavedPageProps = { | ||
| description: string | ||
| onFilterChange: (e: any) => void | ||
| onSortChange: (method: string, direction: string) => void | ||
| hasReachedEnd: boolean | ||
| isQueued: boolean | ||
| playingUid: UID | null | ||
| getFilteredData: ( | ||
| @@ -111,6 +113,7 @@ const SavedPage = ({ | ||
| onFilterChange, | ||
| onSortChange, | ||
| allTracksFetched, | ||
| hasReachedEnd, | ||
| filterText, | ||
| onChangeTab, | ||
| onClickRow, | ||
| @@ -135,9 +138,18 @@ const SavedPage = ({ | ||
| } | ||
| }) | ||
| const getTracksTableData = (): [SavedPageTrack[], number] => { | ||
| let [data, playingIndex] = getFilteredData(entries) | ||
| if (!hasReachedEnd) { | ||
| // Add in some empty rows to show user that more are loading in | ||
| data = data.concat(new Array(5).fill({ kind: Kind.EMPTY })) | ||
| } | ||
| return [data, playingIndex] | ||
| } | ||
| const [dataSource, playingIndex] = | ||
| status === Status.SUCCESS || entries.length | ||
| ? getFilteredData(entries) | ||
| ? getTracksTableData() | ||
| : [[], -1] | ||
| const isEmpty = | ||
| @@ -236,7 +248,7 @@ const SavedPage = ({ | ||
| playingIndex={playingIndex} | ||
| scrollRef={mainContentRef} | ||
| useLocalSort={allTracksFetched} | ||
| totalRowCount={dataSource.length} | ||
| ||
| fetchBatchSize={50} | ||
| userId={account ? account.user_id : 0} | ||
| /> | ||
| ), | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since
totalRowCountdoesn't have a default value anymore, this prevents this value from breaking