slightly hacky prompt management

This commit is contained in:
Seth Forsgren 2022-11-24 18:32:39 -08:00
parent 89bedca20b
commit 87650b07ad
3 changed files with 39 additions and 15 deletions

View File

@ -2,18 +2,20 @@ import { NextComponentType } from 'next'
interface PromptEntryProps { interface PromptEntryProps {
prompt: string prompt: string
index: number
className: string className: string
} }
export default function PromptEntry({ export default function PromptEntry({
prompt, prompt,
index,
className, className,
}: PromptEntryProps) { }: PromptEntryProps) {
return ( return (
<> <>
<p className={className}> <p className={className}>
{prompt} {prompt == "" ? index == 5 ? "UP NEXT: Anything you want" + prompt : "..." : index == 5 ? "UP NEXT: " + prompt : prompt}
</p> </p>
</> </>
) )

View File

@ -1,18 +1,20 @@
import PromptEntry from './PromptEntry' import PromptEntry from './PromptEntry'
import { PromptInput } from "../types"; import { PromptInput } from "../types";
import {useRef} from 'react'; import { useRef } from 'react';
interface PromptPanelProps { interface PromptPanelProps {
prompts: PromptInput[]; prompts: PromptInput[];
addPrompt: (prompt: string) => void; addPrompt: (prompt: string) => void;
changeUpNextPrompt: (prompt: string) => void; changePrompt: (prompt: string, index: number) => void;
nextPrompt: () => void;
} }
export default function PromptPanel({ export default function PromptPanel({
prompts, prompts,
addPrompt, addPrompt,
changeUpNextPrompt, changePrompt,
nextPrompt,
}: PromptPanelProps) { }: PromptPanelProps) {
const inputPrompt = useRef(null); const inputPrompt = useRef(null);
@ -23,40 +25,52 @@ export default function PromptPanel({
<div className="pl-20"> <div className="pl-20">
<div className="h-[80vh] flex flex-col justify-around pt-[5vh] pr-5"> <div className="h-[80vh] flex flex-col justify-around pt-[5vh] pr-5">
{prompts.slice(-6).map((prompt, index) => ( {prompts.slice(-6).map((prompt, index) => (
<PromptEntry prompt={index == 5 ? "UP NEXT: " + prompt.prompt : prompt.prompt} className={promptEntryClassNames[index]} key={index} /> <PromptEntry prompt={prompt.prompt} className={promptEntryClassNames[index]} index={index} />
))} ))}
</div> </div>
<form onSubmit={(e) => { <form onSubmit={(e) => {
e.preventDefault(); e.preventDefault();
const prompt = e.currentTarget.prompt.value; const prompt = e.currentTarget.prompt.value;
changeUpNextPrompt(prompt); var promptLastIndex = prompts.length - 1;
if (prompts[promptLastIndex - 1].prompt == "") {
changePrompt(prompt, promptLastIndex - 1);
} else {
changePrompt(prompt, promptLastIndex);
}
inputPrompt.current.value = ''; inputPrompt.current.value = '';
}}> }}>
<input <input
className="fixed z-90 bottom-20 w-1/2 h-12 pl-3 text-xl text-black rounded-lg border-sky-400 border-4 focus:outline-none focus:border-sky-500" className="fixed z-90 bottom-20 w-1/2 h-12 pl-3 text-xl text-black rounded-lg border-sky-400 border-4 focus:outline-none focus:border-sky-500"
ref={inputPrompt} ref={inputPrompt}
type="text" type="text"
id="prompt" id="prompt"
name="prompt" name="prompt"
placeholder="What do you want to hear next?" placeholder="What do you want to hear next?"
maxLength={150} maxLength={150}
minLength={2}
required={true}
autoComplete="off" autoComplete="off"
/> />
</form> </form>
{/* Test button */}
<button title="Add" className="fixed z-90 top-48 right-8 bg-slate-100 w-14 h-14 rounded-full drop-shadow-lg"
onClick={() => nextPrompt()}
>
</button>
</div> </div>
</main> </main >
</> </>
) )
} }
// WIP manner of passing ideal font of each promptEntry based on where it is in the promptPanel. Could be done better with a map or something.
// need not just order, but some context of where we are in time, and when that prompt will be primary (some global step state)
const promptEntryClassNames = { const promptEntryClassNames = {
0: "font-light text-sm text-gray-400 text-opacity-40", 0: "font-light text-sm text-gray-400 text-opacity-40",
1: "font-normal text-m text-gray-300 text-opacity-60", 1: "font-normal text-m text-gray-300 text-opacity-60",
2: "font-medium text-xl text-gray-200 text-opacity-80", 2: "font-medium text-xl text-gray-200 text-opacity-80",
3: "font-bold text-5xl text-white", // This is the primary prompt 3: "font-bold text-5xl text-white", // This is the primary prompt
4: "font-medium text-2xl text-gray-200 text-opacity-80", // This is prompt it is transitioning to 4: "font-medium text-2xl text-gray-200 text-opacity-80", // This is prompt it is transitioning to
5: "font-normal text-m text-gray-300 text-opacity-60", 5: "font-normal text-m text-gray-300 text-opacity-60", // This is the UP NEXT prompt
} }

View File

@ -15,8 +15,8 @@ const defaultPromptInputs = [
{ prompt: "Country singer and a techno DJ"}, { prompt: "Country singer and a techno DJ"},
{ prompt: "A typewriter in they style of K-Pop"}, { prompt: "A typewriter in they style of K-Pop"},
{ prompt: "Boy band with a tropical beat "}, { prompt: "Boy band with a tropical beat "},
{ prompt: "..."}, { prompt: ""},
{ prompt: "Anything you want"}, { prompt: ""},
]; ];
const defaultInferenceResults = [ const defaultInferenceResults = [
@ -207,11 +207,19 @@ export default function Home() {
addPrompt={(prompt: string) => { addPrompt={(prompt: string) => {
setPromptInputs([...promptInputs, { prompt: prompt }]); setPromptInputs([...promptInputs, { prompt: prompt }]);
}} }}
changeUpNextPrompt={(prompt: string) => { changePrompt={(prompt: string, index: number) => {
const newPromptInputs = [...promptInputs]; const newPromptInputs = [...promptInputs];
newPromptInputs[newPromptInputs.length - 1].prompt = prompt; newPromptInputs[index].prompt = prompt;
setPromptInputs(newPromptInputs); setPromptInputs(newPromptInputs);
}} }}
nextPrompt={() => {
// if there are no upcoming prompts, don't do anything
var promptLastIndex = promptInputs.length - 1;
if (promptInputs[promptLastIndex].prompt == "" && promptInputs[promptLastIndex-1].prompt == "") {
return;
}
setPromptInputs([...promptInputs, { prompt: "" }]);
}}
/> />
<Info /> <Info />