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_FILTERS_CONTAINER = css` height: 60px; display: flex; flex-direction: row-reverse; justify-content: flex-start; align-items: center; `; //TODO(toast): Constants for SDS in future const STYLES_TOOLTIP_ANCHOR = css` border: 1px solid #f2f2f2; background-color: ${Constants.system.white}; border-radius: 2px; right: 0px; top: 48px; width: 256px; height: 216px; display: flex; flex-direction: row; align-items: flex-start; justify-content: space-around; box-shadow: 0px 8px 24px rgba(178, 178, 178, 0.2); position: absolute; z-index: ${Constants.zindex.tooltip}; `; const STYLES_FILETYPE_TOOLTIP = css` display: flex; flex-direction: column; justify-content: flex-start; align-items: center; height: 80%; width: 50%; margin: 24px; margin-top: 20px; margin-bottom: 20px; `; const STYLES_PRIVACY_TOOLTIP = css` display: flex; flex-direction: column; justify-content: flex-start; align-items: flex-start; height: 40%; font-family: ${Constants.font.medium}; font-size: 16px; width: 50%; margin: 24px; margin-top: 20px; margin-bottom: 20px; `; const STYLES_CHECKBOX_LABEL = css` padding-top: 0; position: relative; top: -4px; font-family: ${Constants.font.medium}; font-size: 16px; user-select: none; `; const STYLES_TOOLTIP_DIVIDER_CONTAINER = css` height: 100%; width: 1px; display: flex; flex-direction: column; justify-content: center; `; const STYLES_TOOLTIP_DIVIDER = css` height: 80%; border: 1px solid ${Constants.system.lightBorder}; width: 1px; `; export default class SceneFilesFolder extends React.Component { state = { view: 0, filterTooltip: false, filters: { images: false, audio: false, assets: false, videos: false, books: false, }, filtersActive: false, privacy: "All", files: this.props.viewer?.library[0].children, }; _handleFilterTooltip = () => { this.setState({ filterTooltip: !this.state.filterTooltip }); }; _handlePrivacyFilter = (filter) => { const viewer = this.props.viewer; if (filter === "All") { this.setState({ privacy: "All" }, this._filterFiles); } else if (filter === "Public") { this.setState({ privacy: "Public" }, this._filterFiles); } else if (filter === "Private") { this.setState({ privacy: "Private" }, this._filterFiles); } else { console.log("unusable privacy param"); } }; _getPrivacyFiles = (filter) => { const viewer = this.props.viewer; const filtered = getPublicAndPrivateFiles({ viewer }); if (filter === "All") { return viewer.library[0].children; } else if (filter === "Public") { return filtered.publicFiles; } else if (filter === "Private") { return filtered.privateFiles; } else { console.log("unusable privacy param"); } }; _handleFiletypeFilter = (type) => { this.setState( (prevState) => ({ filters: { ...prevState.filters, [type]: !prevState.filters[type], }, }), this._filterFiles ); }; _filterFiles = () => { const filteredFiles = []; const privacy = this.state.privacy; const library = this._getPrivacyFiles(privacy); const filters = this.state.filters; const filterKeys = Object.keys(filters).filter((key) => { return filters[key] === true; }); if (filterKeys.length && library?.length) { for (const libraryObject of library) { for (const type of filterKeys) { for (const mimeType of Constants.filetypes[type]) { { libraryObject.type === mimeType ? filteredFiles.push(libraryObject) : null; } } } } this.setState((prevState) => ({ files: filteredFiles, filterTooltip: true, filtersActive: true, })); } else { this.setState((prevState) => ({ files: library, filterTooltip: true, filtersActive: false, })); } }; componentDidMount = () => { 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() { 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.state.filterTooltip ? ( this.setState({ filetypeTooltip: false })} >
this._handleFiletypeFilter("images")} boxStyle={{ height: 20, width: 20 }} > Images
this._handleFiletypeFilter("audio")} boxStyle={{ height: 20, width: 20 }} > Audio
this._handleFiletypeFilter("assets")} boxStyle={{ height: 20, width: 20 }} > Assets
this._handleFiletypeFilter("videos")} boxStyle={{ height: 20, width: 20 }} > Videos
this._handleFiletypeFilter("books")} boxStyle={{ height: 20, width: 20 }} > Books
this._handlePrivacyFilter("All")} > All
this._handlePrivacyFilter("Private")} > Private
this._handlePrivacyFilter("Public")} > Public
) : null}
{this.state.files?.length ? ( ) : (
Drag and drop files into Slate to upload
)}
); } }