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)") 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)

View File

@ -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()
//} //}

View File

@ -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,16 +325,7 @@ 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) {
HStack(alignment: .center) {
Spacer()
Text("番剧补完计划")
.font(.system(size: 24))
.foregroundColor(Color(hex: "#999999"))
}
// //
LazyVStack(alignment: .center, spacing: 10) { LazyVStack(alignment: .center, spacing: 10) {
ForEach(indexModel.updateDramaGroups, id: \.group_id) { group in ForEach(indexModel.updateDramaGroups, id: \.group_id) { group in
@ -355,6 +361,7 @@ extension IndexView {
ProgressView() ProgressView()
} }
} }
.frame(width: 370)
.coordinateSpace(name: "indexScrollView") .coordinateSpace(name: "indexScrollView")
.refreshable { .refreshable {
guard !self.isPrevLoading && !self.showDateNavPopover else { guard !self.isPrevLoading && !self.showDateNavPopover else {
@ -366,9 +373,6 @@ extension IndexView {
await self.indexModel.loadMoreUpdateDramas(userId: self.userId, mode: .prev) await self.indexModel.loadMoreUpdateDramas(userId: self.userId, mode: .prev)
self.isPrevLoading = false self.isPrevLoading = false
} }
}
.frame(width: 370)
} }
.ignoresSafeArea(edges: .bottom) .ignoresSafeArea(edges: .bottom)
.popover(isPresented: $showDateNavPopover) { .popover(isPresented: $showDateNavPopover) {