fix index http request task

This commit is contained in:
anlicheng 2025-07-15 16:51:47 +08:00
parent 34a48116d2
commit 7094938c07
2 changed files with 27 additions and 36 deletions

View File

@ -112,7 +112,8 @@ struct IndexMainView: View {
//
self.headerRefreshing = true
Task {
Task { @MainActor in
await self.indexModel.loadPrevUpdateDramasTask(userId: self.userId) { anchorGroupElement in
DispatchQueue.main.async {
self.headerRefreshing = false
@ -140,7 +141,7 @@ struct IndexMainView: View {
.ignoresSafeArea(edges: .bottom)
.popover(isPresented: $showDateNavPopover) {
DateNavView(selectGroupId: self.$selectGroupId, showDateNavPopover: $showDateNavPopover) { selectedDate in
Task {
Task { @MainActor in
await indexModel.loadDateUpdateDramas(userId: self.userId, date: selectedDate)
}
}
@ -148,10 +149,10 @@ struct IndexMainView: View {
.alert(isPresented: $showPrompt) {
Alert(title: Text("提示"), message: Text(self.promptMessage), dismissButton: .default(Text("OK")))
}
.task {
await self.indexModel.loadData(userId: self.userId)
.onAppear {
Task { @MainActor in
await self.indexModel.loadData(userId: self.userId)
}
}
}

View File

@ -149,7 +149,7 @@ final class IndexModel {
let timeDistance = self.updateInterval.distance(to: Date())
//
if timeDistance > 1.0 && isCloseBottom {
Task {
Task { @MainActor in
await self.loadMoreUpdateDramasTask(userId: userId)
}
self.updateInterval = Date()
@ -195,13 +195,11 @@ final class IndexModel {
case .result(let result):
preloadGroupImages(groups: result.update_dramas)
await MainActor.run {
self.updateDramaGroups = result.update_dramas
self.fixedDramaGroup = result.update_dramas.first
self.dramaGroupElements = transformUpdateDramaGroups(groups: result.update_dramas)
self.follow_num = result.follow_num >= 100 ? "99+" : "\(result.follow_num)"
}
self.updateDramaGroups = result.update_dramas
self.fixedDramaGroup = result.update_dramas.first
self.dramaGroupElements = transformUpdateDramaGroups(groups: result.update_dramas)
self.follow_num = result.follow_num >= 100 ? "99+" : "\(result.follow_num)"
}
self.isLoaded = true
}
@ -212,9 +210,7 @@ final class IndexModel {
case .error(let code, let message):
print("reloadFollowNum get error: \(code), message: \(message)")
case .result(let follow_num):
await MainActor.run {
self.follow_num = follow_num >= 100 ? "99+" : "\(follow_num)"
}
self.follow_num = follow_num >= 100 ? "99+" : "\(follow_num)"
}
self.isLoaded = true
}
@ -245,12 +241,10 @@ final class IndexModel {
preloadGroupImages(groups: groups)
displayDramaGroups(self.updateDramaGroups, label: "before")
await MainActor.run {
self.updateDramaGroups = appendMergeDramaGroups(groups: self.updateDramaGroups, mergeGroups: groups)
self.fixedDramaGroup = self.updateDramaGroups.first
self.dramaGroupElements = transformUpdateDramaGroups(groups: self.updateDramaGroups)
}
self.updateDramaGroups = appendMergeDramaGroups(groups: self.updateDramaGroups, mergeGroups: groups)
self.fixedDramaGroup = self.updateDramaGroups.first
self.dramaGroupElements = transformUpdateDramaGroups(groups: self.updateDramaGroups)
displayDramaGroups(self.updateDramaGroups, label: "after")
}
@ -278,14 +272,12 @@ final class IndexModel {
preloadGroupImages(groups: groups)
displayDramaGroups(self.updateDramaGroups, label: "before")
await MainActor.run {
self.updateDramaGroups = preappendMergeDramaGroups(groups: self.updateDramaGroups, mergeGroups: groups)
self.fixedDramaGroup = self.updateDramaGroups.first
self.dramaGroupElements = transformUpdateDramaGroups(groups: self.updateDramaGroups)
//
callback(anchorGroupElement)
}
self.updateDramaGroups = preappendMergeDramaGroups(groups: self.updateDramaGroups, mergeGroups: groups)
self.fixedDramaGroup = self.updateDramaGroups.first
self.dramaGroupElements = transformUpdateDramaGroups(groups: self.updateDramaGroups)
//
callback(anchorGroupElement)
displayDramaGroups(self.updateDramaGroups, label: "after")
}
}
@ -329,11 +321,9 @@ final class IndexModel {
if case let .result(groups) = response {
preloadGroupImages(groups: groups)
await MainActor.run {
self.updateDramaGroups = groups
self.dramaGroupElements = transformUpdateDramaGroups(groups: self.updateDramaGroups)
self.fixedDramaGroup = groups.first
}
self.updateDramaGroups = groups
self.dramaGroupElements = transformUpdateDramaGroups(groups: self.updateDramaGroups)
self.fixedDramaGroup = groups.first
}
}