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"; import WebsitePrototypeWrapper from "~/components/core/WebsitePrototypeWrapper"; 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 ${Constants.semantic.borderGrayLight}; 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.semantic.borderGrayLight}; 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.semantic.bgLight}; 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 = { filterTooltip: false, fileTypes: { image: false, video: false, audio: false, epub: false, pdf: false, }, filtersActive: false, privacy: "ALL", filteredFiles: this.props.viewer?.library, keyboardTooltip: false, index: -1, }; // componentDidMount = () => { // this.openCarouselToItem(); // }; componentDidUpdate = (prevProps, prevState) => { if (prevProps.viewer.library !== this.props.viewer.library) { if (this.state.filtersActive) { this._filterFiles(); } } // if (prevProps.page.params !== this.props.page.params) { // 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; } const filtered = getPublicAndPrivateFiles({ viewer }); if (filter === "PUBLIC") { return filtered.publicFiles; } else if (filter === "PRIVATE") { return filtered.privateFiles; } }; _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?.length) { filteredFiles = filteredFiles.filter((file) => { return ( (filters.image && file.data.type.startsWith("image/")) || (filters.video && file.data.type.startsWith("video/")) || (filters.audio && file.data.type.startsWith("audio/")) || (filters.epub && file.data.type.startsWith("application/epub")) || (filters.pdf && file.data.type.startsWith("application/pdf")) ); }); } this.setState({ filteredFiles, filtersActive, }); }; // openCarouselToItem = () => { // if (!this.props.page?.params || !this.props.viewer.library?.length) { // return; // } // let index = -1; // let params = this.props.page.params; // if (params?.fileId || params?.cid || params?.index) { // if (params?.index) { // index = params.index; // } else { // let library = this.props.viewer.library || []; // for (let i = 0; i < library.length; i++) { // let obj = library[i]; // if ((obj.cid && obj.cid === params?.cid) || (obj.id && obj.id === params?.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; files = files || []; const tab = this.props.page.params?.tab || "grid"; return ( this.setState({ index })} /> { this.props.onAction({ type: "SIDEBAR", value: "SIDEBAR_ADD_FILE_TO_BUCKET", }); }} style={{ whiteSpace: "nowrap", marginRight: 24 }} > Upload data } />
, value: { tab: "grid" }, }, { title: , value: { tab: "table" }, }, ]} value={tab} onAction={this.props.onAction} style={{ margin: "0 0 24px 0" }} />
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
)}
); } }