频道的切换
This commit is contained in:
parent
c2126eccd2
commit
6ca3c607b7
@ -96,7 +96,7 @@ struct DetailView: View {
|
||||
|
||||
if detailModel.selectedEpisodes.count >= 5 {
|
||||
HStack(alignment: .center) {
|
||||
NavigationLink(destination: ListView(id: self.id)) {
|
||||
NavigationLink(destination: ListView(id: self.id, selectedChannelIdx: detailModel.selectedChannelIdx)) {
|
||||
Rectangle()
|
||||
.frame(width: 200, height: 25)
|
||||
.foregroundColor(Color(hex: "#F2F2F2"))
|
||||
|
||||
@ -45,7 +45,7 @@ final class ListModel {
|
||||
var selectedChannelIdx: Int = 0
|
||||
var selectedEpisodes: [Episode] = []
|
||||
|
||||
func loadData(userId: String, id: Int) async {
|
||||
func loadData(userId: String, id: Int, selectedChannelIdx: Int) async {
|
||||
let response = await API.getDramaDetail(userId: userId, id: id, as: DramaDetailResponse.self)
|
||||
switch response {
|
||||
case .error(let code, let message):
|
||||
@ -60,8 +60,13 @@ final class ListModel {
|
||||
self.thumb = detail.thumb
|
||||
self.channels = detail.channels
|
||||
|
||||
self.selectedChannelIdx = 0
|
||||
self.selectedEpisodes = detail.channels[0].episodes
|
||||
if self.channels.count >= selectedChannelIdx {
|
||||
self.selectedChannelIdx = selectedChannelIdx
|
||||
self.selectedEpisodes = detail.channels[selectedChannelIdx].episodes
|
||||
} else {
|
||||
self.selectedChannelIdx = 0
|
||||
self.selectedEpisodes = detail.channels[0].episodes
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,6 +11,7 @@ struct ListView: View {
|
||||
@State var detailModel = ListModel()
|
||||
|
||||
let id: Int
|
||||
let selectedChannelIdx: Int
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .center, spacing: 20) {
|
||||
@ -49,7 +50,7 @@ struct ListView: View {
|
||||
}
|
||||
.navigationTitle(detailModel.name)
|
||||
.task {
|
||||
await detailModel.loadData(userId: self.userId, id: self.id)
|
||||
await detailModel.loadData(userId: self.userId, id: self.id, selectedChannelIdx: self.selectedChannelIdx)
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,5 +89,5 @@ extension ListView {
|
||||
|
||||
|
||||
#Preview {
|
||||
ListView(id: 19625)
|
||||
ListView(id: 19625, selectedChannelIdx: 0)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user