Skip to content

Commit 7dbc8b1

Browse files
authored
Merge pull request #766 from streamich/dropbox
Dropbox
2 parents 422ad74 + e0cd6a8 commit 7dbc8b1

File tree

8 files changed

+87
-27
lines changed

8 files changed

+87
-27
lines changed

.storybook/webpack.config.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const path = require('path');
22
const {compilerOptions} = require('../tsconfig.json');
3-
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
43

54
const SRC_PATH = path.join(__dirname, '../src');
65

@@ -35,6 +34,5 @@ module.exports = {
3534
resolve: {
3635
extensions: ['.ts', '.tsx', '.js', '.jsx', '.gif', '.jpg', '.png'],
3736
enforceExtension: false,
38-
},
39-
plugins: [new ForkTsCheckerWebpackPlugin()],
37+
}
4038
};

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
"@types/react": "18.0.3",
4848
"@types/react-dom": "18.0.0",
4949
"babel-loader": "8.2.4",
50-
"fork-ts-checker-webpack-plugin": "7.2.4",
5150
"gh-pages": "3.2.3",
5251
"git-cz": "4.8.0",
5352
"husky": "7.0.4",

src/ReactEmbed.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export interface Blocks {
2626
}
2727

2828
const defaultBlocks: Blocks = {
29+
dropbox: React.lazy(() => import('./blocks/dropbox')),
2930
figma: React.lazy(() => import('./blocks/figma')),
3031
gfycat: React.lazy(() => import('./blocks/gfycat')),
3132
gist: React.lazy(() => import('./blocks/gist')),

src/__story__/dropbox.story.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import * as React from 'react';
2+
import {storiesOf} from '@storybook/react';
3+
import Embed from '..';
4+
import {Box} from './Box';
5+
6+
const url = 'https://www.dropbox.com/s/cla7asg2zjzscpd/CV%20VC%20Top%2050%20Report%202021%20V1.pdf?dl=0';
7+
8+
storiesOf('Dropbox', module)
9+
.add('A pdf file', () => {
10+
return <Embed url={url} />;
11+
})
12+
.add('Fitted', () => {
13+
return (
14+
<Box>
15+
<Embed url={url} />
16+
</Box>
17+
);
18+
});

src/__story__/pdf.story.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {storiesOf} from '@storybook/react';
33
import Embed from '..';
44
import {Box} from './Box';
55

6-
const pdf = 'https://www.africau.edu/images/default/sample.pdf';
6+
const pdf = 'http://www.africau.edu/images/default/sample.pdf';
77

88
storiesOf('PDF', module)
99
.add('A pdf file', () => {

src/blocks/dropbox/index.tsx

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import * as React from 'react';
2+
import {BlockProps} from '../..';
3+
4+
const script = document.createElement('script');
5+
script.type = 'text/javascript';
6+
script.id = 'dropboxjs';
7+
const DROPBOX_APP_KEY = (window as any).DROPBOX_APP_KEY;
8+
if (DROPBOX_APP_KEY) script.setAttribute('data-app-key', DROPBOX_APP_KEY);
9+
script.src = 'https://www.dropbox.com/static/api/2/dropins.js';
10+
document.body.append(script);
11+
12+
declare const Dropbox: any;
13+
14+
const DropboxUi: React.FC<BlockProps> = ({url, renderWrap}) => {
15+
const ref = React.useRef();
16+
React.useLayoutEffect(() => {
17+
if (!ref.current) return;
18+
const embed = (Dropbox as any).embed({
19+
link: url,
20+
file: {
21+
zoom: "best" // or "fit"
22+
},
23+
folder: {
24+
view: "list", // or "grid"
25+
headerSize: "normal" // or "small"
26+
}
27+
}, ref.current);
28+
return () => {
29+
(Dropbox as any).unmount(embed);
30+
};
31+
}, []);
32+
33+
return renderWrap(
34+
<div ref={ref as any} style={{height: 500}} />,
35+
);
36+
};
37+
38+
const WithDropbox: React.FC<BlockProps> = (props) => {
39+
const [ready, setReady] = React.useState(false);
40+
React.useEffect(() => {
41+
let mounted = true;
42+
const wait = () => {
43+
if (!mounted) return;
44+
if (typeof Dropbox !== 'undefined') setReady(true);
45+
setTimeout(wait, 100);
46+
};
47+
wait();
48+
return () => {
49+
mounted = false;
50+
};
51+
}, []);
52+
53+
if (!ready) return null;
54+
55+
return <DropboxUi {...props} />;
56+
};
57+
58+
export default WithDropbox;

src/routeToBlock.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ const routeToBlock: ReactEmbedRouter = (blocks: Blocks, parsed: ParsedUrl) => {
8989
return routeGoogle(blocks, parsed);
9090
case 'gfycat.com':
9191
return routeGfycat(blocks, parsed);
92+
case 'dropbox.com':
93+
case 'www.dropbox.com':
94+
return [blocks.dropbox, ''];
9295
default:
9396
if (canPlayPdf(url)) {
9497
return [blocks.pdf, ''];

yarn.lock

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4058,7 +4058,7 @@ chokidar@^2.1.8:
40584058
optionalDependencies:
40594059
fsevents "^1.2.7"
40604060

4061-
chokidar@^3.4.1, chokidar@^3.4.2, chokidar@^3.5.3:
4061+
chokidar@^3.4.1, chokidar@^3.4.2:
40624062
version "3.5.3"
40634063
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.3.tgz#1cf37c8707b932bd1af1ae22c0432e2acd1903bd"
40644064
integrity sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==
@@ -4513,7 +4513,7 @@ cosmiconfig@^6.0.0:
45134513
path-type "^4.0.0"
45144514
yaml "^1.7.2"
45154515

4516-
cosmiconfig@^7, cosmiconfig@^7.0.0, cosmiconfig@^7.0.1:
4516+
cosmiconfig@^7, cosmiconfig@^7.0.0:
45174517
version "7.0.1"
45184518
resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-7.0.1.tgz#714d756522cace867867ccb4474c5d01bbae5d6d"
45194519
integrity sha512-a1YWNUV2HwGimB7dU2s1wUMurNKjpx60HxBB6xUM8Re+2s1g1IIfJvFR0/iCF+XHdE0GMTKTuLR32UQff4TEyQ==
@@ -5698,23 +5698,6 @@ foreground-child@^2.0.0:
56985698
cross-spawn "^7.0.0"
56995699
signal-exit "^3.0.2"
57005700

5701-
fork-ts-checker-webpack-plugin@7.2.4:
5702-
version "7.2.4"
5703-
resolved "https://registry.yarnpkg.com/fork-ts-checker-webpack-plugin/-/fork-ts-checker-webpack-plugin-7.2.4.tgz#9c755035405eecad0680826c7063564126d21a16"
5704-
integrity sha512-wVN8w0aGiiF4/1o0N5VPeh+PCs4OMg8VzKiYc7Uw7e2VmTt8JuKjEc2/uvd/VfG0Ux+4WnxMncSRcZpXAS6Fyw==
5705-
dependencies:
5706-
"@babel/code-frame" "^7.16.7"
5707-
chalk "^4.1.2"
5708-
chokidar "^3.5.3"
5709-
cosmiconfig "^7.0.1"
5710-
deepmerge "^4.2.2"
5711-
fs-extra "^10.0.0"
5712-
memfs "^3.4.1"
5713-
minimatch "^3.0.4"
5714-
schema-utils "^3.1.1"
5715-
semver "^7.3.5"
5716-
tapable "^2.2.1"
5717-
57185701
fork-ts-checker-webpack-plugin@^4.1.6:
57195702
version "4.1.6"
57205703
resolved "https://registry.yarnpkg.com/fork-ts-checker-webpack-plugin/-/fork-ts-checker-webpack-plugin-4.1.6.tgz#5055c703febcf37fa06405d400c122b905167fc5"
@@ -7791,7 +7774,7 @@ media-typer@0.3.0:
77917774
resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748"
77927775
integrity sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=
77937776

7794-
memfs@^3.1.2, memfs@^3.4.1:
7777+
memfs@^3.1.2:
77957778
version "3.4.1"
77967779
resolved "https://registry.yarnpkg.com/memfs/-/memfs-3.4.1.tgz#b78092f466a0dce054d63d39275b24c71d3f1305"
77977780
integrity sha512-1c9VPVvW5P7I85c35zAdEr1TD5+F11IToIHIlrVIcflfnzPkJa0ZoYEoEdYDP8KgPFoSZ/opDrUsAoZWym3mtw==
@@ -10315,7 +10298,7 @@ schema-utils@^2.6.5, schema-utils@^2.7.0:
1031510298
ajv "^6.12.4"
1031610299
ajv-keywords "^3.5.2"
1031710300

10318-
schema-utils@^3.0.0, schema-utils@^3.1.1:
10301+
schema-utils@^3.0.0:
1031910302
version "3.1.1"
1032010303
resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-3.1.1.tgz#bc74c4b6b6995c1d88f76a8b77bea7219e0c8281"
1032110304
integrity sha512-Y5PQxS4ITlC+EahLuXaY86TXfR7Dc5lw294alXOq86JAHCihAIZfqv8nNCWvaEJvaC51uN9hbLGeV0cFBdH+Fw==
@@ -11100,7 +11083,7 @@ tapable@^1.0.0, tapable@^1.1.3:
1110011083
resolved "https://registry.yarnpkg.com/tapable/-/tapable-1.1.3.tgz#a1fccc06b58db61fd7a45da2da44f5f3a3e67ba2"
1110111084
integrity sha512-4WK/bYZmj8xLr+HUCODHGF1ZFzsYffasLUgEiMBY4fgtltdO6B4WJtlSbPaDTLpYTcGVwM2qLnFTICEcNxs3kA==
1110211085

11103-
tapable@^2.2.0, tapable@^2.2.1:
11086+
tapable@^2.2.0:
1110411087
version "2.2.1"
1110511088
resolved "https://registry.yarnpkg.com/tapable/-/tapable-2.2.1.tgz#1967a73ef4060a82f12ab96af86d52fdb76eeca0"
1110611089
integrity sha512-GNzQvQTOIP6RyTfE2Qxb8ZVlNmw0n88vp1szwWRimP02mnTsx3Wtn5qRdqY9w2XduFNUgvOwhNnQsjwCp+kqaQ==

0 commit comments

Comments
 (0)