lushdog@outlook.com 4 tygodni temu
rodzic
commit
9c0b73ae41
1 zmienionych plików z 34 dodań i 32 usunięć
  1. 34 32
      src/app/components/DataTable.tsx

+ 34 - 32
src/app/components/DataTable.tsx

@@ -66,7 +66,7 @@ function DataTableContent() {
 	const [data, setData] = useState<TableData[]>([])
 	const [loading, setLoading] = useState(true)
 	const [poolOptions, setPoolOptions] = useState<PoolOption[]>([])
-	const [quickCopyAmount, setQuickCopyAmount] = useState<number>(0)
+	const [quickCopyAmount, setQuickCopyAmount] = useState<number>(1)
 
 	const [selectedPoolAddress, setSelectedPoolAddress] = useState<string>(
 		'FPBW9dtVRoUug2BeUKZAzaknd6iiet9jHM8RcTvwUkyC'
@@ -388,42 +388,44 @@ function DataTableContent() {
 	) => {
 		let currentSortField = sortField
 		let shouldResetPage = false
+		if (newPagination.current && newPagination.current !== pagination.current) {
+			const targetPage = newPagination.current
+			const targetPageSize = newPagination.pageSize || pagination.pageSize
+			setPagination({
+				...pagination,
+				current: targetPage,
+				pageSize: targetPageSize,
+			})
 
-		if (sorter && typeof sorter === 'object' && 'field' in sorter) {
-			const sorterObj = sorter as {
-				field?: string
-				order?: 'ascend' | 'descend' | null
-			}
-			if (sorterObj.field && sorterObj.order) {
-				// 映射字段名到 API 的 sortField
-				const fieldMap: Record<string, string> = {
-					copies: 'copies',
-					earnedUsd: 'earnedUsd',
-					pnlUsd: 'pnlUsd',
-					liquidityUsd: 'liquidity',
-					positionAgeMs: 'positionAgeMs',
+			fetchData(
+				targetPage,
+				targetPageSize,
+				selectedPoolAddress,
+				currentSortField
+			)
+		} else {
+			if (sorter && typeof sorter === 'object' && 'field' in sorter) {
+				const sorterObj = sorter as {
+					field?: string
+					order?: 'ascend' | 'descend' | null
 				}
-				const newSortField = fieldMap[sorterObj.field] || sortField
-				if (newSortField !== sortField) {
-					currentSortField = newSortField
-					shouldResetPage = true
+				if (sorterObj.field && sorterObj.order) {
+					// 映射字段名到 API 的 sortField
+					const fieldMap: Record<string, string> = {
+						copies: 'copies',
+						earnedUsd: 'earnedUsd',
+						pnlUsd: 'pnlUsd',
+						liquidityUsd: 'liquidity',
+						positionAgeMs: 'positionAgeMs',
+					}
+					const newSortField = fieldMap[sorterObj.field] || sortField
+					if (newSortField !== sortField) {
+						currentSortField = newSortField
+						shouldResetPage = true
+					}
 				}
 			}
-			return
 		}
-
-		setSortField(currentSortField)
-		const targetPage = shouldResetPage
-			? 1
-			: newPagination.current || pagination.current
-		const targetPageSize = newPagination.pageSize || pagination.pageSize
-		setPagination({
-			...pagination,
-			current: targetPage,
-			pageSize: targetPageSize,
-		})
-
-		fetchData(targetPage, targetPageSize, selectedPoolAddress, currentSortField)
 	}
 
 	const handlePoolChange = (value: string) => {