From e2f24fe3c49f540340c040e0c21f27656fed388f Mon Sep 17 00:00:00 2001 From: Harish Mohan Raj Date: Thu, 18 Apr 2024 17:48:12 +0530 Subject: [PATCH] WIP --- app/main.wasp | 14 ++++++-- app/src/client/app/ModelsPage.tsx | 46 +++++++++++++++++-------- app/src/client/services/modelService.ts | 6 ++-- app/src/server/actions.ts | 44 ++++++++++++++++++++--- app/src/server/common/constants.ts | 1 + app/src/server/queries.ts | 32 ++++++++++++++++- 6 files changed, 118 insertions(+), 25 deletions(-) create mode 100644 app/src/server/common/constants.ts diff --git a/app/main.wasp b/app/main.wasp index 25f83b0..3a9e709 100644 --- a/app/main.wasp +++ b/app/main.wasp @@ -265,8 +265,13 @@ action updateUserById { entities: [User] } -action getModels { - fn: import { getModels } from "@src/server/actions.js", +action getAvailableModels { + fn: import { getAvailableModels } from "@src/server/actions.js", + entities: [] +} + +action updateUserModels { + fn: import { updateUserModels } from "@src/server/actions.js", entities: [] } @@ -287,6 +292,11 @@ query getPaginatedUsers { entities: [User] } +query getModels { + fn: import { getModels } from "@src/server/queries.js", + entities: [User] +} + /* * 📡 These are custom Wasp API Endpoints. Use them for callbacks, webhooks, etc. * https://wasp-lang.dev/docs/advanced/apis diff --git a/app/src/client/app/ModelsPage.tsx b/app/src/client/app/ModelsPage.tsx index c34cb6a..eda798f 100644 --- a/app/src/client/app/ModelsPage.tsx +++ b/app/src/client/app/ModelsPage.tsx @@ -1,10 +1,12 @@ import { useState } from 'react'; +import { getModels, useQuery, updateUserModels } from 'wasp/client/operations'; + import CustomLayout from './layout/CustomLayout'; import CustomBreadcrumb from '../components/CustomBreadcrumb'; import Button from '../components/Button'; import DynamicFormBuilder from '../components/DynamicFormBuilder'; import Loader from '../admin/common/Loader'; -import { getModels } from '../services/modelService'; +import { getAvailableModels } from '../services/modelService'; import { ModelSchema, JsonSchema } from '../interfaces/models'; import ModelFormContainer from '../components/ModelFormContainer'; import NotificationBox from '../components/NotificationBox'; @@ -15,11 +17,14 @@ const ModelsPage = () => { const [selectedModel, setSelectedModel] = useState(''); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(null); + const [showAddModel, setShowAddModel] = useState(false); + const { data: modelsList, refetch: refetchModels } = useQuery(getModels); const fetchData = async () => { + setShowAddModel(true); setIsLoading(true); try { - const response = await getModels(); + const response = await getAvailableModels(); setModelsSchema(response); setInitialModelSchema(response.schemas[0].json_schema); setSelectedModel(response.schemas[0].name); @@ -42,8 +47,10 @@ const ModelsPage = () => { } }; - const onSuccessCallback = (data: any) => { - console.log('Form submitted with data:', data); + const onSuccessCallback = async (data: any) => { + await updateUserModels({ data }); + refetchModels(); + setShowAddModel(false); }; return ( @@ -57,17 +64,26 @@ const ModelsPage = () => {