Skip to content

Instantly share code, notes, and snippets.

@a-one-d-one
Created April 22, 2018 22:27
Show Gist options
  • Save a-one-d-one/2863bcf0680278bbea0525cbd8a13292 to your computer and use it in GitHub Desktop.
Save a-one-d-one/2863bcf0680278bbea0525cbd8a13292 to your computer and use it in GitHub Desktop.
const getDownloadItems = (state) => {
if (!state || !state.get('downloads')) {
return Immutable.List()
}
const downloadsSize = state.get('downloads').size
const downloadItemWidth = domUtil.getStyleConstants('download-item-width')
const downloadItemMargin = domUtil.getStyleConstants('download-item-margin')
const downloadBarPadding = domUtil.getStyleConstants('download-bar-padding')
const downloadBarButtons = domUtil.getStyleConstants('download-bar-buttons')
const numItems = Math.floor(
(window.innerWidth - (downloadBarPadding * 2) - downloadBarButtons) /
(downloadItemWidth + downloadItemMargin)
)
return state.get('downloads')
.sort((x, y) => x.get('startTime') - y.get('startTime'))
.skip(downloadsSize - numItems)
.reverse()
.map((download, downloadId) => downloadId)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment