Skip to content

Commit 6c179bc

Browse files
committed
initial setup fixes
1 parent 13b17ad commit 6c179bc

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

Django Files/Django_FilesApp.swift

+26-2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ struct Django_FilesApp: App {
4949
}()
5050

5151
@StateObject private var sessionManager = SessionManager()
52+
@State private var hasExistingSessions = false
5253

5354
init() {
5455
// Handle reset arguments
@@ -83,8 +84,19 @@ struct Django_FilesApp: App {
8384

8485
var body: some Scene {
8586
WindowGroup {
86-
// ContentView()
87-
TabViewWindow(sessionManager: sessionManager)
87+
Group {
88+
if hasExistingSessions {
89+
TabViewWindow(sessionManager: sessionManager)
90+
} else {
91+
SessionEditor(session: nil, onSessionCreated: { newSession in
92+
sessionManager.selectedSession = newSession
93+
hasExistingSessions = true
94+
})
95+
.onAppear {
96+
checkForExistingSessions()
97+
}
98+
}
99+
}
88100
}
89101
.modelContainer(sharedModelContainer)
90102
#if os(macOS)
@@ -93,4 +105,16 @@ struct Django_FilesApp: App {
93105
}
94106
#endif
95107
}
108+
109+
private func checkForExistingSessions() {
110+
let context = sharedModelContainer.mainContext
111+
let descriptor = FetchDescriptor<DjangoFilesSession>()
112+
113+
do {
114+
let sessionsCount = try context.fetchCount(descriptor)
115+
hasExistingSessions = sessionsCount > 0
116+
} catch {
117+
print("Error checking for existing sessions: \(error)")
118+
}
119+
}
96120
}

Django Files/Views/FileList.swift

+14-4
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,22 @@ struct FileListView: View {
8787
} label: {
8888
FileRowView(file: file)
8989
}
90+
.id(file.id)
91+
92+
// If this is the last item and we have more pages, load more when it appears
93+
if hasNextPage && file.id == files.last?.id {
94+
Color.clear
95+
.frame(height: 20)
96+
.onAppear {
97+
loadNextPage()
98+
}
99+
}
90100
}
91101

92-
if hasNextPage {
102+
if isLoading && hasNextPage {
93103
HStack {
94-
Button("Load More") {
95-
loadNextPage()
96-
}
104+
105+
ProgressView()
97106
}
98107
}
99108
}
@@ -143,6 +152,7 @@ struct FileListView: View {
143152

144153
private func loadNextPage() {
145154
guard hasNextPage else { return }
155+
guard !isLoading else { return } // Prevent multiple simultaneous loading requests
146156
isLoading = true
147157

148158
Task {

0 commit comments

Comments
 (0)