File tree 2 files changed +40
-6
lines changed
2 files changed +40
-6
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,7 @@ struct Django_FilesApp: App {
49
49
} ( )
50
50
51
51
@StateObject private var sessionManager = SessionManager ( )
52
+ @State private var hasExistingSessions = false
52
53
53
54
init ( ) {
54
55
// Handle reset arguments
@@ -83,8 +84,19 @@ struct Django_FilesApp: App {
83
84
84
85
var body : some Scene {
85
86
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
+ }
88
100
}
89
101
. modelContainer ( sharedModelContainer)
90
102
#if os(macOS)
@@ -93,4 +105,16 @@ struct Django_FilesApp: App {
93
105
}
94
106
#endif
95
107
}
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
+ }
96
120
}
Original file line number Diff line number Diff line change @@ -87,13 +87,22 @@ struct FileListView: View {
87
87
} label: {
88
88
FileRowView ( file: file)
89
89
}
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
+ }
90
100
}
91
101
92
- if hasNextPage {
102
+ if isLoading && hasNextPage {
93
103
HStack {
94
- Button ( " Load More " ) {
95
- loadNextPage ( )
96
- }
104
+
105
+ ProgressView ( )
97
106
}
98
107
}
99
108
}
@@ -143,6 +152,7 @@ struct FileListView: View {
143
152
144
153
private func loadNextPage( ) {
145
154
guard hasNextPage else { return }
155
+ guard !isLoading else { return } // Prevent multiple simultaneous loading requests
146
156
isLoading = true
147
157
148
158
Task {
You can’t perform that action at this time.
0 commit comments