fix index view
This commit is contained in:
parent
cf558b7ca8
commit
976bf090ad
@ -93,8 +93,8 @@ struct API {
|
|||||||
}
|
}
|
||||||
|
|
||||||
print("request url: \(request.url!.absoluteString)")
|
print("request url: \(request.url!.absoluteString)")
|
||||||
// let x = String(data: data, encoding: .utf8)!
|
let x = String(data: data, encoding: .utf8)!
|
||||||
// print("url: \(request.url!.path()), data is: \(x)")
|
print("url: \(request.url!.path()), data is: \(x)")
|
||||||
do {
|
do {
|
||||||
let result = try JSONDecoder().decode(APISuccessResponse<T>.self, from: data)
|
let result = try JSONDecoder().decode(APISuccessResponse<T>.self, from: data)
|
||||||
return .result(result.result)
|
return .result(result.result)
|
||||||
|
|||||||
@ -70,10 +70,12 @@ struct DateNavView: View {
|
|||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
ScrollView(.vertical, showsIndicators: false) {
|
ScrollView(.vertical, showsIndicators: false) {
|
||||||
VStack(alignment: .center) {
|
VStack(alignment: .center, spacing: 15) {
|
||||||
ForEach(navModel.dateModels) { model in
|
ForEach(navModel.dateModels) { model in
|
||||||
VStack(alignment: .leading, spacing: 15) {
|
VStack(alignment: .leading, spacing: 5) {
|
||||||
Text(model.year)
|
Text("\(model.year)年")
|
||||||
|
.font(.system(size: 18, weight: .regular))
|
||||||
|
|
||||||
HStack {
|
HStack {
|
||||||
ForEach(model.months, id: \.id) { month in
|
ForEach(model.months, id: \.id) { month in
|
||||||
if month.disabled {
|
if month.disabled {
|
||||||
@ -156,7 +158,6 @@ extension DateNavView {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
//#Preview {
|
//#Preview {
|
||||||
// DateNavView()
|
// DateNavView()
|
||||||
//}
|
//}
|
||||||
|
|||||||
@ -146,7 +146,7 @@ final class IndexModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return targetGroups
|
return sortDramaGroups(groups: targetGroups)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func appendMergeDramaGroups(groups: [UpdateDramaGroup], mergeGroups: [UpdateDramaGroup]) -> [UpdateDramaGroup] {
|
private func appendMergeDramaGroups(groups: [UpdateDramaGroup], mergeGroups: [UpdateDramaGroup]) -> [UpdateDramaGroup] {
|
||||||
@ -163,7 +163,22 @@ final class IndexModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return targetGroups
|
return sortDramaGroups(groups: targetGroups)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 按照日期进行排序
|
||||||
|
private func sortDramaGroups(groups: [UpdateDramaGroup]) -> [UpdateDramaGroup] {
|
||||||
|
return groups.sorted { g0, g1 in
|
||||||
|
let dateFormatter = DateFormatter()
|
||||||
|
dateFormatter.dateFormat = "yyyy-MM"
|
||||||
|
|
||||||
|
if let date0 = dateFormatter.date(from: g0.group_id),
|
||||||
|
let date1 = dateFormatter.date(from: g1.group_id) {
|
||||||
|
return date0 > date1
|
||||||
|
} else {
|
||||||
|
return g0.group_id > g1.group_id
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func getDramaIds(_ updateDramaGroups: [UpdateDramaGroup]) -> [Int] {
|
private func getDramaIds(_ updateDramaGroups: [UpdateDramaGroup]) -> [Int] {
|
||||||
@ -291,14 +306,14 @@ extension IndexView {
|
|||||||
.overlay {
|
.overlay {
|
||||||
HStack(alignment: .center) {
|
HStack(alignment: .center) {
|
||||||
Text("亚次元")
|
Text("亚次元")
|
||||||
.font(.system(size: 16))
|
.font(.system(size: 18, weight: .bold))
|
||||||
.padding([.top, .bottom], 5)
|
.padding([.top, .bottom], 5)
|
||||||
Spacer()
|
Spacer()
|
||||||
|
|
||||||
NavigationLink(destination: FollowListView()) {
|
NavigationLink(destination: FollowListView()) {
|
||||||
HStack {
|
HStack {
|
||||||
Text("♡ \(indexModel.follow_num)")
|
Text("♡ \(indexModel.follow_num)")
|
||||||
.font(.system(size: 16))
|
.font(.system(size: 17))
|
||||||
.foregroundColor(.black)
|
.foregroundColor(.black)
|
||||||
.padding([.top, .bottom], 5)
|
.padding([.top, .bottom], 5)
|
||||||
}
|
}
|
||||||
@ -310,65 +325,54 @@ extension IndexView {
|
|||||||
.frame(height: 50)
|
.frame(height: 50)
|
||||||
.background(Color(hex: "#F2F2F2"), ignoresSafeAreaEdges: .top)
|
.background(Color(hex: "#F2F2F2"), ignoresSafeAreaEdges: .top)
|
||||||
|
|
||||||
VStack(alignment: .center) {
|
ScrollView(.vertical, showsIndicators: false) {
|
||||||
|
// 基于日期的更新列表
|
||||||
ScrollView(.vertical, showsIndicators: false) {
|
LazyVStack(alignment: .center, spacing: 10) {
|
||||||
HStack(alignment: .center) {
|
ForEach(indexModel.updateDramaGroups, id: \.group_id) { group in
|
||||||
Spacer()
|
DramaGroupView(group: group) {
|
||||||
Text("番剧补完计划")
|
selectGroupId = group.group_id
|
||||||
.font(.system(size: 24))
|
indexModel.selectedDate = group.group_id
|
||||||
.foregroundColor(Color(hex: "#999999"))
|
showDateNavPopover = true
|
||||||
}
|
|
||||||
|
|
||||||
// 基于日期的更新列表
|
|
||||||
LazyVStack(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()
|
Rectangle()
|
||||||
.frame(height: 0)
|
.frame(height: 0)
|
||||||
.background(GeometryReader {
|
.background(GeometryReader {
|
||||||
geometry in
|
geometry in
|
||||||
Color.clear.onChange(of: geometry.frame(in: .global).minY) {_, offset in
|
Color.clear.onChange(of: geometry.frame(in: .global).minY) {_, offset in
|
||||||
|
|
||||||
let frame = geometry.frame(in: .global)
|
let frame = geometry.frame(in: .global)
|
||||||
let screenBounds = UIScreen.main.bounds
|
let screenBounds = UIScreen.main.bounds
|
||||||
let contextFrame = geometry.frame(in: .named("indexScrollView"))
|
let contextFrame = geometry.frame(in: .named("indexScrollView"))
|
||||||
|
|
||||||
if screenBounds.height - frame.minY > 50 && contextFrame.minY > 0 && !isMoreLoading {
|
if screenBounds.height - frame.minY > 50 && contextFrame.minY > 0 && !isMoreLoading {
|
||||||
Task {
|
Task {
|
||||||
self.isMoreLoading = true
|
self.isMoreLoading = true
|
||||||
await self.indexModel.loadMoreUpdateDramas(userId: self.userId, mode: .next)
|
await self.indexModel.loadMoreUpdateDramas(userId: self.userId, mode: .next)
|
||||||
self.isMoreLoading = false
|
self.isMoreLoading = false
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
})
|
||||||
|
|
||||||
if self.isMoreLoading {
|
if self.isMoreLoading {
|
||||||
ProgressView()
|
ProgressView()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.coordinateSpace(name: "indexScrollView")
|
|
||||||
.refreshable {
|
|
||||||
guard !self.isPrevLoading && !self.showDateNavPopover else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 上拉刷新功能
|
|
||||||
self.isPrevLoading = true
|
|
||||||
await self.indexModel.loadMoreUpdateDramas(userId: self.userId, mode: .prev)
|
|
||||||
self.isPrevLoading = false
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
.frame(width: 370)
|
.frame(width: 370)
|
||||||
|
.coordinateSpace(name: "indexScrollView")
|
||||||
|
.refreshable {
|
||||||
|
guard !self.isPrevLoading && !self.showDateNavPopover else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 上拉刷新功能
|
||||||
|
self.isPrevLoading = true
|
||||||
|
await self.indexModel.loadMoreUpdateDramas(userId: self.userId, mode: .prev)
|
||||||
|
self.isPrevLoading = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.ignoresSafeArea(edges: .bottom)
|
.ignoresSafeArea(edges: .bottom)
|
||||||
.popover(isPresented: $showDateNavPopover) {
|
.popover(isPresented: $showDateNavPopover) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user