| 
									
										
										
										
											2023-07-07 10:35:05 +08:00
										 |  |  | 'use client' | 
					
						
							|  |  |  | import type { FC } from 'react' | 
					
						
							|  |  |  | import React from 'react' | 
					
						
							|  |  |  | import { useTranslation } from 'react-i18next' | 
					
						
							| 
									
										
										
										
											2024-06-20 11:05:08 +08:00
										 |  |  | import { | 
					
						
							|  |  |  |   RiLoader2Line, | 
					
						
							| 
									
										
										
										
											2025-03-03 14:44:51 +08:00
										 |  |  |   RiPlayLargeLine, | 
					
						
							| 
									
										
										
										
											2024-06-20 11:05:08 +08:00
										 |  |  | } from '@remixicon/react' | 
					
						
							| 
									
										
										
										
											2023-07-07 10:35:05 +08:00
										 |  |  | import CSVReader from './csv-reader' | 
					
						
							|  |  |  | import CSVDownload from './csv-download' | 
					
						
							|  |  |  | import Button from '@/app/components/base/button' | 
					
						
							| 
									
										
										
										
											2025-03-03 14:44:51 +08:00
										 |  |  | import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints' | 
					
						
							|  |  |  | import cn from '@/utils/classnames' | 
					
						
							| 
									
										
										
										
											2023-07-07 10:35:05 +08:00
										 |  |  | export type IRunBatchProps = { | 
					
						
							|  |  |  |   vars: { name: string }[] | 
					
						
							|  |  |  |   onSend: (data: string[][]) => void | 
					
						
							| 
									
										
										
										
											2023-09-25 10:20:50 +08:00
										 |  |  |   isAllFinished: boolean | 
					
						
							| 
									
										
										
										
											2023-07-07 10:35:05 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const RunBatch: FC<IRunBatchProps> = ({ | 
					
						
							|  |  |  |   vars, | 
					
						
							|  |  |  |   onSend, | 
					
						
							| 
									
										
										
										
											2023-09-25 10:20:50 +08:00
										 |  |  |   isAllFinished, | 
					
						
							| 
									
										
										
										
											2023-07-07 10:35:05 +08:00
										 |  |  | }) => { | 
					
						
							|  |  |  |   const { t } = useTranslation() | 
					
						
							| 
									
										
										
										
											2025-03-03 14:44:51 +08:00
										 |  |  |   const media = useBreakpoints() | 
					
						
							|  |  |  |   const isPC = media === MediaType.pc | 
					
						
							| 
									
										
										
										
											2023-07-07 10:35:05 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   const [csvData, setCsvData] = React.useState<string[][]>([]) | 
					
						
							|  |  |  |   const [isParsed, setIsParsed] = React.useState(false) | 
					
						
							|  |  |  |   const handleParsed = (data: string[][]) => { | 
					
						
							|  |  |  |     setCsvData(data) | 
					
						
							|  |  |  |     // console.log(data)
 | 
					
						
							|  |  |  |     setIsParsed(true) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const handleSend = () => { | 
					
						
							|  |  |  |     onSend(csvData) | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2025-03-03 14:44:51 +08:00
										 |  |  |   const Icon = isAllFinished ? RiPlayLargeLine : RiLoader2Line | 
					
						
							| 
									
										
										
										
											2023-07-07 10:35:05 +08:00
										 |  |  |   return ( | 
					
						
							|  |  |  |     <div className='pt-4'> | 
					
						
							|  |  |  |       <CSVReader onParsed={handleParsed} /> | 
					
						
							|  |  |  |       <CSVDownload vars={vars} /> | 
					
						
							|  |  |  |       <div className='flex justify-end'> | 
					
						
							|  |  |  |         <Button | 
					
						
							| 
									
										
										
										
											2024-06-19 14:13:16 +08:00
										 |  |  |           variant="primary" | 
					
						
							| 
									
										
										
										
											2025-03-03 14:44:51 +08:00
										 |  |  |           className={cn('mt-4 pl-3 pr-4', !isPC && 'grow')} | 
					
						
							| 
									
										
										
										
											2023-07-07 10:35:05 +08:00
										 |  |  |           onClick={handleSend} | 
					
						
							| 
									
										
										
										
											2023-09-25 10:20:50 +08:00
										 |  |  |           disabled={!isParsed || !isAllFinished} | 
					
						
							| 
									
										
										
										
											2023-07-07 10:35:05 +08:00
										 |  |  |         > | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |           <Icon className={cn(!isAllFinished && 'animate-spin', 'mr-1 h-4 w-4 shrink-0')} aria-hidden="true" /> | 
					
						
							|  |  |  |           <span className='text-[13px] uppercase'>{t('share.generation.run')}</span> | 
					
						
							| 
									
										
										
										
											2023-07-07 10:35:05 +08:00
										 |  |  |         </Button> | 
					
						
							|  |  |  |       </div> | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | export default React.memo(RunBatch) |