This repository has been archived by the owner on Oct 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tsx
134 lines (126 loc) · 3.84 KB
/
index.tsx
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import { Box, Input, Button, Checkbox, Text } from "@saleor/macaw-ui/next";
import Head from "next/head";
import { FormEvent, useEffect, useState } from "react";
import { labelText, textarea } from "../textarea.css";
import { useRouter } from "next/router";
export default function Page() {
const router = useRouter();
const [version, setVersion] = useState(router.query.version?.toString() || "");
const [contents, setContents] = useState(router.query.contents?.toString() || "");
const [theme, setTheme] = useState(router.query.theme?.toString() || "");
const [params, setParams] = useState<{
version: string;
contents: string;
theme: string;
} | null>(null);
useEffect(() => {
const version = router.query.version?.toString() || "";
const contents = router.query.contents?.toString() || "";
const theme = router.query.theme?.toString() || "";
setVersion(version);
setContents(contents);
setTheme(theme);
if (version || contents || theme) {
setParams({ version, contents, theme });
}
}, [router.query]);
const handleSubmit = (e: FormEvent<HTMLFormElement>) => {
e.preventDefault();
setParams({ contents, version, theme });
router.push({ query: { contents, version, theme } });
};
const urlSmall = params && `/api/updates?` + new URLSearchParams(params);
const urlLarge = params && `/api/updates?` + new URLSearchParams({ ...params, variant: "large" });
const urlYouTube =
params && `/api/updates?` + new URLSearchParams({ ...params, variant: "youtube" });
return (
<Box paddingBottom={13}>
<Head>
<meta name="og:title" content="Vercel Edge Network" />
<meta name="og:description" content="Vercel Edge Network" />
<meta
name="og:image"
content={
// Because OG images must have a absolute URL, we use the
// `VERCEL_URL` environment variable to get the deployment’s URL.
// More info:
// https://vercel.com/docs/concepts/projects/environment-variables
`${process.env.VERCEL_URL ? "https://" + process.env.VERCEL_URL : ""}/api/updates`
}
/>
</Head>
<Box
onSubmit={handleSubmit}
display="flex"
as="form"
flexDirection="column"
gap={8}
__maxWidth={768}
marginLeft="auto"
marginRight="auto"
>
<Input
label="Version"
name="version"
value={version}
onChange={(e) => setVersion(e.currentTarget.value)}
size="large"
/>
<Box as="label" display="flex" flexDirection="column">
<div className={labelText}>Text</div>
<textarea
name="contents"
value={contents}
onChange={(e) => setContents(e.currentTarget.value)}
rows={4}
className={textarea}
required
/>
</Box>
<Checkbox
name="theme"
checked={theme === "dark"}
onCheckedChange={(e) => setTheme(e ? "dark" : "light")}
>
Noire? ▰
</Checkbox>
<Button type="submit" size="large">
Generate
</Button>
{urlSmall && urlLarge && urlYouTube && (
<Box display="flex" flexDirection="column" rowGap={12}>
<div>
<Text as="h2" variant="hero" size="large" marginBottom={4}>
Blog small:
</Text>
<Box>
<a href={urlSmall} download={`saleor-update-small-${new Date().toISOString()}.png`}>
<img src={urlSmall} />
</a>
</Box>
</div>
<div>
<Text as="h2" variant="hero" size="large" marginBottom={4}>
Blog large:
</Text>
<a href={urlLarge} download={`saleor-update-large-${new Date().toISOString()}.png`}>
<img src={urlLarge} />
</a>
</div>
<div>
<Text as="h2" variant="hero" size="large" marginBottom={4}>
YouTube:
</Text>
<a
href={urlYouTube}
download={`saleor-update-youtube-${new Date().toISOString()}.png`}
>
<img src={urlYouTube} />
</a>
</div>
</Box>
)}
</Box>
</Box>
);
}