@@ -23,6 +23,9 @@ export type OpenProcessingCurationResponse = Array<{
2323 title : string ;
2424 /** Description of sketch */
2525 description : string ;
26+ instructions : string ;
27+ mode : string ;
28+ createdOn : string ;
2629 userID : string ;
2730 submittedOn : string ;
2831 /** Author's name */
@@ -72,17 +75,31 @@ export type OpenProcessingSketchResponse = {
7275
7376/**
7477 * 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
7580 *
7681 * https://documenter.getpostman.com/view/16936458/2s9YC1Xa6X#7cd344f6-6e87-426a-969b-2b4a79701dd1
7782 * @param id
7883 * @returns
7984 */
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 ) ;
8399 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 ) ;
86103 }
87104 const payload = await response . json ( ) ;
88105 return payload as OpenProcessingSketchResponse ;
0 commit comments