fix: Ask-AI history list reversed when loading answer (#1301)

pull/1306/head
Xiang Jaywhen 2 years ago committed by GitHub
parent 008d6a0c81
commit daa1e9edfb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,5 +1,4 @@
import { Button, Textarea } from "@mui/joy";
import { reverse } from "lodash-es";
import { useEffect, useState } from "react";
import * as api from "../helpers/api";
import useLoading from "../hooks/useLoading";
@ -60,11 +59,11 @@ const AskAIDialog: React.FC<Props> = (props: Props) => {
data: { data: answer },
} = await api.postChatCompletion(question);
setHistoryList([
...historyList,
{
question,
answer: answer.replace(/^\n\n/, ""),
},
...historyList,
]);
};
@ -86,7 +85,7 @@ const AskAIDialog: React.FC<Props> = (props: Props) => {
<Icon.Loader className="w-5 h-auto animate-spin" />
</p>
)}
{reverse(historyList).map((history, index) => (
{historyList.map((history, index) => (
<div key={index} className="w-full flex flex-col justify-start items-start mt-4 space-y-2">
<div className="w-full flex flex-row justify-start items-start pr-6">
<span className="word-break rounded shadow px-3 py-2 opacity-80 bg-gray-100 dark:bg-zinc-700">{history.question}</span>

Loading…
Cancel
Save