Skip to content

Commit fa4e39a

Browse files
committed
Updated design and supported multiple files (Processing 4.4.1)
1 parent 6d504b1 commit fa4e39a

3 files changed

Lines changed: 53 additions & 8 deletions

File tree

src/components/OpenWithButton.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,34 @@
1-
import React from 'react';
1+
import React, { useState } from 'react';
22
import classnames from 'classnames';
33

44
import ProcessingIcon from '../images/logo-processing.svg';
55

6-
import * as css from './CopyButton.module.css';
6+
import * as css from './OpenWithButton.module.css';
7+
8+
const OpenWithButton = ({ pdes }) => {
9+
const main = pdes[0]
10+
let sketchURL = `pde://sketch/base64/${stringToBase64(main.code)}?pde=`
11+
for (let pde of pdes) {
12+
if (pde === main) continue
13+
sketchURL += `${pde.name}:${stringToBase64(pde.code)},`
14+
}
15+
const [showInstructions, setShowInstructions] = useState(false)
716

8-
const OpenWithButton = ({ text }) => {
917
return (
1018
<a
11-
href={`pde://sketch/base64/${stringToBase64(text)}`}
19+
href={sketchURL}
1220
type="button"
1321
className={classnames(css.root)}
22+
onClick={() => setShowInstructions(true)}
1423
>
1524
<ProcessingIcon /> {'Open With Processing'}
25+
{showInstructions && (
26+
<div className={classnames(css.instructions)}>
27+
<p>If this did not open Processing, make sure you have it installed and opened at least once.</p>
28+
<p>Currently only versions of Processing later than 4.4 are supported</p>
29+
<a href="https://www.processing.org/download/" target="_black">Download Processing</a>
30+
</div>
31+
)}
1632
</a>
1733
)
1834
}
@@ -23,5 +39,5 @@ function stringToBase64(str) {
2339
if (typeof Buffer !== 'undefined') {
2440
return Buffer.from(str).toString('base64');
2541
}
26-
return btoa(str);
27-
}
42+
return btoa(str)
43+
}

src/components/OpenWithButton.module.css

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
color: var(--darkgray);
77
cursor: pointer;
88
fill: var(--darkgray);
9+
position: relative;
910

1011
& svg {
1112
height: 12px;
@@ -21,4 +22,32 @@
2122
.root:active {
2223
color: var(--processing-blue-mid);
2324
fill: var(--processing-blue-mid);
24-
}
25+
}
26+
27+
.instructions {
28+
bottom: 100%;
29+
margin-bottom: 10px;
30+
left: 50%;
31+
position: absolute;
32+
transform: translateX(-50%);
33+
min-width: 16em;
34+
background-color: #555;
35+
color: #fff;
36+
text-align: left;
37+
border-radius: 6px;
38+
padding: 8px 10px 10px 25px;
39+
transition: opacity 0.3s;
40+
a {
41+
color: var(--processing-blue-mid);
42+
}
43+
&::before {
44+
content: "";
45+
position: absolute;
46+
top: 100%;
47+
left: 50%;
48+
margin-left: -10px;
49+
border-width: 10px;
50+
border-style: solid;
51+
border-color: #555 transparent transparent transparent;
52+
}
53+
}

src/components/Tabs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const Tabs = ({ pdes, className }) => {
4343
key={key}>
4444
<div className={css.actions}>
4545
<CopyButton text={pde.code} />
46-
<OpenWithButton text={pde.code} />
46+
<OpenWithButton pdes={pdes} />
4747
</div>
4848
<pre className={css.codeBlock}>
4949
<code

0 commit comments

Comments
 (0)