Skip to content

Commit

Permalink
feat: #153 while going to previous question, previous answer should a…
Browse files Browse the repository at this point in the history
…lso auto-filled in input
  • Loading branch information
growupanand committed Jan 22, 2024
1 parent 55aaed6 commit f8c2b15
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/components/formSubmissionPage/formFields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const FormFieldsViewer = ({
<form onSubmit={handleFormSubmit}>
<div className={cn("py-3", isFirstQuestion && "hidden")}>
<Button
type="button"
variant="ghost"
className={cn("rounded-full", montserrat.className)}
size="sm"
Expand Down
13 changes: 11 additions & 2 deletions src/components/formSubmissionPage/formViewer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { useEffect, useState } from "react";
import { ChangeEvent, useEffect, useState } from "react";
import { Form } from "@prisma/client";
import { useChat } from "ai/react";

Expand Down Expand Up @@ -92,9 +92,18 @@ export function FormViewer({ form, refresh, isPreview }: Props) {
};

const handleShowPreviousQuestion = () => {
// Remove previous question message from messages list
messages.pop();
messages.pop();
// Remove previous answer message from messages list
const previousAnswerMessage = messages.pop();
setMessages(messages);
// Set previous answer in text input
const event = {
target: {
value: previousAnswerMessage?.content || "",
},
} as ChangeEvent<HTMLTextAreaElement>;
handleInputChange(event);
};

useEffect(() => {
Expand Down

0 comments on commit f8c2b15

Please sign in to comment.