remove index prompt
This commit is contained in:
parent
23b6664c04
commit
466ff8e387
@ -49,12 +49,7 @@ final class IndexModel {
|
||||
let update_dramas: [UpdateDramaGroup]
|
||||
let dramas: [DramaItem]
|
||||
}
|
||||
|
||||
enum LoadMoreResult {
|
||||
case success
|
||||
case error(String)
|
||||
}
|
||||
|
||||
|
||||
var dramas: [DramaItem]
|
||||
var selectedDate: String
|
||||
|
||||
@ -79,7 +74,7 @@ final class IndexModel {
|
||||
}
|
||||
|
||||
@MainActor
|
||||
func loadMoreUpdateDramas(userId: String, mode: API.LoadMode) async -> LoadMoreResult {
|
||||
func loadMoreUpdateDramas(userId: String, mode: API.LoadMode) async {
|
||||
// 按照id来判断不一定正确,需要借助其他值
|
||||
let dramaIds = self.getDramaIds(self.updateDramaGroups)
|
||||
print("current ids: \(dramaIds)")
|
||||
@ -98,13 +93,7 @@ final class IndexModel {
|
||||
print("--------- after ------------")
|
||||
displayDramaGroups(self.updateDramaGroups)
|
||||
print("--------- ------------")
|
||||
|
||||
return .success
|
||||
} else {
|
||||
return .error("没有更多数据")
|
||||
}
|
||||
} else {
|
||||
return .error("加载失败")
|
||||
}
|
||||
}
|
||||
case .next:
|
||||
@ -119,17 +108,10 @@ final class IndexModel {
|
||||
print("----------after-----------")
|
||||
displayDramaGroups(self.updateDramaGroups)
|
||||
print("---------------------")
|
||||
|
||||
return .success
|
||||
} else {
|
||||
return .error("没有更多数据")
|
||||
}
|
||||
} else {
|
||||
return .error("加载失败")
|
||||
}
|
||||
}
|
||||
}
|
||||
return .success
|
||||
}
|
||||
|
||||
// 指定日期,并更新日期下对应的数据
|
||||
@ -294,7 +276,7 @@ extension IndexView {
|
||||
@State private var showDateNavPopover: Bool = false
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .center) {
|
||||
VStack {
|
||||
|
||||
HStack(alignment: .center) {
|
||||
Color.clear
|
||||
@ -305,94 +287,78 @@ extension IndexView {
|
||||
}
|
||||
}
|
||||
.frame(height: 50)
|
||||
.background(Color(hex: "#F2F2F2"), ignoresSafeAreaEdges: .bottom)
|
||||
.background(Color(hex: "#F2F2F2"), ignoresSafeAreaEdges: .top)
|
||||
|
||||
HStack(alignment: .center) {
|
||||
Spacer()
|
||||
Text("番剧补完计划")
|
||||
.font(.system(size: 24))
|
||||
.foregroundColor(Color(hex: "#999999"))
|
||||
}
|
||||
|
||||
ForEach(indexModel.dramas, id: \.id) { drama in
|
||||
DramaCellView(dramaItem: drama)
|
||||
}
|
||||
|
||||
// 基于日期的更新列表
|
||||
ScrollView(.vertical, showsIndicators: false) {
|
||||
VStack(alignment: .center, spacing: 10) {
|
||||
ForEach(indexModel.updateDramaGroups, id: \.group_id) { group in
|
||||
DramaGroupView(group: group) {
|
||||
selectGroupId = group.group_id
|
||||
indexModel.selectedDate = group.group_id
|
||||
showDateNavPopover = true
|
||||
}
|
||||
}
|
||||
VStack(alignment: .center) {
|
||||
HStack(alignment: .center) {
|
||||
Spacer()
|
||||
Text("番剧补完计划")
|
||||
.font(.system(size: 24))
|
||||
.foregroundColor(Color(hex: "#999999"))
|
||||
}
|
||||
|
||||
Rectangle()
|
||||
.frame(height: 0)
|
||||
.background(GeometryReader {
|
||||
geometry in
|
||||
Color.clear.onChange(of: geometry.frame(in: .global).minY) {_, offset in
|
||||
|
||||
let frame = geometry.frame(in: .global)
|
||||
let screenBounds = UIScreen.main.bounds
|
||||
let contextFrame = geometry.frame(in: .named("scrollView"))
|
||||
|
||||
if screenBounds.height - frame.minY > 50 && contextFrame.minY > 0 && !isMoreLoading {
|
||||
Task {
|
||||
self.isMoreLoading = true
|
||||
let result = await self.indexModel.loadMoreUpdateDramas(userId: self.userId, mode: .next)
|
||||
switch result {
|
||||
case .success:
|
||||
()
|
||||
case .error(let message):
|
||||
DispatchQueue.main.async {
|
||||
self.showPrompt = true
|
||||
self.promptMessage = message
|
||||
}
|
||||
}
|
||||
self.isMoreLoading = false
|
||||
}
|
||||
ForEach(indexModel.dramas, id: \.id) { drama in
|
||||
DramaCellView(dramaItem: drama)
|
||||
}
|
||||
|
||||
// 基于日期的更新列表
|
||||
ScrollView(.vertical, showsIndicators: false) {
|
||||
VStack(alignment: .center, spacing: 10) {
|
||||
ForEach(indexModel.updateDramaGroups, id: \.group_id) { group in
|
||||
DramaGroupView(group: group) {
|
||||
selectGroupId = group.group_id
|
||||
indexModel.selectedDate = group.group_id
|
||||
showDateNavPopover = true
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if self.isMoreLoading {
|
||||
ProgressView()
|
||||
}
|
||||
}
|
||||
.coordinateSpace(name: "scrollView")
|
||||
.popover(isPresented: $showDateNavPopover) {
|
||||
DateNavView(selectGroupId: self.$selectGroupId, showDateNavPopover: $showDateNavPopover) { selectedDate in
|
||||
Task {
|
||||
await indexModel.loadDateUpdateDramas(userId: self.userId, date: selectedDate)
|
||||
}
|
||||
|
||||
Rectangle()
|
||||
.frame(height: 0)
|
||||
.background(GeometryReader {
|
||||
geometry in
|
||||
Color.clear.onChange(of: geometry.frame(in: .global).minY) {_, offset in
|
||||
|
||||
let frame = geometry.frame(in: .global)
|
||||
let screenBounds = UIScreen.main.bounds
|
||||
let contextFrame = geometry.frame(in: .named("scrollView"))
|
||||
|
||||
if screenBounds.height - frame.minY > 50 && contextFrame.minY > 0 && !isMoreLoading {
|
||||
Task {
|
||||
self.isMoreLoading = true
|
||||
await self.indexModel.loadMoreUpdateDramas(userId: self.userId, mode: .next)
|
||||
self.isMoreLoading = false
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if self.isMoreLoading {
|
||||
ProgressView()
|
||||
}
|
||||
}
|
||||
}
|
||||
.refreshable {
|
||||
guard !self.isPrevLoading else {
|
||||
return
|
||||
}
|
||||
|
||||
// 上拉刷新功能
|
||||
self.isPrevLoading = true
|
||||
let result = await self.indexModel.loadMoreUpdateDramas(userId: self.userId, mode: .prev)
|
||||
switch result {
|
||||
case .success:
|
||||
()
|
||||
case .error(let message):
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
|
||||
self.showPrompt = true
|
||||
self.promptMessage = message
|
||||
.coordinateSpace(name: "scrollView")
|
||||
.popover(isPresented: $showDateNavPopover) {
|
||||
DateNavView(selectGroupId: self.$selectGroupId, showDateNavPopover: $showDateNavPopover) { selectedDate in
|
||||
Task {
|
||||
await indexModel.loadDateUpdateDramas(userId: self.userId, date: selectedDate)
|
||||
}
|
||||
}
|
||||
}
|
||||
self.isPrevLoading = false
|
||||
.refreshable {
|
||||
guard !self.isPrevLoading else {
|
||||
return
|
||||
}
|
||||
|
||||
// 上拉刷新功能
|
||||
self.isPrevLoading = true
|
||||
await self.indexModel.loadMoreUpdateDramas(userId: self.userId, mode: .prev)
|
||||
self.isPrevLoading = false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
.frame(width: 370)
|
||||
}
|
||||
.frame(width: 370)
|
||||
.ignoresSafeArea(edges: .bottom)
|
||||
.alert(isPresented: $showPrompt) {
|
||||
Alert(title: Text("提示"), message: Text(self.promptMessage), dismissButton: .default(Text("OK")))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user