Skip to content

Commit 8a7bd6c

Browse files
committed
update community 10 sketches to be fetched with getCuratedSketches with no args and memoize getCurationSketches
1 parent 43b62aa commit 8a7bd6c

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

src/api/OpenProcessing.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,19 @@ export type OpenProcessingCurationResponse = Array<{
3636
* @param limit max number of sketches to return
3737
* @returns sketches
3838
*/
39-
export const getCurationSketches = async (
39+
export const getCurationSketches = memoize(async (
4040
limit?: number,
4141
): Promise<OpenProcessingCurationResponse> => {
4242
const limitParam = limit ? `limit=${limit}` : "";
4343
const response = await fetch(
4444
`${openProcessingEndpoint}curation/${curationId}/sketches?${limitParam}`,
4545
);
4646
if(!response.ok){ //log error instead of throwing error to not cache result in memoize
47-
console.log('getCurationSketches', response.status, response.statusText)
47+
console.error('getCurationSketches', response.status, response.statusText)
4848
}
4949
const payload = await response.json();
5050
return payload as OpenProcessingCurationResponse;
51-
};
51+
});
5252

5353
/**
5454
* API Response from a call to the Sketch endpoint
@@ -82,7 +82,7 @@ export const getSketch = memoize(async (
8282
): Promise<OpenProcessingSketchResponse> => {
8383
const response = await fetch(`${openProcessingEndpoint}sketch/${id}`);
8484
if(!response.ok){ //log error instead of throwing error to not cache result in memoize
85-
console.log('getSketch', id, response.status, response.statusText)
85+
console.error('getSketch', id, response.status, response.statusText)
8686
}
8787
const payload = await response.json();
8888
return payload as OpenProcessingSketchResponse;
@@ -96,7 +96,7 @@ export const getSketchSize = memoize(async (id: string) => {
9696

9797
const response = await fetch(`${openProcessingEndpoint}sketch/${id}/code`);
9898
if(!response.ok){ //log error instead of throwing error to not cache result in memoize
99-
console.log('getSketchSize', id, response.status, response.statusText)
99+
console.error('getSketchSize', id, response.status, response.statusText)
100100
}
101101
const payload = await response.json();
102102

src/pages/[locale]/community.astro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import CommunityLayout from "@layouts/CommunityLayout.astro";
55
import { getCollectionInLocaleWithFallbacks } from "@pages/_utils";
66
77
export const getStaticPaths = async () => {
8-
const sketches = await getCurationSketches(10);
8+
const allSketches = await getCurationSketches();
9+
const sketches = allSketches.slice(0, 10);
910
return await Promise.all(
1011
nonDefaultSupportedLocales.map(async (locale) => {
1112
const libraries = await getCollectionInLocaleWithFallbacks(

src/pages/community.astro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { getCurationSketches } from "../api/OpenProcessing";
33
import CommunityLayout from "../layouts/CommunityLayout.astro";
44
import { getCollectionInDefaultLocale } from "./_utils";
55
6-
const sketches = await getCurationSketches(10);
6+
const allSketches = await getCurationSketches(10);
7+
const sketches = allSketches.slice(0, 10);
78
const libraries = await getCollectionInDefaultLocale("libraries");
89
const pastEvents = await getCollectionInDefaultLocale("events");
910
---

0 commit comments

Comments
 (0)