simple index
This commit is contained in:
parent
4c0a63a1f4
commit
eecee74af2
@ -68,15 +68,15 @@ struct IndexMainView: View {
|
|||||||
LazyVStack(alignment: .center, spacing: 10) {
|
LazyVStack(alignment: .center, spacing: 10) {
|
||||||
ForEach(Array(indexModel.dramaGroupElements.enumerated()), id: \.offset) { idx, item in
|
ForEach(Array(indexModel.dramaGroupElements.enumerated()), id: \.offset) { idx, item in
|
||||||
switch item {
|
switch item {
|
||||||
case .label(groupId: let groupId, groupName: let groupName):
|
case .label(let groupId, let groupName):
|
||||||
DramaGroupLabelView(group_name: groupName) {
|
DramaGroupLabelView(group_name: groupName) {
|
||||||
selectGroupId = groupId
|
selectGroupId = groupId
|
||||||
indexModel.selectedDate = groupId
|
indexModel.selectedDate = groupId
|
||||||
showDateNavPopover = true
|
showDateNavPopover = true
|
||||||
}
|
}
|
||||||
case .item(groupId: let groupId, item: let item):
|
case .item(let groupId, let item):
|
||||||
DramaGroupItemView(groupId: groupId, item: item)
|
DramaGroupItemView(groupId: groupId, item: item)
|
||||||
.id(item.id)
|
.id(idx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -51,8 +51,10 @@ final class IndexModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
enum GroupElement {
|
enum GroupElement {
|
||||||
case label(groupId: String, groupName: String)
|
// groupId, groupName
|
||||||
case item(groupId: String, item: UpdateDramaGroup.Item)
|
case label(String, String)
|
||||||
|
// groupId, UpdateDramaGroup.Item
|
||||||
|
case item(String, UpdateDramaGroup.Item)
|
||||||
}
|
}
|
||||||
|
|
||||||
var selectedDate: String
|
var selectedDate: String
|
||||||
@ -94,18 +96,13 @@ final class IndexModel {
|
|||||||
|
|
||||||
self.cancel = self.scrollIDPublisher
|
self.cancel = self.scrollIDPublisher
|
||||||
.sink { userId, scrollID in
|
.sink { userId, scrollID in
|
||||||
|
|
||||||
// 更新group的label的部分
|
// 更新group的label的部分
|
||||||
self.dramaGroupElements.forEach { element in
|
switch self.dramaGroupElements[scrollID] {
|
||||||
switch element {
|
case .label(_, _):
|
||||||
case .label(_, _):
|
()
|
||||||
()
|
case .item(let groupId, let item):
|
||||||
case .item(let groupId, let item):
|
DispatchQueue.main.async {
|
||||||
if item.id == scrollID {
|
self.setFixedDrameGroup(groupId: groupId)
|
||||||
DispatchQueue.main.async {
|
|
||||||
self.setFixedDrameGroup(groupId: groupId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,9 +218,9 @@ final class IndexModel {
|
|||||||
private func transformUpdateDramaGroups(groups: [UpdateDramaGroup]) -> [GroupElement] {
|
private func transformUpdateDramaGroups(groups: [UpdateDramaGroup]) -> [GroupElement] {
|
||||||
var groupElements: [GroupElement] = []
|
var groupElements: [GroupElement] = []
|
||||||
for group in groups {
|
for group in groups {
|
||||||
groupElements.append(.label(groupId: group.group_id, groupName: group.group_name))
|
groupElements.append(.label(group.group_id, group.group_name))
|
||||||
for item in group.items {
|
for item in group.items {
|
||||||
groupElements.append(.item(groupId: group.group_id, item: item))
|
groupElements.append(.item(group.group_id, item))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return groupElements
|
return groupElements
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user