Skip to content

Instantly share code, notes, and snippets.

@a-one-d-one
Created April 23, 2018 01:04
Show Gist options
  • Save a-one-d-one/3d0f40bdc3354efc3cc672ddbf3b8273 to your computer and use it in GitHub Desktop.
Save a-one-d-one/3d0f40bdc3354efc3cc672ddbf3b8273 to your computer and use it in GitHub Desktop.
const getDownloadItems = (state) => {
const currentWindow = state.get('currentWindow')
const tabId = frameStateUtil.getActiveFrameTabId(state)
const frameKey = frameStateUtil.getFrameKeyByTabId(currentWindow, tabId)
const isPrivate = privateState.isPrivateTab(state, frameKey)
if (!isPrivate) {
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