Skip to content

Commit fe40984

Browse files
committed
plugin onboardingModal: add paste from clipboard button
This may be a workaround for #439, where we can paste into the form without needing the input to be focussed.
1 parent 0a46e24 commit fe40984

File tree

5 files changed

+31
-7
lines changed

5 files changed

+31
-7
lines changed

docs/docs/translation-status.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
{
33
"name": "English",
44
"code": "en",
5-
"completed": 202,
5+
"completed": 203,
66
"missing": 0,
77
"percent": 100
88
},
99
{
1010
"name": "Nederlands",
1111
"code": "nl",
1212
"completed": 146,
13-
"missing": 56,
13+
"missing": 57,
1414
"percent": 72
1515
}
1616
]

plugin/src/i18n/langs/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ export const en: Translations = {
209209
},
210210
tokenInputLabel: "API Token",
211211
submitButtonLabel: "Save",
212+
pasteButtonLabel: "Paste from clipboard",
212213
},
213214
query: {
214215
displays: {

plugin/src/i18n/translation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ export type Translations = {
190190
};
191191
tokenInputLabel: string;
192192
submitButtonLabel: string;
193+
pasteButtonLabel: string;
193194
};
194195
query: {
195196
displays: {

plugin/src/ui/onboardingModal/TokenInputForm.tsx

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ export const TokenInputForm: React.FC<Props> = ({ onTokenSubmit, tester }) => {
2323
setToken(newToken.trim());
2424
};
2525

26+
const pasteFromClipboard = async () => {
27+
try {
28+
const clipboardText = await navigator.clipboard.readText();
29+
onTokenChange(clipboardText);
30+
} catch (e) {
31+
console.error("Failed to read from clipboard", e);
32+
}
33+
};
34+
2635
// The epoch ensures that only the latest validation request is processed.
2736
// The debounce ensures that we don't fire off too many requests.
2837
const validationEpoch = useRef(0);
@@ -75,9 +84,20 @@ export const TokenInputForm: React.FC<Props> = ({ onTokenSubmit, tester }) => {
7584
</Group>
7685
<FieldError>{validationStatus.kind === "error" ? validationStatus.message : ""}</FieldError>
7786
</TextField>
78-
<Button type="submit" isDisabled={!canSubmit} onPress={() => onTokenSubmit(token)}>
79-
{i18n.submitButtonLabel}
80-
</Button>
87+
<div className="controls">
88+
<Button type="button" onPress={pasteFromClipboard}>
89+
Paste from clipboard
90+
{i18n.pasteButtonLabel}
91+
</Button>
92+
<Button
93+
type="submit"
94+
isDisabled={!canSubmit}
95+
onPress={() => onTokenSubmit(token)}
96+
className="mod-cta"
97+
>
98+
{i18n.submitButtonLabel}
99+
</Button>
100+
</div>
81101
</div>
82102
);
83103
};

plugin/src/ui/onboardingModal/styles.scss

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@
3131
}
3232
}
3333

34-
.react-aria-Button {
35-
float: right;
34+
.controls {
35+
display: flex;
36+
justify-content: flex-end;
37+
gap: 1em;
3638
margin-top: 1em;
3739
}
3840

0 commit comments

Comments
 (0)