import * as React from "react"; import * as Jumper from "~/components/system/components/fragments/Jumper"; import * as MobileJumper from "~/components/system/components/fragments/MobileJumper"; import * as System from "~/components/system"; import * as FileUtilities from "~/common/file-utilities"; import * as Logging from "~/common/logging"; import * as Strings from "~/common/strings"; import * as Styles from "~/common/styles"; import * as Constants from "~/common/constants"; import * as SVG from "~/common/svg"; import { css } from "@emotion/react"; import { useUploadContext } from "~/components/core/Upload/Provider"; import { useUploadStore } from "~/components/core/Upload/store"; import { useUploadOnboardingContext } from "~/components/core/Onboarding/Upload"; import { useCheckIfExtensionIsInstalled, useLocalStorage } from "~/common/hooks"; import DownloadExtensionButton from "~/components/core/Extension/DownloadExtensionButton"; const STYLES_EXTENSION_BAR = (theme) => css` ${Styles.HORIZONTAL_CONTAINER_CENTERED}; justify-content: space-between; background-color: ${theme.semantic.bgWhite}; @supports ((-webkit-backdrop-filter: blur(75px)) or (backdrop-filter: blur(75px))) { -webkit-backdrop-filter: blur(75px); backdrop-filter: blur(75px); background-color: ${theme.semantic.bgBlurLight}; } `; function ExtensionBar() { const localStorage = useLocalStorage("upload-jumper-extension-bar"); const [isVisible, setVisibility] = React.useState(JSON.parse(localStorage.getItem() || true)); const hideExtensionBar = () => (setVisibility(false), localStorage.setItem(false)); const { isExtensionDownloaded } = useCheckIfExtensionIsInstalled(); if (isExtensionDownloaded || !isVisible) return null; return ( Save from anywhere on the Web
); } /* -----------------------------------------------------------------------------------------------*/ const STYLES_LINK_INPUT = (theme) => css` background-color: ${theme.semantic.bgWhite}; width: calc(100% - 8px); margin-right: 8px; `; const STYLES_FILES_UPLOAD_WRAPPER = css` ${Styles.VERTICAL_CONTAINER_CENTERED}; padding-top: 55px; padding-bottom: 55px; `; function LinkForm({ data }) { const { uploadLink } = useUploadStore((store) => store.handlers); const [, { hideUploadJumper }] = useUploadContext(); const onboardingContext = useUploadOnboardingContext(); const [state, setState] = React.useState({ url: "", urlError: false, }); const handleChange = (e) => setState((prev) => ({ ...prev, [e.target.name]: e.target.value, urlError: false })); const handleUploadLink = () => { if (Strings.isEmpty(state.url)) { setState((prev) => ({ ...prev, urlError: true })); return; } try { new URL(state.url); } catch (e) { Logging.error(e); setState((prev) => ({ ...prev, urlError: true })); return; } uploadLink({ url: state.url, slate: data }); setState({ url: "", urlError: false }); onboardingContext?.goToNextStep?.(); hideUploadJumper(); }; return (
Save
); } /* ------------------------------------------------------------------------------------------------- * UploadJumper * -----------------------------------------------------------------------------------------------*/ const STYLES_FILE_HIDDEN = css` height: 1px; width: 1px; opacity: 0; visibility: hidden; position: fixed; top: -1px; left: -1px; `; const STYLES_LINK_UPLOAD_WRAPPER = css` padding: 50px 72px; `; const useFileUpload = ({ onUpload, data }) => { const { upload } = useUploadStore((store) => store.handlers); const [, { hideUploadJumper }] = useUploadContext(); const handleUpload = (e) => { const { files } = FileUtilities.formatUploadedFiles({ files: e.target.files }); upload({ files, slate: data }); onUpload?.(); hideUploadJumper(); }; return { handleUpload }; }; export function UploadJumper({ data }) { const [{ isUploadJumperVisible }, { hideUploadJumper }] = useUploadContext(); const onboardingContext = useUploadOnboardingContext(); const { handleUpload } = useFileUpload({ data, onUpload: onboardingContext?.goToNextStep }); const handleSelectFileKeyDown = (e) => { if (e.key === "Enter" || e.key === " ") { e.target.click(); e.preventDefault(); } }; return ( {isUploadJumperVisible ? ( (onboardingContext.goToNextStep(), hideUploadJumper())} > Upload
Drop or select files to save to Slate
(we recommend uploading fewer than 200 files at a time)
Select files
) : null}
); } /* ------------------------------------------------------------------------------------------------- * MobileUploadJumper * -----------------------------------------------------------------------------------------------*/ export function MobileUploadJumper({ data }) { const [{ isUploadJumperVisible }, { hideUploadJumper }] = useUploadContext(); const onboardingContext = useUploadOnboardingContext(); return ( {isUploadJumperVisible ? ( (onboardingContext.goToNextStep(), hideUploadJumper())}> Upload
open Slate on desktop to upload files
) : null}
); }