fix index view

This commit is contained in:
anlicheng 2025-03-31 16:03:24 +08:00
parent cf558b7ca8
commit 976bf090ad
3 changed files with 68 additions and 63 deletions

View File

@ -93,8 +93,8 @@ struct API {
}
print("request url: \(request.url!.absoluteString)")
// let x = String(data: data, encoding: .utf8)!
// print("url: \(request.url!.path()), data is: \(x)")
let x = String(data: data, encoding: .utf8)!
print("url: \(request.url!.path()), data is: \(x)")
do {
let result = try JSONDecoder().decode(APISuccessResponse<T>.self, from: data)
return .result(result.result)

View File

@ -70,10 +70,12 @@ struct DateNavView: View {
var body: some View {
ScrollView(.vertical, showsIndicators: false) {
VStack(alignment: .center) {
VStack(alignment: .center, spacing: 15) {
ForEach(navModel.dateModels) { model in
VStack(alignment: .leading, spacing: 15) {
Text(model.year)
VStack(alignment: .leading, spacing: 5) {
Text("\(model.year)")
.font(.system(size: 18, weight: .regular))
HStack {
ForEach(model.months, id: \.id) { month in
if month.disabled {
@ -156,7 +158,6 @@ extension DateNavView {
}
//
//#Preview {
// DateNavView()
//}

View File

@ -146,7 +146,7 @@ final class IndexModel {
}
}
return targetGroups
return sortDramaGroups(groups: targetGroups)
}
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] {
@ -291,14 +306,14 @@ extension IndexView {
.overlay {
HStack(alignment: .center) {
Text("亚次元")
.font(.system(size: 16))
.font(.system(size: 18, weight: .bold))
.padding([.top, .bottom], 5)
Spacer()
NavigationLink(destination: FollowListView()) {
HStack {
Text("\(indexModel.follow_num)")
.font(.system(size: 16))
.font(.system(size: 17))
.foregroundColor(.black)
.padding([.top, .bottom], 5)
}
@ -310,16 +325,7 @@ extension IndexView {
.frame(height: 50)
.background(Color(hex: "#F2F2F2"), ignoresSafeAreaEdges: .top)
VStack(alignment: .center) {
ScrollView(.vertical, showsIndicators: false) {
HStack(alignment: .center) {
Spacer()
Text("番剧补完计划")
.font(.system(size: 24))
.foregroundColor(Color(hex: "#999999"))
}
//
LazyVStack(alignment: .center, spacing: 10) {
ForEach(indexModel.updateDramaGroups, id: \.group_id) { group in
@ -355,6 +361,7 @@ extension IndexView {
ProgressView()
}
}
.frame(width: 370)
.coordinateSpace(name: "indexScrollView")
.refreshable {
guard !self.isPrevLoading && !self.showDateNavPopover else {
@ -366,9 +373,6 @@ extension IndexView {
await self.indexModel.loadMoreUpdateDramas(userId: self.userId, mode: .prev)
self.isPrevLoading = false
}
}
.frame(width: 370)
}
.ignoresSafeArea(edges: .bottom)
.popover(isPresented: $showDateNavPopover) {