-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMuseumToClipboard.jsx
116 lines (107 loc) · 2.77 KB
/
MuseumToClipboard.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import React, { useRef } from "react";
function MuseumToClipboard({ language, type, list, selected }) {
const typeEmoji = {
bugs: "🐜",
fishes: "🐟",
fossils: "🦕",
}[type];
const missingList = list
.filter((item) => !selected.includes(item.id))
.map((item) => `${typeEmoji} · ${item.name}`)
.join("\n");
const caughtList = list
.filter((item) => selected.includes(item.id))
.map((item) => `${typeEmoji} · ${item.name}`)
.join("\n");
const filteredList = {
missing: missingList,
caught: caughtList,
};
const missing = useRef(null);
const caught = useRef(null);
function copyToClipboard(input) {
input.current.value = filteredList[input.current.name];
input.current.select();
document.execCommand("copy");
alert("Copied");
}
return (
<div className="textCenter">
<h2>{language.copyToClipboard}</h2>
<p>
<button className="button" onClick={() => copyToClipboard(missing)}>
{language.copyMissingItems?.replace(
"{museumType}",
language[type].toLowerCase()
)}
</button>
</p>
<p>
<button
className="button buttonSecondary"
onClick={() => copyToClipboard(caught)}
>
{language.copyCaughtItems?.replace(
"{museumType}",
language[type].toLowerCase()
)}
</button>
<label style={{
position: "absolute",
left: "-100vw",
width: 0,
height: 0,
padding: 0
}}>
{
language.copyMissingItems?.replace(
"{museumType}",
language[type].toLowerCase()
)
}
<textarea
name="missing"
ref={missing}
defaultValue={missingList}
style={{
position: "absolute",
left: "-100vw",
width: 0,
height: 0,
padding: 0,
fontSize: '1em'
}}
/>
</label>
<label style={{
position: "absolute",
left: "-100vw",
opactiy: 0,
width: 0,
height: 0,
padding: 0
}}>
{language.copyCaughtItems?.replace(
"{museumType}",
language[type].toLowerCase()
)}
<textarea
name="caught"
ref={caught}
style={{
position: "absolute",
left: "-100vw",
opactiy: 0,
width: 0,
height: 0,
padding: 0,
fontSize: '1em'
}}
defaultValue={caughtList}
/>
</label>
</p>
</div>
);
}
export default MuseumToClipboard;