Skip to content

Commit

Permalink
Page fixing update
Browse files Browse the repository at this point in the history
  • Loading branch information
infomiho committed Jun 29, 2023
1 parent 88a8f6a commit c209077
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 26 deletions.
10 changes: 6 additions & 4 deletions wasp-ai/src/client/pages/MainPage.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from "react";
import { useState, useMemo } from "react";
import startGeneratingNewApp from "@wasp/actions/startGeneratingNewApp";
import { StatusPill } from "../components/StatusPill";
import { useHistory } from "react-router-dom";
Expand Down Expand Up @@ -55,9 +55,11 @@ const MainPage = () => {
},
];
// Pick random 3 ideas
const ideasToDisplay = poolOfExampleIdeas
.sort(() => Math.random() - Math.random())
.slice(0, 3);
const ideasToDisplay = useMemo(
() =>
poolOfExampleIdeas.sort(() => Math.random() - Math.random()).slice(0, 3),
[]
);

function useIdea(idea) {
setAppName(idea.name);
Expand Down
2 changes: 1 addition & 1 deletion waspc/src/Wasp/AI/GenerateNewProject.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ generateNewProject newProjectDetails waspProjectSkeletonFiles = do

writeToLog "Fixing any mistakes in pages..."
forM_ (getPageComponentPath <$> pages) $ \pageFp -> do
fixPageComponent newProjectDetails waspFilePath pageFp actions queries
fixPageComponent newProjectDetails waspFilePath pageFp
writeToLog $ T.pack $ "Fixed '" <> pageFp <> "' page."
writeToLog "Pages fixed."

Expand Down
39 changes: 18 additions & 21 deletions waspc/src/Wasp/AI/GenerateNewProject/PageComponentFile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ import Wasp.AI.GenerateNewProject.Common
)
import Wasp.AI.GenerateNewProject.Common.Prompts (appDescriptionBlock)
import qualified Wasp.AI.GenerateNewProject.Common.Prompts as Prompts
import Wasp.AI.GenerateNewProject.Operation (Operation)
import Wasp.AI.GenerateNewProject.Page (operationInfo, pageDocPrompt)
import Wasp.AI.GenerateNewProject.Page (pageDocPrompt)
import Wasp.AI.OpenAI.ChatGPT (ChatMessage (..), ChatRole (..))

fixPageComponent :: NewProjectDetails -> FilePath -> FilePath -> [Operation] -> [Operation] -> CodeAgent ()
fixPageComponent newProjectDetails waspFilePath pageComponentPath actions queries = do
fixPageComponent :: NewProjectDetails -> FilePath -> FilePath -> CodeAgent ()
fixPageComponent newProjectDetails waspFilePath pageComponentPath = do
currentWaspFileContent <- fromMaybe (error "couldn't find wasp file") <$> getFile waspFilePath
currentPageComponentContent <- fromMaybe (error "couldn't find page file to fix") <$> getFile pageComponentPath
fixedPageComponent <-
Expand All @@ -35,9 +34,6 @@ fixPageComponent newProjectDetails waspFilePath pageComponentPath actions querie
]
writeToFile pageComponentPath (const $ pageComponentImpl fixedPageComponent)
where
actionsInfo = T.intercalate "\n" $ (" - " <>) . operationInfo <$> actions
queriesInfo = T.intercalate "\n" $ (" - " <>) . operationInfo <$> queries

fixPageComponentPrompt currentWaspFileContent currentPageContent =
[trimming|
${basicWaspLangInfoPrompt}
Expand All @@ -48,11 +44,6 @@ fixPageComponent newProjectDetails waspFilePath pageComponentPath actions querie

We are together building a new Wasp app (description at the end of prompt).

Here is a wasp file that we generated together so far:
```wasp
${currentWaspFileContent}
```

Here is a React component (${pageComponentPathText}) containing some frontend code
that we generated together earlier:
```js
Expand All @@ -61,24 +52,30 @@ fixPageComponent newProjectDetails waspFilePath pageComponentPath actions querie

===============

The NodeJS file with operations likely has some mistakes: let's fix it!
The React component probably has some mistakes: let's fix it!

Some common mistakes to look for:
- Make sure to use only queries and actions that are defined in the Wasp file (listed below)
- You should import queries from "@wasp/queries/{queryName}" like import getTask from '@wasp/queries/getTasks';
- You should import actions from "@wasp/actions/{actionName}" like import createTask from '@wasp/actions/createTask';
- Make sure to use only queries and actions that are defined in the Wasp file (listed below)!
- You should import queries from "@wasp/queries/{queryName}" like
```
import getTask from '@wasp/queries/getTasks';
```
- You should import actions from "@wasp/actions/{actionName}" like
```
import createTask from '@wasp/actions/createTask';
```
- Don't use `useAction` or `useMutation`! Use actions directly.
- Use Tailwind CSS to style the page if you didn't.
- Use <Link /> component from "react-router-dom" to link to other pages where needed.
- "TODO" comments or "..." that should be replaced with actual implementation.
Fix these by replacing them with actual implementation.
- Duplicate imports. If there are any, make sure to remove them.
- There might be some invalid JS or JSX syntax -> fix it if there is any.

Actions:
${actionsInfo}

Queries:
${queriesInfo}
Here is the Wasp file to help you:
```wasp
${currentWaspFileContent}
```

With this in mind, generate a new, fixed React component (${pageComponentPathText}).
Do actual fixes, don't leave comments with "TODO"!
Expand Down

0 comments on commit c209077

Please # to comment.