Skip to content

Commit ab9f538

Browse files
committed
fix typescript
1 parent e31bec3 commit ab9f538

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

app/api/artifact/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { getServerSideConfig } from "@/app/config/server";
44

55
async function handle(req: NextRequest, res: NextResponse) {
66
const serverConfig = getServerSideConfig();
7-
const storeUrl = (key) =>
7+
const storeUrl = (key: string) =>
88
`https://api.cloudflare.com/client/v4/accounts/${serverConfig.cloudflareAccountId}/storage/kv/namespaces/${serverConfig.cloudflareKVNamespaceId}/values/${key}`;
99
const storeHeaders = () => ({
1010
Authorization: `Bearer ${serverConfig.cloudflareKVApiKey}`,
@@ -32,7 +32,7 @@ async function handle(req: NextRequest, res: NextResponse) {
3232
}
3333
if (req.method === "GET") {
3434
const id = req?.nextUrl?.searchParams?.get("id");
35-
const res = await fetch(storeUrl(id), {
35+
const res = await fetch(storeUrl(id as string), {
3636
headers: storeHeaders(),
3737
method: "GET",
3838
});

app/components/artifact.tsx

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,34 @@ export function HTMLPreview(props: {
6767
style={{ width: "100%", height }}
6868
// src={`data:text/html,${encodeURIComponent(srcDoc)}`}
6969
srcDoc={srcDoc}
70-
onLoad={(e) => props?.onLoad(title)}
70+
onLoad={(e) => props?.onLoad && props?.onLoad(title)}
7171
></iframe>
7272
);
7373
}
7474

75-
export function ArtifactShareButton({ getCode, id, style, fileName }) {
75+
export function ArtifactShareButton({
76+
getCode,
77+
id,
78+
style,
79+
fileName,
80+
}: {
81+
getCode: () => string;
82+
id?: string;
83+
style?: any;
84+
fileName?: string;
85+
}) {
7686
const [name, setName] = useState(id);
7787
const [show, setShow] = useState(false);
78-
const shareUrl = useMemo(() =>
79-
[location.origin, "#", Path.Artifact, "/", name].join(""),
88+
const shareUrl = useMemo(
89+
() => [location.origin, "#", Path.Artifact, "/", name].join(""),
90+
[name],
8091
);
81-
const upload = (code) =>
92+
const upload = (code: string) =>
8293
id
8394
? Promise.resolve({ id })
8495
: fetch(ApiPath.Artifact, {
8596
method: "POST",
86-
body: getCode(),
97+
body: code,
8798
})
8899
.then((res) => res.json())
89100
.then(({ id }) => {
@@ -103,9 +114,11 @@ export function ArtifactShareButton({ getCode, id, style, fileName }) {
103114
bordered
104115
title={Locale.Export.Artifact.Title}
105116
onClick={() => {
106-
upload(getCode()).then(({ id }) => {
107-
setShow(true);
108-
setName(id);
117+
upload(getCode()).then((res) => {
118+
if (res?.id) {
119+
setShow(true);
120+
setName(res?.id);
121+
}
109122
});
110123
}}
111124
/>
@@ -168,7 +181,7 @@ export function Artifact() {
168181
return (
169182
<div
170183
style={{
171-
disply: "block",
184+
display: "block",
172185
width: "100%",
173186
height: "100%",
174187
position: "relative",
@@ -195,7 +208,7 @@ export function Artifact() {
195208
autoHeight={false}
196209
height={height - 36}
197210
onLoad={(title) => {
198-
setFileName(title);
211+
setFileName(title as string);
199212
setLoading(false);
200213
}}
201214
/>

app/components/home.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ function Screen() {
143143
if (isArtifact) {
144144
return (
145145
<Routes>
146-
<Route exact path="/artifact/:id" element={<Artifact />} />
146+
<Route path="/artifact/:id" element={<Artifact />} />
147147
</Routes>
148148
);
149149
}

0 commit comments

Comments
 (0)