This commit is contained in:
anlicheng 2025-02-25 12:27:18 +08:00
parent d785eef3df
commit d74414a6c5
3 changed files with 23 additions and 10 deletions

View File

@ -77,11 +77,13 @@ struct API {
do { do {
let (data, response) = try await URLSession.shared.data(for: request) let (data, response) = try await URLSession.shared.data(for: request)
guard let response = response as? HTTPURLResponse, response.statusCode == 200 else { guard let response = response as? HTTPURLResponse, response.statusCode == 200 else {
print("url: \(request.url!.absoluteString)")
// print(String(data: data, encoding: .utf8)!)
return .error(-1, "http status error") return .error(-1, "http status error")
} }
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

@ -90,6 +90,8 @@ final class DetailModel {
print(message) print(message)
case .result(let detail): case .result(let detail):
self.name = detail.name self.name = detail.name
self.summary = detail.summary
self.thumb = detail.thumb
self.statuses = detail.status.flatMap({ s in self.statuses = detail.status.flatMap({ s in
if let status = DramaStatus(s) { if let status = DramaStatus(s) {
return [status] return [status]
@ -123,18 +125,24 @@ struct DetailView: View {
.font(.system(size: 28)) .font(.system(size: 28))
.fontWeight(.bold) .fontWeight(.bold)
.foregroundColor(Color(hex: "#333333")) .foregroundColor(Color(hex: "#333333"))
Text(detailModel.summary)
.lineLimit(3)
.multilineTextAlignment(.leading)
.padding()
//.frame(maxWidth: .infinity, alignment: .leading)
} }
.padding([.top, .leading], 10) .padding([.top, .leading], 10)
.background(Color(hex: "#F2F2F2"), ignoresSafeAreaEdges: [.bottom]) .background(Color(hex: "#F2F2F2"), ignoresSafeAreaEdges: [.bottom])
// HStack(alignment: .center, spacing: 10) { HStack(alignment: .center, spacing: 10) {
// Spacer() Spacer()
// ForEach(detailModel.statuses, id: \.status) { status in ForEach(detailModel.statuses, id: \.status) { status in
// FollowButtonView(title: status.config.name, bgColor: status.config.bgColor, fontColor: status.config.fontColor) { FollowButtonView(title: status.config.name, bgColor: status.config.bgColor, fontColor: status.config.fontColor) {
// print("call me follow button clicked") print("call me follow button clicked")
// } }
// } }
// } }
// //
HStack(alignment: .center, spacing: 15) { HStack(alignment: .center, spacing: 15) {
@ -203,6 +211,7 @@ struct DetailView: View {
.frame(width: 370, alignment: .center) .frame(width: 370, alignment: .center)
.task { .task {
await detailModel.loadData(userId: 1, id: self.id) await detailModel.loadData(userId: 1, id: self.id)
print(detailModel.summary)
} }
} }

View File

@ -54,6 +54,8 @@ final class ListModel {
print(message) print(message)
case .result(let detail): case .result(let detail):
self.name = detail.name self.name = detail.name
self.summary = detail.summary
self.thumb = detail.thumb
self.channels = detail.channels self.channels = detail.channels
self.selectedChannelIdx = 0 self.selectedChannelIdx = 0