fix index http request task
This commit is contained in:
parent
34a48116d2
commit
7094938c07
@ -112,7 +112,8 @@ struct IndexMainView: View {
|
|||||||
|
|
||||||
// 上拉刷新功能
|
// 上拉刷新功能
|
||||||
self.headerRefreshing = true
|
self.headerRefreshing = true
|
||||||
Task {
|
|
||||||
|
Task { @MainActor in
|
||||||
await self.indexModel.loadPrevUpdateDramasTask(userId: self.userId) { anchorGroupElement in
|
await self.indexModel.loadPrevUpdateDramasTask(userId: self.userId) { anchorGroupElement in
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.headerRefreshing = false
|
self.headerRefreshing = false
|
||||||
@ -140,7 +141,7 @@ struct IndexMainView: View {
|
|||||||
.ignoresSafeArea(edges: .bottom)
|
.ignoresSafeArea(edges: .bottom)
|
||||||
.popover(isPresented: $showDateNavPopover) {
|
.popover(isPresented: $showDateNavPopover) {
|
||||||
DateNavView(selectGroupId: self.$selectGroupId, showDateNavPopover: $showDateNavPopover) { selectedDate in
|
DateNavView(selectGroupId: self.$selectGroupId, showDateNavPopover: $showDateNavPopover) { selectedDate in
|
||||||
Task {
|
Task { @MainActor in
|
||||||
await indexModel.loadDateUpdateDramas(userId: self.userId, date: selectedDate)
|
await indexModel.loadDateUpdateDramas(userId: self.userId, date: selectedDate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -148,10 +149,10 @@ struct IndexMainView: View {
|
|||||||
.alert(isPresented: $showPrompt) {
|
.alert(isPresented: $showPrompt) {
|
||||||
Alert(title: Text("提示"), message: Text(self.promptMessage), dismissButton: .default(Text("OK")))
|
Alert(title: Text("提示"), message: Text(self.promptMessage), dismissButton: .default(Text("OK")))
|
||||||
}
|
}
|
||||||
.task {
|
.onAppear {
|
||||||
await self.indexModel.loadData(userId: self.userId)
|
Task { @MainActor in
|
||||||
|
await self.indexModel.loadData(userId: self.userId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -149,7 +149,7 @@ final class IndexModel {
|
|||||||
let timeDistance = self.updateInterval.distance(to: Date())
|
let timeDistance = self.updateInterval.distance(to: Date())
|
||||||
// 滑动停止的时候,检测是否到达了底部
|
// 滑动停止的时候,检测是否到达了底部
|
||||||
if timeDistance > 1.0 && isCloseBottom {
|
if timeDistance > 1.0 && isCloseBottom {
|
||||||
Task {
|
Task { @MainActor in
|
||||||
await self.loadMoreUpdateDramasTask(userId: userId)
|
await self.loadMoreUpdateDramasTask(userId: userId)
|
||||||
}
|
}
|
||||||
self.updateInterval = Date()
|
self.updateInterval = Date()
|
||||||
@ -195,13 +195,11 @@ final class IndexModel {
|
|||||||
case .result(let result):
|
case .result(let result):
|
||||||
preloadGroupImages(groups: result.update_dramas)
|
preloadGroupImages(groups: result.update_dramas)
|
||||||
|
|
||||||
await MainActor.run {
|
self.updateDramaGroups = result.update_dramas
|
||||||
self.updateDramaGroups = result.update_dramas
|
self.fixedDramaGroup = result.update_dramas.first
|
||||||
self.fixedDramaGroup = result.update_dramas.first
|
|
||||||
|
|
||||||
self.dramaGroupElements = transformUpdateDramaGroups(groups: result.update_dramas)
|
self.dramaGroupElements = transformUpdateDramaGroups(groups: result.update_dramas)
|
||||||
self.follow_num = result.follow_num >= 100 ? "99+" : "\(result.follow_num)"
|
self.follow_num = result.follow_num >= 100 ? "99+" : "\(result.follow_num)"
|
||||||
}
|
|
||||||
}
|
}
|
||||||
self.isLoaded = true
|
self.isLoaded = true
|
||||||
}
|
}
|
||||||
@ -212,9 +210,7 @@ final class IndexModel {
|
|||||||
case .error(let code, let message):
|
case .error(let code, let message):
|
||||||
print("reloadFollowNum get error: \(code), message: \(message)")
|
print("reloadFollowNum get error: \(code), message: \(message)")
|
||||||
case .result(let follow_num):
|
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
|
self.isLoaded = true
|
||||||
}
|
}
|
||||||
@ -245,12 +241,10 @@ final class IndexModel {
|
|||||||
preloadGroupImages(groups: groups)
|
preloadGroupImages(groups: groups)
|
||||||
|
|
||||||
displayDramaGroups(self.updateDramaGroups, label: "before")
|
displayDramaGroups(self.updateDramaGroups, label: "before")
|
||||||
await MainActor.run {
|
self.updateDramaGroups = appendMergeDramaGroups(groups: self.updateDramaGroups, mergeGroups: groups)
|
||||||
self.updateDramaGroups = appendMergeDramaGroups(groups: self.updateDramaGroups, mergeGroups: groups)
|
self.fixedDramaGroup = self.updateDramaGroups.first
|
||||||
self.fixedDramaGroup = self.updateDramaGroups.first
|
|
||||||
|
|
||||||
self.dramaGroupElements = transformUpdateDramaGroups(groups: self.updateDramaGroups)
|
self.dramaGroupElements = transformUpdateDramaGroups(groups: self.updateDramaGroups)
|
||||||
}
|
|
||||||
|
|
||||||
displayDramaGroups(self.updateDramaGroups, label: "after")
|
displayDramaGroups(self.updateDramaGroups, label: "after")
|
||||||
}
|
}
|
||||||
@ -278,14 +272,12 @@ final class IndexModel {
|
|||||||
preloadGroupImages(groups: groups)
|
preloadGroupImages(groups: groups)
|
||||||
|
|
||||||
displayDramaGroups(self.updateDramaGroups, label: "before")
|
displayDramaGroups(self.updateDramaGroups, label: "before")
|
||||||
await MainActor.run {
|
self.updateDramaGroups = preappendMergeDramaGroups(groups: self.updateDramaGroups, mergeGroups: groups)
|
||||||
self.updateDramaGroups = preappendMergeDramaGroups(groups: self.updateDramaGroups, mergeGroups: groups)
|
self.fixedDramaGroup = self.updateDramaGroups.first
|
||||||
self.fixedDramaGroup = self.updateDramaGroups.first
|
|
||||||
|
|
||||||
self.dramaGroupElements = transformUpdateDramaGroups(groups: self.updateDramaGroups)
|
self.dramaGroupElements = transformUpdateDramaGroups(groups: self.updateDramaGroups)
|
||||||
// 处理回调
|
// 处理回调
|
||||||
callback(anchorGroupElement)
|
callback(anchorGroupElement)
|
||||||
}
|
|
||||||
displayDramaGroups(self.updateDramaGroups, label: "after")
|
displayDramaGroups(self.updateDramaGroups, label: "after")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -329,11 +321,9 @@ final class IndexModel {
|
|||||||
if case let .result(groups) = response {
|
if case let .result(groups) = response {
|
||||||
preloadGroupImages(groups: groups)
|
preloadGroupImages(groups: groups)
|
||||||
|
|
||||||
await MainActor.run {
|
self.updateDramaGroups = groups
|
||||||
self.updateDramaGroups = groups
|
self.dramaGroupElements = transformUpdateDramaGroups(groups: self.updateDramaGroups)
|
||||||
self.dramaGroupElements = transformUpdateDramaGroups(groups: self.updateDramaGroups)
|
self.fixedDramaGroup = groups.first
|
||||||
self.fixedDramaGroup = groups.first
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user