Skip to content

Commit

Permalink
Merge pull request #204 from polywrap/handle-no-results
Browse files Browse the repository at this point in the history
feat: handle no results found
  • Loading branch information
dOrgJelli committed Feb 20, 2024
2 parents 984fb8b + edbffe2 commit 4663213
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 8 deletions.
26 changes: 18 additions & 8 deletions web/app/s/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Disclaimer from "@/components/Disclaimer";
import RealtimeLogs from "@/components/RealtimeLogs";
import Strategy from "@/components/Strategy";
import NoResultsFound from "@/components/NoResultsFound";
import {
StrategiesWithProjects,
Application,
Expand Down Expand Up @@ -107,12 +108,21 @@ export default async function StrategyPage({
const uniqueNetworks = Array.from(
new Set(strategies.map((x) => x.networks).flat())
);
return (
<Strategy
fetchedStrategies={strategies}
prompt={run.data.prompt}
runId={run.data.id}
networks={uniqueNetworks}
/>
);

if (strategies.length > 0) {
return (
<Strategy
fetchedStrategies={strategies}
prompt={run.data.prompt}
runId={run.data.id}
networks={uniqueNetworks}
/>
);
} else {
return (
<NoResultsFound
prompt={run.data.prompt}
/>
);
}
}
58 changes: 58 additions & 0 deletions web/components/NoResultsFound.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"use client";

import { useState } from "react";
import TextField from "./TextField";
import { useRouter } from "next/navigation";
import useSession from "@/hooks/useSession";
import { startRun } from "@/app/actions";
import ChatInputButton from "./ChatInputButton";

export default function NoResultsFound(props: {
prompt: string;
}) {
const [currentPrompt, setCurrentPrompt] = useState<string>(props.prompt);
const [isRegenerating, setIsRegenerating] = useState(false);
const { data: session } = useSession();
const router = useRouter();

async function regenerateStrat(prompt: string) {
setIsRegenerating(true);
if (!session) {
throw new Error("User needs to have a session");
}
const response = await startRun(prompt, session.supabaseAccessToken);
router.push(`/s/${response.runId}`);
setIsRegenerating(false);
}

return (
<>
<div className='flex justify-center py-10 px-6 flex-grow flex-column'>
<div className='flex flex-col mx-auto max-w-wrapper w-full space-y-4'>
<TextField
label={`No results found for ${props.prompt}, try again...`}
value={currentPrompt}
onChange={(e) => setCurrentPrompt(e.target.value)}
onKeyDown={(e) => {
if (e.key === "Enter" && !!currentPrompt) {
regenerateStrat(currentPrompt);
}
}}
rightAdornment={
<ChatInputButton
running={isRegenerating}
message={currentPrompt}
regenerate
handleSend={async () => {
if (currentPrompt) {
await regenerateStrat(currentPrompt);
}
}}
/>
}
/>
</div>
</div>
</>
)
}

0 comments on commit 4663213

Please sign in to comment.