diff --git a/wasp-ai/main.wasp b/wasp-ai/main.wasp index 22f9e6f6d..43b362538 100644 --- a/wasp-ai/main.wasp +++ b/wasp-ai/main.wasp @@ -42,10 +42,6 @@ app waspAi { userEntity: User, externalAuthEntity: SocialLogin, methods: { - gitHub: { - configFn: import { getGitHubAuthConfig } from "@server/auth.js", - getUserFieldsFn: import { getGitHubUserFields } from "@server/auth.js", - }, google: { configFn: import { getGoogleAuthConfig } from "@server/auth.js", getUserFieldsFn: import { getGoogleUserFields } from "@server/auth.js", diff --git a/wasp-ai/src/client/components/Header.jsx b/wasp-ai/src/client/components/Header.jsx index 55e73ff53..c61ab1fc4 100644 --- a/wasp-ai/src/client/components/Header.jsx +++ b/wasp-ai/src/client/components/Header.jsx @@ -1,7 +1,5 @@ import { StatusPill } from './StatusPill'; import { Title } from './Title'; -import { signInUrl as gitHubSignInUrl } from '@wasp/auth/helpers/GitHub'; -import { AiFillGithub } from 'react-icons/ai'; export function Header({ currentStatus, isStatusVisible }) { return ( @@ -14,12 +12,4 @@ export function Header({ currentStatus, isStatusVisible }) { )} ); -} - -function GithubLoginButton() { - return ( - - ) } \ No newline at end of file diff --git a/wasp-ai/src/client/pages/MainPage.jsx b/wasp-ai/src/client/pages/MainPage.jsx index de67c6314..34717a2d6 100644 --- a/wasp-ai/src/client/pages/MainPage.jsx +++ b/wasp-ai/src/client/pages/MainPage.jsx @@ -14,7 +14,7 @@ import { MyDialog } from "../components/Dialog"; const MainPage = () => { const [appName, setAppName] = useState(""); const [appDesc, setAppDesc] = useState(""); - const [isGhModalOpen, setIsGhModalOpen] = useState(false); + const [isPowerUserModalOpen, setIsPowerUserModalOpen] = useState(false); const [currentStatus, setCurrentStatus] = useState({ status: "idle", message: "Waiting for instructions", @@ -78,7 +78,7 @@ const MainPage = () => { localStorage.setItem("appNum", 0); } if (appNum === 2) { - setIsGhModalOpen(true); + setIsPowerUserModalOpen(true); } if (appDetails) { setAppName(appDetails.appName); @@ -151,7 +151,7 @@ const MainPage = () => {
- +
@@ -188,64 +188,38 @@ The simpler and more specific the app is, the better the generated app will be."
-
-
-
-
-

- Some example ideas -

+

Some example ideas

{exampleIdeas.map((idea) => ( ))}
- +
@@ -253,9 +227,9 @@ The simpler and more specific the app is, the better the generated app will be." }; export default MainPage; -export function GhModal({ isGhModalOpen, setIsGhModalOpen }) { +export function PowerUserModal({ isOpen, setIsOpen }) { return ( - setIsGhModalOpen(false)} title={With Great Power Comes Great Responsibility! 🧙}> + setIsOpen(false)} title={With Great Power Comes Great Responsibility! 🧙}>

We've made this tool completely free and cover all the costs 😇 diff --git a/wasp-ai/src/client/pages/ResultPage.jsx b/wasp-ai/src/client/pages/ResultPage.jsx index 04ddb69cb..e72dc5efe 100644 --- a/wasp-ai/src/client/pages/ResultPage.jsx +++ b/wasp-ai/src/client/pages/ResultPage.jsx @@ -34,7 +34,8 @@ const jsConfetti = new JSConfetti(); export const ResultPage = () => { const { appId } = useParams(); const [generationDone, setGenerationDone] = useState(false); - const [isStarRepoOpen, setIsStarRepoOpen] = useState(false); + const [isRunning, setIsRunning] = useState(false); + const [isSuccessModalOpen, setIsSuccessModalOpen] = useState(false); const { data: appGenerationResult, isError, @@ -46,7 +47,7 @@ export const ResultPage = () => { ); const [activeFilePath, setActiveFilePath] = useState(null); const [currentStatus, setCurrentStatus] = useState({ - status: "idle", + status: "idle", message: "Waiting", }); const [currentFiles, setCurrentFiles] = useState({}); @@ -73,10 +74,16 @@ export const ResultPage = () => { }, [appId]); useEffect(() => { - if (currentStatus.status === "success") { - setIsStarRepoOpen(true); + const currentAppStatus = appGenerationResult?.project?.status; + if (currentAppStatus === "in-progress") { + setIsRunning(true) + } else if (currentAppStatus === "success" && isRunning) { + setIsSuccessModalOpen(true) + setIsRunning(false) + } else if (isRunning) { + setIsRunning(false) } - }, [currentStatus]) + }, [appGenerationResult?.project?.status]) const logs = appGenerationResult?.project?.logs.map((log) => log.content); @@ -217,7 +224,7 @@ export const ResultPage = () => { currentStatus={currentStatus} isStatusVisible={!!appGenerationResult?.project} /> - + {isError && (

@@ -406,59 +413,71 @@ function getCardinalNumber(number) { } } -export function StarOurRepoModal({ isStarRepoOpen, setIsStarRepoOpen, appGenerationResult }) { - const [tokens, setTokens] = useState(0) - const { data: numTotalProjects } = useQuery(getNumProjects, {}, { enabled: isStarRepoOpen }) - - const tokenNumberStr = appGenerationResult?.project?.logs?.filter(log => log.content.toLowerCase().includes("tokens usage") === true)[0]?.content.split(':')[1]?.trim() +export function OnSuccessModal({ isOpen, setIsOpen, appGenerationResult }) { + const [numTokensSpent, setNumTokensSpent] = useState(0) + const { data: numTotalProjects } = useQuery(getNumProjects, {}, { enabled: isOpen }) useEffect(() => { - if (!!tokenNumberStr) { - const num = tokenNumberStr.slice(1, -1) * 1000 - setTokens(num) + const logText = appGenerationResult?.project?.logs?.find((log) => /tokens usage/i.test(log.content))?.content; + const tokenNumberStr = logText ? logText.split(":")[1]?.trim() : null; + if (tokenNumberStr) { + const num = Number(tokenNumberStr.replace(/[\s~k]/gi, '')) * 1000; + if (num.toString().match(/^[0-9]+$/)) { + setNumTokensSpent(num); + } } - }, [tokenNumberStr]) + }, [appGenerationResult]); useEffect(() => { - if (isStarRepoOpen) { + if (isOpen) { jsConfetti.addConfetti({ emojis: ['🐝'], emojiSize: 120, }) } - }, [isStarRepoOpen]) + }, [isOpen]) + + function FormattedText({ children }) { + return {children}; + } + return ( - setIsStarRepoOpen(false)} title={Your App is Ready! 🎉}> + setIsOpen(false)} title={Your App is Ready! 🎉}>

We've made this tool completely free and cover all the costs 😇

- - {/* */} - - - - - - - - - {numTotalProjects && ( - - - - - )} -
Fun Stats
Number of tokens your app used: - {" "} - {tokens.toLocaleString(2) ?? "~22k"}{" "} -
Cost to generate your app: - {" "} - {tokens ? `$${((tokens / 1000) * 0.004).toFixed(2)}` : "~ $0.50"}{" "} -
Total number of apps generated with Mage: - {" "} - {numTotalProjects.toLocaleString()}{" "} -
+ {numTokensSpent && ( + + + + + + + + + + + {numTotalProjects && ( + + + + + )} + +
Number of tokens your app used: + {" "} + {numTokensSpent.toLocaleString()}{" "} +
Cost to generate your app: + {" "} + + {`$${((Number(numTokensSpent) / 1000) * 0.004).toFixed(2)}`} + {" "} +
Total number of apps generated with Mage: + {" "} + {numTotalProjects.toLocaleString()}{" "} +
+ )}

But you can still show your support by starring us on GitHub:

@@ -478,15 +497,9 @@ export function StarOurRepoModal({ isStarRepoOpen, setIsStarRepoOpen, appGenerat

We'd very much appreciate it! 🧙

- ) + ); } -function FormattedText({ children }) { - return ( - {children} - ) -} - export default function RunTheAppModal({ disabled, onDownloadZip }) { const [showModal, setShowModal] = useState(false); return ( diff --git a/wasp-ai/src/server/auth.ts b/wasp-ai/src/server/auth.ts index b54419310..ede5df730 100644 --- a/wasp-ai/src/server/auth.ts +++ b/wasp-ai/src/server/auth.ts @@ -13,19 +13,3 @@ export const getGoogleAuthConfig = () => { scope: ["profile", "email"], }; }; - - -export const getGitHubUserFields: GetUserFieldsFn = async (_context, args) => { - // NOTE: if we don't want to access users' emails, we can use scope ["user:read"] - // instead of ["user"] and access args.profile.username instead - const email = args.profile.emails[0].value; - return { email }; -}; - -export function getGitHubAuthConfig() { - return { - clientID: process.env.GITHUB_CLIENT_ID, // look up from env or elsewhere - clientSecret: process.env.GITHUB_CLIENT_SECRET, // look up from env or elsewhere - scope: ["user"], - }; -} \ No newline at end of file diff --git a/wasp-ai/src/server/operations.ts b/wasp-ai/src/server/operations.ts index 7dcd91a43..f266697f6 100644 --- a/wasp-ai/src/server/operations.ts +++ b/wasp-ai/src/server/operations.ts @@ -225,9 +225,7 @@ export const getStats = (async (_args, context) => { }) satisfies GetStats<{}>; export const getNumProjects = (async (_args, context) => { - const { Project } = context.entities; - const numProjects = await Project.count(); - return numProjects; + return context.entities.Project.count(); }) satisfies GetNumProjects<{}>; function getDownloadStats(projects: Project[]) {