import * as React from "react"; import * as Constants from "~/common/constants"; import * as Styles from "~/common/styles"; import * as UserBehaviors from "~/common/user-behaviors"; import * as Strings from "~/common/strings"; import * as Environment from "~/common/environment"; import { ButtonPrimaryFull, PopoverNavigation } from "~/components/system"; import { css } from "@emotion/react"; import { Link } from "~/components/core/Link"; import { Boundary } from "~/components/system/components/fragments/Boundary"; import { H4, P3 } from "~/components/system/components/Typography"; import ProfilePhoto from "~/components/core/ProfilePhoto"; const STYLES_HEADER = css` position: relative; @media (max-width: ${Constants.sizes.mobile}px) { padding: 0px; width: auto; } `; const STYLES_PROFILE_MOBILE = css` display: flex; align-items: center; `; const STYLES_POPOVER_CONTANIER = (theme) => css` padding: 16px 20px; border-radius: 16px; border: 1px solid ${theme.semantic.borderGrayLight4}; box-shadow: ${theme.shadow.lightLarge}; @supports ((-webkit-backdrop-filter: blur(75px)) or (backdrop-filter: blur(75px))) { background-color: ${theme.semantic.bgBlurWhite}; -webkit-backdrop-filter: blur(75px); backdrop-filter: blur(75px); } `; const STYLES_POPOVER_SECTION = (theme) => css` border-top: 1px solid ${theme.semantic.borderGrayLight4}; border-bottom: none; padding: 0; margin: 0; padding-top: 8px; padding-bottom: 8px; p { display: block; width: 100%; } :last-child { padding-bottom: 0px; } * + * { margin-top: 4px; } `; const STYLES_POPOVER_SECTION_ITEM = (theme) => css` position: relative; padding: 0px; width: calc(100% + 16px); left: -8px; a { display: block; } `; const STYLES_SECTION_ITEM_HOVER = (theme) => css` padding: 1px 8px 3px; border-radius: 8px; &:hover { background-color: ${theme.system.grayLight4}; } `; const STYLES_DATAMETER_WRAPPER = (theme) => css` width: 100%; min-width: 240px; height: 8px; background-color: ${theme.semantic.bgBlurWhiteTRN}; border: 1px solid ${theme.semantic.borderGrayLight4}; border-radius: 2px; overflow: hidden; `; const STYLES_DATAMETER = (theme) => css` height: 100%; background-color: ${theme.system.blue}; border-radius: 2px; `; const DataMeter = ({ bytes = 1000, maximumBytes = 4000, ...props }) => { const percentage = bytes / maximumBytes; return (
); }; export class ApplicationUserControlsPopup extends React.Component { state = { isExtensionDownloaded: false, }; componentDidMount() { if (document) { const isExtensionDownloaded = this._checkIfExtensionIsDownloaded(); this.setState({ isExtensionDownloaded }); } } _checkIfExtensionIsDownloaded = () => { const extensionElement = document.getElementById("browser_extension"); if (!extensionElement) return false; return extensionElement.className.includes("isDownloaded"); }; _handleExtensionDownloadLink = () => { const testUserAgent = (regex) => regex.test(window.navigator.userAgent); const isFirefox = testUserAgent(/firefox/i); const firefoxLink = Environment.EXTENSION_FIREFOX; if (isFirefox && firefoxLink) return window.open(firefoxLink, "_blank"); const isSafari = testUserAgent(/safari/i); const safariLink = Environment.EXTENSION_SAFARI; if (isSafari && safariLink) return window.open(safariLink, "_blank"); window.open(Environment.EXTENSION_CHROME, "_blank"); }; _handleAction = (props) => { this.props.onTogglePopup(); this.props.onAction(props); }; _handleSignOut = (e) => { e.preventDefault(); e.stopPropagation(); this.props.onTogglePopup(); UserBehaviors.signOut({ viewer: this.props.viewer }); }; render() { if (this.props.popup !== "profile") return null; const username = this.props.viewer.name || `@${this.props.viewer.username}`; const objectsLength = this.props.viewer.library.length; const { stats } = this.props.viewer; const topSection = (

{username}

{objectsLength} {Strings.pluralize("Object", objectsLength)} {Strings.bytesToSize(stats.bytes, 0)} of {Strings.bytesToSize(stats.maximumBytes, 0)}{" "} Stored
); const ExtensionButton = (
Install Slate browser extension
); const navigation = [ [ { text: (
Profile
), }, { text: (
Directory
), }, ], [ { text: (
Filecoin
), }, { text: (
Storage deal
), }, { text: (
API
), }, ], [ { text: (
Settings
), }, { text:
Sign out
, onClick: (e) => { this._handleSignOut(e); }, }, ...(!this.state.isExtensionDownloaded ? [{ text: ExtensionButton }] : []), ], ]; return ( <>
this.props.onTogglePopup()} >
this.props.onTogglePopup()} >
); } } export class ApplicationUserControls extends React.Component { render() { let tooltip = ; return (
{this.props.popup === "profile" ? tooltip : null}
); } }