Skip to content

Commit f69be29

Browse files
committed
Extract refresh handling into MainContentCoordinator+Refresh extension
Fixes SwiftLint type_body_length violation (1107 > 1100 lines) by moving handleRefreshAll and handleRefresh into a separate extension file.
1 parent 030a49b commit f69be29

2 files changed

Lines changed: 80 additions & 70 deletions

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
//
2+
// MainContentCoordinator+Refresh.swift
3+
// TablePro
4+
//
5+
// Refresh handling operations for MainContentCoordinator
6+
//
7+
8+
import Foundation
9+
10+
extension MainContentCoordinator {
11+
// MARK: - Refresh Handling
12+
13+
func handleRefreshAll(
14+
hasPendingTableOps: Bool,
15+
onDiscard: @escaping () -> Void
16+
) {
17+
// If showing structure view, let it handle refresh notifications
18+
if let tabIndex = tabManager.selectedTabIndex,
19+
tabManager.tabs[tabIndex].showStructure {
20+
return
21+
}
22+
23+
let hasEditedCells = changeManager.hasChanges
24+
25+
if hasEditedCells || hasPendingTableOps {
26+
Task { @MainActor in
27+
let confirmed = await confirmDiscardChanges(action: .refreshAll)
28+
if confirmed {
29+
onDiscard()
30+
changeManager.clearChanges()
31+
NotificationCenter.default.post(name: .databaseDidConnect, object: nil)
32+
runQuery()
33+
}
34+
}
35+
} else {
36+
NotificationCenter.default.post(name: .databaseDidConnect, object: nil)
37+
runQuery()
38+
}
39+
}
40+
41+
func handleRefresh(
42+
hasPendingTableOps: Bool,
43+
onDiscard: @escaping () -> Void
44+
) {
45+
// If showing structure view, let it handle refresh notifications
46+
if let tabIndex = tabManager.selectedTabIndex,
47+
tabManager.tabs[tabIndex].showStructure {
48+
return
49+
}
50+
51+
let hasEditedCells = changeManager.hasChanges
52+
53+
if hasEditedCells || hasPendingTableOps {
54+
Task { @MainActor in
55+
let confirmed = await confirmDiscardChanges(action: .refresh)
56+
if confirmed {
57+
onDiscard()
58+
changeManager.clearChanges()
59+
// Only execute query if we're in a table tab
60+
// Query tabs should not auto-execute on refresh (use Cmd+Enter to execute)
61+
if let tabIndex = tabManager.selectedTabIndex,
62+
tabManager.tabs[tabIndex].tabType == .table {
63+
currentQueryTask?.cancel()
64+
rebuildTableQuery(at: tabIndex)
65+
runQuery()
66+
}
67+
}
68+
}
69+
} else {
70+
// Only execute query if we're in a table tab
71+
// Query tabs should not auto-execute on refresh (use Cmd+Enter to execute)
72+
if let tabIndex = tabManager.selectedTabIndex,
73+
tabManager.tabs[tabIndex].tabType == .table {
74+
currentQueryTask?.cancel()
75+
rebuildTableQuery(at: tabIndex)
76+
runQuery()
77+
}
78+
}
79+
}
80+
}

TablePro/Views/Main/MainContentCoordinator.swift

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,74 +1434,4 @@ final class MainContentCoordinator: ObservableObject {
14341434
AppState.shared.isCurrentTabEditable = false
14351435
}
14361436
}
1437-
1438-
// MARK: - Refresh Handling
1439-
1440-
func handleRefreshAll(
1441-
hasPendingTableOps: Bool,
1442-
onDiscard: @escaping () -> Void
1443-
) {
1444-
// If showing structure view, let it handle refresh notifications
1445-
if let tabIndex = tabManager.selectedTabIndex,
1446-
tabManager.tabs[tabIndex].showStructure {
1447-
return
1448-
}
1449-
1450-
let hasEditedCells = changeManager.hasChanges
1451-
1452-
if hasEditedCells || hasPendingTableOps {
1453-
Task { @MainActor in
1454-
let confirmed = await confirmDiscardChanges(action: .refreshAll)
1455-
if confirmed {
1456-
onDiscard()
1457-
changeManager.clearChanges()
1458-
NotificationCenter.default.post(name: .databaseDidConnect, object: nil)
1459-
runQuery()
1460-
}
1461-
}
1462-
} else {
1463-
NotificationCenter.default.post(name: .databaseDidConnect, object: nil)
1464-
runQuery()
1465-
}
1466-
}
1467-
1468-
func handleRefresh(
1469-
hasPendingTableOps: Bool,
1470-
onDiscard: @escaping () -> Void
1471-
) {
1472-
// If showing structure view, let it handle refresh notifications
1473-
if let tabIndex = tabManager.selectedTabIndex,
1474-
tabManager.tabs[tabIndex].showStructure {
1475-
return
1476-
}
1477-
1478-
let hasEditedCells = changeManager.hasChanges
1479-
1480-
if hasEditedCells || hasPendingTableOps {
1481-
Task { @MainActor in
1482-
let confirmed = await confirmDiscardChanges(action: .refresh)
1483-
if confirmed {
1484-
onDiscard()
1485-
changeManager.clearChanges()
1486-
// Only execute query if we're in a table tab
1487-
// Query tabs should not auto-execute on refresh (use Cmd+Enter to execute)
1488-
if let tabIndex = tabManager.selectedTabIndex,
1489-
tabManager.tabs[tabIndex].tabType == .table {
1490-
currentQueryTask?.cancel()
1491-
rebuildTableQuery(at: tabIndex)
1492-
runQuery()
1493-
}
1494-
}
1495-
}
1496-
} else {
1497-
// Only execute query if we're in a table tab
1498-
// Query tabs should not auto-execute on refresh (use Cmd+Enter to execute)
1499-
if let tabIndex = tabManager.selectedTabIndex,
1500-
tabManager.tabs[tabIndex].tabType == .table {
1501-
currentQueryTask?.cancel()
1502-
rebuildTableQuery(at: tabIndex)
1503-
runQuery()
1504-
}
1505-
}
1506-
}
15071437
}

0 commit comments

Comments
 (0)