remove index prompt

This commit is contained in:
anlicheng 2025-03-03 21:58:01 +08:00
parent 23b6664c04
commit 466ff8e387

View File

@ -49,12 +49,7 @@ final class IndexModel {
let update_dramas: [UpdateDramaGroup] let update_dramas: [UpdateDramaGroup]
let dramas: [DramaItem] let dramas: [DramaItem]
} }
enum LoadMoreResult {
case success
case error(String)
}
var dramas: [DramaItem] var dramas: [DramaItem]
var selectedDate: String var selectedDate: String
@ -79,7 +74,7 @@ final class IndexModel {
} }
@MainActor @MainActor
func loadMoreUpdateDramas(userId: String, mode: API.LoadMode) async -> LoadMoreResult { func loadMoreUpdateDramas(userId: String, mode: API.LoadMode) async {
// id // id
let dramaIds = self.getDramaIds(self.updateDramaGroups) let dramaIds = self.getDramaIds(self.updateDramaGroups)
print("current ids: \(dramaIds)") print("current ids: \(dramaIds)")
@ -98,13 +93,7 @@ final class IndexModel {
print("--------- after ------------") print("--------- after ------------")
displayDramaGroups(self.updateDramaGroups) displayDramaGroups(self.updateDramaGroups)
print("--------- ------------") print("--------- ------------")
return .success
} else {
return .error("没有更多数据")
} }
} else {
return .error("加载失败")
} }
} }
case .next: case .next:
@ -119,17 +108,10 @@ final class IndexModel {
print("----------after-----------") print("----------after-----------")
displayDramaGroups(self.updateDramaGroups) displayDramaGroups(self.updateDramaGroups)
print("---------------------") print("---------------------")
return .success
} else {
return .error("没有更多数据")
} }
} else {
return .error("加载失败")
} }
} }
} }
return .success
} }
// //
@ -294,7 +276,7 @@ extension IndexView {
@State private var showDateNavPopover: Bool = false @State private var showDateNavPopover: Bool = false
var body: some View { var body: some View {
VStack(alignment: .center) { VStack {
HStack(alignment: .center) { HStack(alignment: .center) {
Color.clear Color.clear
@ -305,94 +287,78 @@ extension IndexView {
} }
} }
.frame(height: 50) .frame(height: 50)
.background(Color(hex: "#F2F2F2"), ignoresSafeAreaEdges: .bottom) .background(Color(hex: "#F2F2F2"), ignoresSafeAreaEdges: .top)
HStack(alignment: .center) { VStack(alignment: .center) {
Spacer() HStack(alignment: .center) {
Text("番剧补完计划") Spacer()
.font(.system(size: 24)) Text("番剧补完计划")
.foregroundColor(Color(hex: "#999999")) .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
}
}
} }
Rectangle() ForEach(indexModel.dramas, id: \.id) { drama in
.frame(height: 0) DramaCellView(dramaItem: drama)
.background(GeometryReader { }
geometry in
Color.clear.onChange(of: geometry.frame(in: .global).minY) {_, offset in //
ScrollView(.vertical, showsIndicators: false) {
let frame = geometry.frame(in: .global) VStack(alignment: .center, spacing: 10) {
let screenBounds = UIScreen.main.bounds ForEach(indexModel.updateDramaGroups, id: \.group_id) { group in
let contextFrame = geometry.frame(in: .named("scrollView")) DramaGroupView(group: group) {
selectGroupId = group.group_id
if screenBounds.height - frame.minY > 50 && contextFrame.minY > 0 && !isMoreLoading { indexModel.selectedDate = group.group_id
Task { showDateNavPopover = true
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
}
} }
} }
}) }
if self.isMoreLoading { Rectangle()
ProgressView() .frame(height: 0)
} .background(GeometryReader {
} geometry in
.coordinateSpace(name: "scrollView") Color.clear.onChange(of: geometry.frame(in: .global).minY) {_, offset in
.popover(isPresented: $showDateNavPopover) {
DateNavView(selectGroupId: self.$selectGroupId, showDateNavPopover: $showDateNavPopover) { selectedDate in let frame = geometry.frame(in: .global)
Task { let screenBounds = UIScreen.main.bounds
await indexModel.loadDateUpdateDramas(userId: self.userId, date: selectedDate) 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()
} }
} }
} .coordinateSpace(name: "scrollView")
.refreshable { .popover(isPresented: $showDateNavPopover) {
guard !self.isPrevLoading else { DateNavView(selectGroupId: self.$selectGroupId, showDateNavPopover: $showDateNavPopover) { selectedDate in
return Task {
} await indexModel.loadDateUpdateDramas(userId: self.userId, date: selectedDate)
}
//
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
} }
} }
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) .ignoresSafeArea(edges: .bottom)
.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")))