Skip to content

Commit 69abe9d

Browse files
committed
Add atomFamily and appTemplatesFetchSelector to atoms.js
1 parent ac19f73 commit 69abe9d

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

llmstack/client/src/data/atoms.js

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { atom, selector } from "recoil";
1+
import { atom, atomFamily, selector } from "recoil";
22
import { axios } from "./axios";
33

44
const 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

391421
export const appDebugState = atom({

0 commit comments

Comments
 (0)