import * as React from "react"; import * as Constants from "~/common/constants"; import * as SVG from "~/common/svg"; import * as Events from "~/common/custom-events"; import { css } from "@emotion/react"; import { ButtonPrimary, ButtonTertiary } from "~/components/system/components/Buttons"; import { FileTypeGroup } from "~/components/core/FileTypeIcon"; import { TabGroup, PrimaryTabGroup, SecondaryTabGroup } from "~/components/core/TabGroup"; import { CheckBox } from "~/components/system/components/CheckBox.js"; import { Boundary } from "~/components/system/components/fragments/Boundary"; import { GlobalCarousel } from "~/components/system/components/GlobalCarousel"; import { getPublicAndPrivateFiles } from "~/common/utilities"; import ScenePage from "~/components/core/ScenePage"; import DataView from "~/components/core/DataView"; import DataMeter from "~/components/core/DataMeterDetailed"; import ScenePageHeader from "~/components/core/ScenePageHeader"; import EmptyState from "~/components/core/EmptyState"; const POLLING_INTERVAL = 10000; const STYLES_CONTAINER_WRAPPER = css` display: flex; align-items: center; justify-content: flex-end; margin-bottom: 20px; `; const STYLES_CONTAINER = css` height: 60px; display: flex; flex-direction: row-reverse; justify-content: flex-start; align-items: center; `; const STYLES_COMMAND_WRAPPER = css` padding: 4px 0; display: flex; align-items: center; justify-content: center; `; //TODO(toast): Constants for SDS in future const STYLES_TOOLTIP_ANCHOR = css` border: 1px solid #f2f2f2; background-color: ${Constants.system.white}; border-radius: 4px; right: 0px; top: 48px; padding: 20px 24px; box-shadow: 0px 8px 24px rgba(178, 178, 178, 0.2); position: absolute; display: flex; z-index: ${Constants.zindex.tooltip}; `; const STYLES_FILETYPE_TOOLTIP = css` display: flex; flex-direction: column; justify-content: flex-start; align-items: center; border-right: 1px solid ${Constants.system.lightBorder}; padding-right: 4px; `; const STYLES_PRIVACY_TOOLTIP = css` display: flex; flex-direction: column; justify-content: flex-start; font-family: ${Constants.font.text}; font-size: ${Constants.typescale.lvl0}; padding-left: 24px; `; const STYLES_CHECKBOX_LABEL = css` padding-top: 0; position: relative; top: -4px; font-family: ${Constants.font.text}; font-size: ${Constants.typescale.lvl0}; user-select: none; `; const STYLES_BUTTONS_ROW = css` display: flex; flex-direction: row; align-items: center; `; const STYLES_TOOLTIP_TEXT = css` font-family: ${Constants.font.text}; font-size: 12px; `; const STYLES_COMMAND_TOOLTIP_ANCHOR = css` border: 1px solid ${Constants.system.bgGray}; background-color: ${Constants.system.white}; border-radius: 4px; display: flex; flex-direction: column; gap: 12px; align-items: flex-start; justify-content: space-around; box-shadow: 0px 8px 24px rgba(178, 178, 178, 0.2); width: 275px; position: absolute; top: 4px; right: 50px; z-index: ${Constants.zindex.tooltip}; padding: 12px; `; export default class SceneFilesFolder extends React.Component { state = { view: 0, filterTooltip: false, fileTypes: { image: false, video: false, audio: false, epub: false, pdf: false, }, filtersActive: false, privacy: "ALL", filteredFiles: this.props.viewer?.library[0].children, keyboardTooltip: false, }; componentDidMount = () => { this.openCarouselToItem(); }; componentDidUpdate = (prevProps, prevState) => { if (prevProps.viewer.library[0].children !== this.props.viewer.library[0].children) { if (this.state.filtersActive) { this._filterFiles(); } } if (prevProps.page !== this.props.page) { this.openCarouselToItem(); } }; _handleFilterTooltip = () => { this.setState({ filterTooltip: !this.state.filterTooltip }); }; _handlePrivacyFilter = (filter) => { this.setState({ privacy: filter }, this._filterFiles); }; _getPrivacyFilteredFiles = () => { let filter = this.state.privacy; const viewer = this.props.viewer; if (filter === "ALL") { return viewer.library[0].children; } const filtered = getPublicAndPrivateFiles({ viewer }); if (filter === "PUBLIC") { return filtered.publicFiles; } else if (filter === "PRIVATE") { return filtered.privateFiles; } else { console.log("unusable privacy param"); } }; _handleFiletypeFilter = (type) => { this.setState( { fileTypes: { ...this.state.fileTypes, [type]: !this.state.fileTypes[type] } }, this._filterFiles ); }; _filterFiles = () => { const filters = this.state.fileTypes; let fileTypeFiltersActive = Object.values(filters).some((val) => val === true); let filtersActive = fileTypeFiltersActive || this.state.privacy !== "ALL"; if (!filtersActive) { this.setState({ filtersActive }); return; } let filteredFiles = this._getPrivacyFilteredFiles(); if (fileTypeFiltersActive && this.props.viewer?.library[0].children?.length) { filteredFiles = filteredFiles.filter((file) => { return ( (filters.image && file.type.startsWith("image/")) || (filters.video && file.type.startsWith("video/")) || (filters.audio && file.type.startsWith("audio/")) || (filters.epub && file.type.startsWith("application/epub")) || (filters.pdf && file.type.startsWith("application/pdf")) ); }); } this.setState({ filteredFiles, filtersActive, }); }; openCarouselToItem = () => { let index = -1; let page = this.props.page; if (page?.fileId || page?.cid || page?.index) { if (page?.index) { index = page.index; } else { let library = this.props.viewer.library[0]?.children || []; for (let i = 0; i < library.length; i++) { let obj = library[i]; if ((obj.cid && obj.cid === page?.cid) || (obj.id && obj.id === page?.fileId)) { index = i; break; } } } } if (index !== -1) { Events.dispatchCustomEvent({ name: "slate-global-open-carousel", detail: { index }, }); } }; render() { let files = this.state.filtersActive ? this.state.filteredFiles : this.props.viewer?.library[0].children; files = files || []; return ( this.setState({ tab: value })} style={{ marginTop: 0, marginBottom: 32 }} itemStyle={{ margin: "0px 12px" }} /> ) : ( ) } actions={ this.props.mobile ? null : ( , , ]} value={this.state.view} onChange={(value) => this.setState({ view: value })} style={{ margin: "0 0 24px 0" }} /> ) } /> { this.props.onAction({ type: "SIDEBAR", value: "SIDEBAR_ADD_FILE_TO_BUCKET", }); }} style={{ whiteSpace: "nowrap", marginRight: 24 }} > Upload data } />
this.setState({ keyboardTooltip: false })} > this.setState({ keyboardTooltip: true })} > {this.state.keyboardTooltip ? (

Keyboard shortcuts

shift + click

select a range of items between two selections

shift + drag

select items by draging over them

alt + drag

deselect items by draging over them

) : null}
{this.state.filterTooltip ? ( { this.setState({ filterTooltip: false }); }} >
this._handleFiletypeFilter("image")} boxStyle={{ height: 20, width: 20 }} > Image
this._handleFiletypeFilter("audio")} boxStyle={{ height: 20, width: 20 }} > Audio
this._handleFiletypeFilter("video")} boxStyle={{ height: 20, width: 20 }} > Video
this._handleFiletypeFilter("epub")} boxStyle={{ height: 20, width: 20 }} > Epub
this._handleFiletypeFilter("pdf")} boxStyle={{ height: 20, width: 20 }} > Pdf
this._handlePrivacyFilter("ALL")} > All
this._handlePrivacyFilter("PRIVATE")} > Private
this._handlePrivacyFilter("PUBLIC")} > Public
) : null}
{files.length ? ( ) : (
Drag and drop files into Slate to upload
)}
); } }