From 84b5978ba1202fe45a1dd4d8efe3eb73b9b54cbe Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Wed, 9 Jun 2021 08:59:27 -0700 Subject: [PATCH] wip --- app/embeds/Dropbox.js | 25 ++++++++++++++++++++++--- app/embeds/index.js | 3 ++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/app/embeds/Dropbox.js b/app/embeds/Dropbox.js index ee07a35f8d..edfb1fc8ee 100644 --- a/app/embeds/Dropbox.js +++ b/app/embeds/Dropbox.js @@ -3,7 +3,7 @@ import * as React from "react"; import styled from "styled-components"; import env from "env"; -const URL_REGEX = new RegExp("^https://www.dropbox.com/s/(.*)$"); +const URL_REGEX = new RegExp("^https://www.dropbox.com/sh?/(.*)$"); type Props = {| isSelected: boolean, @@ -16,10 +16,28 @@ type Props = {| class Dropbox extends React.Component { static ENABLED = [URL_REGEX]; - container = React.createRef(); + container = React.createRef(); + + shouldComponentUpdate(nextProps: Props) { + return ( + nextProps.isSelected !== this.props.isSelected || + nextProps.attrs.href !== this.props.attrs.href + ); + } componentDidMount() { - var tag = document.createElement("script"); + if (document.getElementById("dropboxjs")) { + if (this.container.current) { + window.Dropbox.embed( + { link: this.props.attrs.href }, + this.container.current + ); + } + + return; + } + + const tag = document.createElement("script"); tag.async = false; tag.id = "dropboxjs"; tag.setAttribute("data-app-key", env.DROPBOX_APP_KEY); @@ -45,6 +63,7 @@ class Dropbox extends React.Component { const Rounded = styled.div` border-radius: 3px; + height: 400px; `; export default Dropbox; diff --git a/app/embeds/index.js b/app/embeds/index.js index 2a72e47fe5..33db02dfa1 100644 --- a/app/embeds/index.js +++ b/app/embeds/index.js @@ -32,6 +32,7 @@ import Typeform from "./Typeform"; import Vimeo from "./Vimeo"; import YouTube from "./YouTube"; import env from "env"; +import { isCustomDomain } from "utils/domains"; function matcher(Component) { return (url: string) => { @@ -107,7 +108,7 @@ export default filter( component: Descript, matcher: matcher(Descript), }, - env.DROPBOX_APP_KEY + env.DROPBOX_APP_KEY && !isCustomDomain() ? { title: "Dropbox", keywords: "dropbox file pdf",