diff --git a/dimensionhub/Views/Index/IndexMainView.swift b/dimensionhub/Views/Index/IndexMainView.swift index f19f357..7f82536 100644 --- a/dimensionhub/Views/Index/IndexMainView.swift +++ b/dimensionhub/Views/Index/IndexMainView.swift @@ -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) } } } diff --git a/dimensionhub/Views/Index/IndexModel.swift b/dimensionhub/Views/Index/IndexModel.swift index 71cfca5..6905a53 100644 --- a/dimensionhub/Views/Index/IndexModel.swift +++ b/dimensionhub/Views/Index/IndexModel.swift @@ -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,18 +96,13 @@ final class IndexModel { self.cancel = self.scrollIDPublisher .sink { userId, scrollID in - // 更新group的label的部分 - self.dramaGroupElements.forEach { element in - switch element { - case .label(_, _): - () - case .item(let groupId, let item): - if item.id == scrollID { - DispatchQueue.main.async { - self.setFixedDrameGroup(groupId: groupId) - } - } + switch self.dramaGroupElements[scrollID] { + case .label(_, _): + () + case .item(let groupId, let item): + DispatchQueue.main.async { + self.setFixedDrameGroup(groupId: groupId) } } @@ -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