Skip to content

Commit 3439d35

Browse files
committed
Dont share link when it is too big
1 parent bc3f820 commit 3439d35

1 file changed

Lines changed: 40 additions & 29 deletions

File tree

apps/class-solid/src/components/ShareButton.tsx

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ import {
1010
import {
1111
Dialog,
1212
DialogContent,
13-
DialogDescription,
1413
DialogHeader,
1514
DialogTitle,
1615
DialogTrigger,
1716
} from "./ui/dialog";
1817
import { TextField, TextFieldInput } from "./ui/text-field";
1918
import { showToast } from "./ui/toast";
2019

20+
const MAX_SHAREABLE_LINK_LENGTH = 32_000;
21+
2122
export function ShareButton() {
2223
const [open, setOpen] = createSignal(false);
2324
const [isCopied, setIsCopied] = createSignal(false);
@@ -65,7 +66,18 @@ export function ShareButton() {
6566
<DialogContent>
6667
<DialogHeader>
6768
<DialogTitle class="mr-10">Share link</DialogTitle>
68-
<DialogDescription>
69+
</DialogHeader>
70+
<Show
71+
when={shareableLink().length < MAX_SHAREABLE_LINK_LENGTH}
72+
fallback={
73+
<p>
74+
Cannot share application state, it is too large. Please download
75+
each experiment by itself or make it smaller by removing
76+
permutations and/or experiments.
77+
</p>
78+
}
79+
>
80+
<div>
6981
Anyone with{" "}
7082
<a
7183
target="_blank"
@@ -77,33 +89,32 @@ export function ShareButton() {
7789
</a>{" "}
7890
will be able to view the current application state in their web
7991
browser.
80-
</DialogDescription>
81-
</DialogHeader>
82-
83-
<div class="flex items-center space-x-2">
84-
<TextField class="w-full" defaultValue={shareableLink()}>
85-
<TextFieldInput
86-
ref={inputRef}
87-
type="text"
88-
readonly
89-
class="w-full"
90-
aria-label="Shareable link for current application state"
91-
/>
92-
</TextField>
93-
<Button
94-
type="submit"
95-
variant="outline"
96-
size="icon"
97-
class="px-3"
98-
onClick={copyToClipboard}
99-
aria-label={isCopied() ? "Link copied" : "Copy link"}
100-
>
101-
<span class="sr-only">Copy</span>
102-
<Show when={isCopied()} fallback={<MdiClipboard />}>
103-
<MdiClipboardCheck />
104-
</Show>
105-
</Button>
106-
</div>
92+
</div>
93+
<div class="flex items-center space-x-2">
94+
<TextField class="w-full" defaultValue={shareableLink()}>
95+
<TextFieldInput
96+
ref={inputRef}
97+
type="text"
98+
readonly
99+
class="w-full"
100+
aria-label="Shareable link for current application state"
101+
/>
102+
</TextField>
103+
<Button
104+
type="submit"
105+
variant="outline"
106+
size="icon"
107+
class="px-3"
108+
onClick={copyToClipboard}
109+
aria-label={isCopied() ? "Link copied" : "Copy link"}
110+
>
111+
<span class="sr-only">Copy</span>
112+
<Show when={isCopied()} fallback={<MdiClipboard />}>
113+
<MdiClipboardCheck />
114+
</Show>
115+
</Button>
116+
</div>
117+
</Show>
107118
<div aria-live="polite" class="sr-only">
108119
<Show when={isCopied()}>Link copied to clipboard</Show>
109120
</div>

0 commit comments

Comments
 (0)