now historic are sort by date

dev_ARKit^2
Rayhân HASSOU 10 months ago
parent 2f8b6b92b9
commit 4e691bfd5f

@ -24,6 +24,13 @@ class HistoricListVM: ObservableObject {
return historicList
}
public func groupByDate() -> [String: [HistoricVM]] {
let groupedDictionary = Dictionary(grouping: historicList) { historicVM in
return historicVM.date
}
return groupedDictionary
}
init() {
historicList = []

@ -20,6 +20,12 @@ class HistoricVM: ObservableObject, Identifiable, Hashable{
}
@Published var historic: Historique
var date: String {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
return dateFormatter.string(from: Date())
}
init(historic: Historique) {
self.historic = historic

@ -1,7 +1,4 @@
import SwiftUI
#if DEBUG
import DouShouQiModel
#endif
struct HistoricView: View {
@ -11,15 +8,19 @@ struct HistoricView: View {
VStack {
TitlePageFrame(Text: "Historic", ImageWidth: 200, ImageHeight: 200)
VStack {
List(historicListVM.historicList) { historicVM in
GameResumeFrame(historicVm: historicVM)
// Afficher chaque groupe de dates dans une section distincte
ForEach(historicListVM.groupByDate().sorted(by: { $0.key > $1.key }), id: \.key) { key, historicVMs in
VStack(alignment: .leading) {
Text(key) // Affiche la date comme titre de section
List(historicVMs) { historicVM in
GameResumeFrame(historicVm: historicVM)
}
}
.padding(.horizontal, 10)
}
.padding(.horizontal, 10)
Spacer()
}
}
}

Loading…
Cancel
Save