Skip to content

Commit 2b5f2bb

Browse files
committed
fix: pagination — clamp go-to-page, guard next page, cache column details, page loading indicator
1 parent 01f6be6 commit 2b5f2bb

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

TableProMobile/TableProMobile/Views/DataBrowserView.swift

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ struct DataBrowserView: View {
1919
@State private var columnDetails: [ColumnInfo] = []
2020
@State private var rows: [[String?]] = []
2121
@State private var isLoading = true
22+
@State private var isPageLoading = false
2223
@State private var appError: AppError?
2324
@State private var pagination = PaginationState(pageSize: 100, currentPage: 0)
2425
@State private var showInsertSheet = false
@@ -144,6 +145,10 @@ struct DataBrowserView: View {
144145
}
145146
}
146147
.listStyle(.insetGrouped)
148+
.opacity(isPageLoading ? 0.5 : 1)
149+
.allowsHitTesting(!isPageLoading)
150+
.overlay { if isPageLoading { ProgressView() } }
151+
.animation(.default, value: isPageLoading)
147152
.refreshable { await loadData() }
148153
}
149154

@@ -253,7 +258,9 @@ struct DataBrowserView: View {
253258
let result = try await session.driver.execute(query: query)
254259
columns = result.columns
255260
rows = result.rows
256-
columnDetails = try await session.driver.fetchColumns(table: table.name, schema: nil)
261+
if columnDetails.isEmpty {
262+
columnDetails = try await session.driver.fetchColumns(table: table.name, schema: nil)
263+
}
257264
if pagination.totalRows == nil {
258265
await fetchTotalRows(session: session)
259266
}
@@ -283,24 +290,36 @@ struct DataBrowserView: View {
283290
pagination.pageSize = newSize
284291
pagination.currentPage = 0
285292
pagination.totalRows = nil
286-
Task { await loadData() }
293+
Task { await navigatePage() }
287294
}
288295

289296
private func goToPage() {
290297
guard let page = Int(goToPageInput), page >= 1 else { return }
291-
pagination.currentPage = page - 1
292-
Task { await loadData() }
298+
if let total = pagination.totalRows {
299+
let maxPage = max(1, (total + pagination.pageSize - 1) / pagination.pageSize)
300+
pagination.currentPage = min(page - 1, maxPage - 1)
301+
} else {
302+
pagination.currentPage = page - 1
303+
}
304+
Task { await navigatePage() }
293305
}
294306

295307
private func goToNextPage() async {
308+
guard pagination.hasNextPage else { return }
296309
pagination.currentPage += 1
297-
await loadData()
310+
await navigatePage()
298311
}
299312

300313
private func goToPreviousPage() async {
301314
guard pagination.currentPage > 0 else { return }
302315
pagination.currentPage -= 1
316+
await navigatePage()
317+
}
318+
319+
private func navigatePage() async {
320+
isPageLoading = true
303321
await loadData()
322+
isPageLoading = false
304323
}
305324

306325
// MARK: - Row Operations

0 commit comments

Comments
 (0)