Created
April 23, 2018 01:04
-
-
Save a-one-d-one/3d0f40bdc3354efc3cc672ddbf3b8273 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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