|
2 | 2 |
|
3 | 3 | import { CreatePrompt } from "@/components/project/dataset/create-data"; |
4 | 4 | import { EditPrompt } from "@/components/project/dataset/edit-data"; |
| 5 | +import { Spinner } from "@/components/shared/spinner"; |
5 | 6 | import { Button } from "@/components/ui/button"; |
6 | 7 | import { Separator } from "@/components/ui/separator"; |
7 | 8 | import { ChevronLeft } from "lucide-react"; |
8 | 9 | import { useParams } from "next/navigation"; |
9 | | -import { useQuery } from "react-query"; |
10 | 10 | import { useState } from "react"; |
11 | | -import { useBottomScrollListener } from 'react-bottom-scroll-listener'; |
12 | | -import { Spinner } from '@/components/shared/spinner'; |
| 11 | +import { useBottomScrollListener } from "react-bottom-scroll-listener"; |
| 12 | +import { useQuery } from "react-query"; |
13 | 13 |
|
14 | 14 | export default function Promptset() { |
15 | 15 | const promptset_id = useParams()?.promptset_id as string; |
@@ -39,19 +39,22 @@ export default function Promptset() { |
39 | 39 | return result; |
40 | 40 | }, |
41 | 41 | onSuccess: (result) => { |
42 | | - if (totalPages !== result.metadata.total_pages) { |
43 | | - setTotalPages(result.metadata.total_pages); |
| 42 | + if (totalPages !== result?.metadata?.total_pages) { |
| 43 | + setTotalPages(result?.metadata?.total_pages); |
44 | 44 | } |
45 | 45 | if (result) { |
46 | 46 | if (data) { |
47 | | - setData((prevData: any) => [...prevData, ...result.promptsets.Prompt]); |
| 47 | + setData((prevData: any) => [ |
| 48 | + ...prevData, |
| 49 | + ...result.promptsets.Prompt, |
| 50 | + ]); |
48 | 51 | } else { |
49 | 52 | setData(result.promptsets.Prompt); |
50 | 53 | } |
51 | 54 | } |
52 | 55 | setPage((currentPage) => currentPage + 1); |
53 | 56 | setShowLoader(false); |
54 | | - } |
| 57 | + }, |
55 | 58 | }); |
56 | 59 |
|
57 | 60 | if (fetchPromptset.isLoading || !fetchPromptset.data || !data) { |
@@ -82,29 +85,24 @@ export default function Promptset() { |
82 | 85 | </div> |
83 | 86 | )} |
84 | 87 | {fetchPromptset.data?.promptsets && |
85 | | - data.map( |
86 | | - (prompt: any, i: number) => { |
87 | | - return ( |
88 | | - <div className="flex flex-col" key={i}> |
89 | | - <div className="grid grid-cols-5 items-start justify-stretch gap-3 py-3 px-4"> |
90 | | - <p className="text-xs">{prompt.createdAt}</p> |
91 | | - <p className="text-xs">{prompt.value}</p> |
92 | | - <p className="text-xs text-end">{prompt.note}</p> |
93 | | - <div className="text-end"> |
94 | | - <EditPrompt |
95 | | - prompt={prompt} |
96 | | - promptSetId={promptset_id} |
97 | | - /> |
98 | | - </div> |
| 88 | + data.map((prompt: any, i: number) => { |
| 89 | + return ( |
| 90 | + <div className="flex flex-col" key={i}> |
| 91 | + <div className="grid grid-cols-5 items-start justify-stretch gap-3 py-3 px-4"> |
| 92 | + <p className="text-xs">{prompt.createdAt}</p> |
| 93 | + <p className="text-xs">{prompt.value}</p> |
| 94 | + <p className="text-xs text-end">{prompt.note}</p> |
| 95 | + <div className="text-end"> |
| 96 | + <EditPrompt prompt={prompt} promptSetId={promptset_id} /> |
99 | 97 | </div> |
100 | | - <Separator orientation="horizontal" /> |
101 | 98 | </div> |
102 | | - ); |
103 | | - } |
104 | | - )} |
105 | | - {showLoader && ( |
106 | | - <div className='flex justify-center py-8'> |
107 | | - <Spinner className='h-8 w-8 text-center' /> |
| 99 | + <Separator orientation="horizontal" /> |
| 100 | + </div> |
| 101 | + ); |
| 102 | + })} |
| 103 | + {showLoader && ( |
| 104 | + <div className="flex justify-center py-8"> |
| 105 | + <Spinner className="h-8 w-8 text-center" /> |
108 | 106 | </div> |
109 | 107 | )} |
110 | 108 | </div> |
|
0 commit comments