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