fix index
This commit is contained in:
parent
fc81d12ca0
commit
ae31aea9f2
@ -93,21 +93,22 @@ final class IndexModel {
|
|||||||
@MainActor
|
@MainActor
|
||||||
func loadMoreUpdateDramas(userId: String, mode: API.LoadMode) async {
|
func loadMoreUpdateDramas(userId: String, mode: API.LoadMode) async {
|
||||||
// 按照id来判断不一定正确,需要借助其他值
|
// 按照id来判断不一定正确,需要借助其他值
|
||||||
|
let dramaIds = self.getDramaIds(self.updateDramaGroups)
|
||||||
|
print("current ids: \(dramaIds)")
|
||||||
|
|
||||||
switch mode {
|
switch mode {
|
||||||
case .prev:
|
case .prev:
|
||||||
// 查找最小的id
|
// 查找最小的id
|
||||||
if let firstGroup = self.updateDramaGroups.first(where: { $0.items.count > 0}),
|
if let firstId = dramaIds.first {
|
||||||
let firstItem = firstGroup.items.first {
|
let response = await API.loadMoreUpdateDramas(userId: userId, mode: mode, id: firstId, as: [UpdateDramaGroup].self)
|
||||||
let response = await API.loadMoreUpdateDramas(userId: userId, mode: mode, id: firstItem.id, as: [UpdateDramaGroup].self)
|
|
||||||
if case let .result(groups) = response {
|
if case let .result(groups) = response {
|
||||||
self.updateDramaGroups = preappendMergeDramaGroups(groups: self.updateDramaGroups, mergeGroups: groups)
|
self.updateDramaGroups = preappendMergeDramaGroups(groups: self.updateDramaGroups, mergeGroups: groups)
|
||||||
self.showUpdateDramas = transformGroupUpdateDramas(updateDramaGroups: self.updateDramaGroups)
|
self.showUpdateDramas = transformGroupUpdateDramas(updateDramaGroups: self.updateDramaGroups)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case .next:
|
case .next:
|
||||||
if let lastGroup = self.updateDramaGroups.last(where: {$0.items.count > 0}),
|
if let lastId = dramaIds.last {
|
||||||
let lastItem = lastGroup.items.last {
|
let response = await API.loadMoreUpdateDramas(userId: userId, mode: mode, id: lastId, as: [UpdateDramaGroup].self)
|
||||||
let response = await API.loadMoreUpdateDramas(userId: userId, mode: mode, id: lastItem.id, as: [UpdateDramaGroup].self)
|
|
||||||
if case let .result(groups) = response {
|
if case let .result(groups) = response {
|
||||||
self.updateDramaGroups = appendMergeDramaGroups(groups: self.updateDramaGroups, mergeGroups: groups)
|
self.updateDramaGroups = appendMergeDramaGroups(groups: self.updateDramaGroups, mergeGroups: groups)
|
||||||
self.showUpdateDramas = transformGroupUpdateDramas(updateDramaGroups: self.updateDramaGroups)
|
self.showUpdateDramas = transformGroupUpdateDramas(updateDramaGroups: self.updateDramaGroups)
|
||||||
@ -174,6 +175,13 @@ final class IndexModel {
|
|||||||
return targetGroups
|
return targetGroups
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func getDramaIds(_ updateDramaGroups: [UpdateDramaGroup]) -> [Int] {
|
||||||
|
return self.updateDramaGroups.flatMap { group in
|
||||||
|
return group.items.map { item in
|
||||||
|
return item.id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct IndexView: View {
|
struct IndexView: View {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user