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