@@ -23,6 +23,9 @@ export type OpenProcessingCurationResponse = Array<{
23
23
title : string ;
24
24
/** Description of sketch */
25
25
description : string ;
26
+ instructions : string ;
27
+ mode : string ;
28
+ createdOn : string ;
26
29
userID : string ;
27
30
submittedOn : string ;
28
31
/** Author's name */
@@ -72,17 +75,31 @@ export type OpenProcessingSketchResponse = {
72
75
73
76
/**
74
77
* Get info about a specific sketch from the OpenProcessing API
78
+ * First checks if the sketch is in the memoized curated sketches and returns the data if so,
79
+ * Otherwise calls OpenProcessing API for this specific sketch
75
80
*
76
81
* https://documenter.getpostman.com/view/16936458/2s9YC1Xa6X#7cd344f6-6e87-426a-969b-2b4a79701dd1
77
82
* @param id
78
83
* @returns
79
84
*/
80
- export const getSketch = memoize ( async (
81
- id : string ,
82
- ) : Promise < OpenProcessingSketchResponse > => {
85
+ export const getSketch = memoize (
86
+ async ( id : string ) : Promise < OpenProcessingSketchResponse > => {
87
+ // check for memoized sketch in curation sketches
88
+ const curationSketches = await getCurationSketches ( ) ;
89
+ const memoizedSketch = curationSketches . find ( ( el ) => el . visualID === id ) ;
90
+ if ( memoizedSketch ) {
91
+ return {
92
+ ...memoizedSketch ,
93
+ license : "" ,
94
+ } as OpenProcessingSketchResponse ;
95
+ }
96
+
97
+ // check for sketch data in Open Processing API
98
+ console . log ( "CALLING API TEST FOR:" , id ) ;
83
99
const response = await fetch ( `${ openProcessingEndpoint } sketch/${ id } ` ) ;
84
- if ( ! response . ok ) { //log error instead of throwing error to not cache result in memoize
85
- console . error ( 'getSketch' , id , response . status , response . statusText )
100
+ if ( ! response . ok ) {
101
+ //log error instead of throwing error to not cache result in memoize
102
+ console . error ( "getSketch" , id , response . status , response . statusText ) ;
86
103
}
87
104
const payload = await response . json ( ) ;
88
105
return payload as OpenProcessingSketchResponse ;
0 commit comments