simple index

This commit is contained in:
anlicheng 2025-06-10 16:27:46 +08:00
parent 4c0a63a1f4
commit eecee74af2
2 changed files with 15 additions and 18 deletions

View File

@ -68,15 +68,15 @@ struct IndexMainView: View {
LazyVStack(alignment: .center, spacing: 10) {
ForEach(Array(indexModel.dramaGroupElements.enumerated()), id: \.offset) { idx, item in
switch item {
case .label(groupId: let groupId, groupName: let groupName):
case .label(let groupId, let groupName):
DramaGroupLabelView(group_name: groupName) {
selectGroupId = groupId
indexModel.selectedDate = groupId
showDateNavPopover = true
}
case .item(groupId: let groupId, item: let item):
case .item(let groupId, let item):
DramaGroupItemView(groupId: groupId, item: item)
.id(item.id)
.id(idx)
}
}
}

View File

@ -51,8 +51,10 @@ final class IndexModel {
}
enum GroupElement {
case label(groupId: String, groupName: String)
case item(groupId: String, item: UpdateDramaGroup.Item)
// groupId, groupName
case label(String, String)
// groupId, UpdateDramaGroup.Item
case item(String, UpdateDramaGroup.Item)
}
var selectedDate: String
@ -94,20 +96,15 @@ final class IndexModel {
self.cancel = self.scrollIDPublisher
.sink { userId, scrollID in
// grouplabel
self.dramaGroupElements.forEach { element in
switch element {
switch self.dramaGroupElements[scrollID] {
case .label(_, _):
()
case .item(let groupId, let item):
if item.id == scrollID {
DispatchQueue.main.async {
self.setFixedDrameGroup(groupId: groupId)
}
}
}
}
//
let ids = self.getDramaIds(self.updateDramaGroups).suffix(6)
@ -221,9 +218,9 @@ final class IndexModel {
private func transformUpdateDramaGroups(groups: [UpdateDramaGroup]) -> [GroupElement] {
var groupElements: [GroupElement] = []
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 {
groupElements.append(.item(groupId: group.group_id, item: item))
groupElements.append(.item(group.group_id, item))
}
}
return groupElements