fix
This commit is contained in:
parent
ba79ba08cf
commit
5f1533c019
@ -40,20 +40,17 @@ final class DateNavModel {
|
||||
self.dateModels = await getDateModelData(userId: userId)
|
||||
}
|
||||
|
||||
// 增加了一个缓存的逻辑
|
||||
private func getDateModelData(userId: String) async -> [DateModel] {
|
||||
let models = await DataCache.shared.getDateModelCache()
|
||||
if models.count > 0 {
|
||||
return models
|
||||
} else {
|
||||
let response = await API.getDateIndex(userId: userId, as: [DateModel].self)
|
||||
print(response)
|
||||
switch response {
|
||||
case .error(let code, let message):
|
||||
print(code)
|
||||
print(message)
|
||||
return []
|
||||
case .result(let models):
|
||||
print(models)
|
||||
await DataCache.shared.setDateModelCache(models)
|
||||
return models
|
||||
}
|
||||
@ -64,7 +61,6 @@ final class DateNavModel {
|
||||
|
||||
struct DateNavView: View {
|
||||
@AppStorage("userId") private var userId: String = Utils.defaultUserId()
|
||||
|
||||
@State var navModel = DateNavModel()
|
||||
|
||||
@Binding var selectGroupId: String
|
||||
@ -98,9 +94,6 @@ struct DateNavView: View {
|
||||
.task {
|
||||
await self.navModel.loadDateCells(userId: self.userId)
|
||||
}
|
||||
.onAppear {
|
||||
print("group_id is: \(selectGroupId)")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -82,8 +82,7 @@ final class IndexModel {
|
||||
let response = await API.getIndexData(userId: userId, as: IndexResponse.self)
|
||||
switch response {
|
||||
case .error(let code, let message):
|
||||
print(code)
|
||||
print(message)
|
||||
print("index load data get error_code: \(code), message: \(message)")
|
||||
case .result(let result):
|
||||
self.dramas = result.dramas
|
||||
self.showUpdateDramas = transformGroupUpdateDramas(updateDramaGroups: result.update_dramas)
|
||||
@ -93,24 +92,29 @@ final class IndexModel {
|
||||
|
||||
@MainActor
|
||||
func loadMoreUpdateDramas(userId: String, mode: API.LoadMode) async {
|
||||
let id: Int = 8030
|
||||
// TODO 按照id来判断不一定正确,需要借助其他值
|
||||
// 按照id来判断不一定正确,需要借助其他值
|
||||
switch mode {
|
||||
case .prev:
|
||||
// 查找最小的id
|
||||
let response = await API.loadMoreUpdateDramas(userId: userId, mode: mode, id: id, as: [UpdateDramaGroup].self)
|
||||
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 case let .result(groups) = response {
|
||||
self.updateDramaGroups = preappendMergeDramaGroups(groups: self.updateDramaGroups, mergeGroups: groups)
|
||||
self.showUpdateDramas = transformGroupUpdateDramas(updateDramaGroups: self.updateDramaGroups)
|
||||
}
|
||||
}
|
||||
case .next:
|
||||
let response = await API.loadMoreUpdateDramas(userId: userId, mode: mode, id: id, as: [UpdateDramaGroup].self)
|
||||
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 case let .result(groups) = response {
|
||||
self.updateDramaGroups = appendMergeDramaGroups(groups: self.updateDramaGroups, mergeGroups: groups)
|
||||
self.showUpdateDramas = transformGroupUpdateDramas(updateDramaGroups: self.updateDramaGroups)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 指定日期,并更新日期下对应的数据
|
||||
@MainActor
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user