File tree Expand file tree Collapse file tree 1 file changed +33
-3
lines changed Expand file tree Collapse file tree 1 file changed +33
-3
lines changed Original file line number Diff line number Diff line change 1- import { atom , selector } from "recoil" ;
1+ import { atom , atomFamily , selector } from "recoil" ;
22import { axios } from "./axios" ;
33
44const apiProvidersFetchSelector = selector ( {
@@ -383,9 +383,39 @@ export const isMobileState = atom({
383383 default : window . innerWidth < 768 ,
384384} ) ;
385385
386- export const appTemplateState = atom ( {
386+ const appTemplatesFetchSelector = selector ( {
387+ key : "appTemplatesFetchSelector" ,
388+ get : async ( ) => {
389+ try {
390+ const appTemplates = await axios ( ) . get ( "/api/apps/templates" ) ;
391+ return appTemplates . data ;
392+ } catch ( error ) {
393+ return [ ] ;
394+ }
395+ } ,
396+ } ) ;
397+
398+ export const appTemplatesState = atom ( {
399+ key : "appTemplatesState" ,
400+ default : appTemplatesFetchSelector ,
401+ } ) ;
402+
403+ export const appTemplateState = atomFamily ( {
387404 key : "appTemplateState" ,
388- default : null ,
405+ default : async ( templateSlug ) => {
406+ if ( ! templateSlug || templateSlug === "_blank_" ) {
407+ return { } ;
408+ }
409+
410+ try {
411+ const appTemplate = await axios ( ) . get (
412+ `/api/apps/templates/${ templateSlug } ` ,
413+ ) ;
414+ return appTemplate . data ;
415+ } catch ( error ) {
416+ return { } ;
417+ }
418+ } ,
389419} ) ;
390420
391421export const appDebugState = atom ( {
You can’t perform that action at this time.
0 commit comments