Skip to content

Commit 76d4202

Browse files
committed
destructure return from getSketch for legibility and revert title to come from getSketch
1 parent cebf48a commit 76d4202

File tree

4 files changed

+17
-26
lines changed

4 files changed

+17
-26
lines changed

src/api/OpenProcessing.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ export const getSketch = memoize(
9595
}
9696

9797
// check for sketch data in Open Processing API
98-
console.log("CALLING API TEST FOR:", id);
9998
const response = await fetch(`${openProcessingEndpoint}sketch/${id}`);
10099
if (!response.ok) {
101100
//log error instead of throwing error to not cache result in memoize

src/layouts/SketchLayout.astro

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,14 @@ import { ScalingIframe } from "@components/ScalingIframe";
1818
interface Props {
1919
sketchId: string;
2020
authorName: string;
21-
title: string;
2221
}
2322
24-
const { sketchId, authorName, title } = Astro.props;
25-
const sketchInfo = await getSketch(sketchId);
23+
const { sketchId, authorName } = Astro.props;
24+
const { title, createdOn, instructions } = await getSketch(sketchId);
2625
2726
const currentLocale = getCurrentLocale(Astro.url.pathname);
2827
const t = await getUiTranslator(currentLocale);
29-
const dateString = new Date(sketchInfo.createdOn).toLocaleDateString(
30-
currentLocale,
31-
{
28+
const dateString = new Date(createdOn).toLocaleDateString(currentLocale, {
3229
year: "numeric",
3330
month: "long",
3431
day: "numeric",
@@ -37,12 +34,12 @@ const dateString = new Date(sketchInfo.createdOn).toLocaleDateString(
3734
3835
setJumpToState(null);
3936
const moreSketches = await getRandomCurationSketches(4);
40-
const featuredImageURL = makeThumbnailUrl(sketchInfo.visualID);
37+
const featuredImageURL = makeThumbnailUrl(sketchId);
4138
4239
// NOTE: Commenting out the call to getSketchSize to minimise calls to OP due to rate limiting
4340
// width and height should be moved to data fetched by either getCuratedSketches or getSketch to minimise calls.
4441
45-
// let { width, height } = await getSketchSize(sketchInfo.visualID);
42+
// let { width, height } = await getSketchSize(sketchId);
4643
// let heightOverWidth = 1 / 1.5;
4744
// if (width && height) {
4845
// // Account for OP header bar
@@ -61,7 +58,7 @@ const iframeTitle = `OpenProcessing Sketch: ${title} by ${authorName}`;
6158
title={title}
6259
locale={currentLocale}
6360
featuredImageSrc={featuredImageURL}
64-
description={sketchInfo.instructions}
61+
description={instructions}
6562
/>
6663

6764
<BaseLayout
@@ -83,14 +80,14 @@ const iframeTitle = `OpenProcessing Sketch: ${title} by ${authorName}`;
8380
width ? (
8481
<ScalingIframe
8582
client:load
86-
src={makeSketchEmbedUrl(sketchInfo.visualID)}
83+
src={makeSketchEmbedUrl(sketchId)}
8784
width={width}
8885
height={height}
8986
title={iframeTitle}
9087
/>
9188
) : (
9289
<iframe
93-
src={makeSketchEmbedUrl(sketchInfo.visualID)}
90+
src={makeSketchEmbedUrl(sketchId)}
9491
width="100%"
9592
height="100%"
9693
style={{
@@ -108,7 +105,7 @@ const iframeTitle = `OpenProcessing Sketch: ${title} by ${authorName}`;
108105
<div class="py-md grid gap-y-sm md:gap-y-md">
109106
<LinkButton
110107
variant="code"
111-
url={`${makeSketchLinkUrl(sketchInfo.visualID)}/#code`}
108+
url={`${makeSketchLinkUrl(sketchId)}/#code`}
112109
class="min-w-[184px] lg:min-w-[220px]">{t("Show Code")}</LinkButton
113110
>
114111
<LinkButton
@@ -118,16 +115,11 @@ const iframeTitle = `OpenProcessing Sketch: ${title} by ${authorName}`;
118115
>
119116
</div>
120117

121-
{
122-
sketchInfo.instructions && (
123-
<p class="text-md my-sm md:my-lg">{sketchInfo.instructions}</p>
124-
)
125-
}
118+
{instructions && <p class="text-md my-sm md:my-lg">{instructions}</p>}
126119

127120
<p class="text-xs md:text-base mb-3xl">
128-
This <a
129-
class="text-type-magenta"
130-
href={makeSketchLinkUrl(sketchInfo.visualID)}>sketch</a
121+
This <a class="text-type-magenta" href={makeSketchLinkUrl(sketchId)}
122+
>sketch</a
131123
> is ported from the <a
132124
class="text-type-magenta"
133125
href="https://openprocessing.org">OpenProcessing</a

src/pages/[locale]/sketches/[...slug].astro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export async function getStaticPaths() {
1717
return entries.flat();
1818
}
1919
const { slug } = Astro.params;
20-
const { authorName, title } = Astro.props;
20+
const { authorName } = Astro.props;
2121
---
2222

23-
<SketchLayout sketchId={slug} authorName={authorName} title={title} />
23+
<SketchLayout sketchId={slug} authorName={authorName} />

src/pages/sketches/[...slug].astro

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ export async function getStaticPaths() {
66
const sketches = await getCurationSketches();
77
return sketches.map((sketch) => ({
88
params: { slug: sketch.visualID },
9-
props: { authorName: sketch.fullname, title: sketch.title },
9+
props: { authorName: sketch.fullname },
1010
}));
1111
}
1212
1313
const { slug } = Astro.params;
14-
const { authorName, title } = Astro.props;
14+
const { authorName } = Astro.props;
1515
---
1616

17-
<SketchLayout sketchId={slug} authorName={authorName} title={title} />
17+
<SketchLayout sketchId={slug} authorName={authorName} />

0 commit comments

Comments
 (0)