- Replace Core Data with SwiftData for iOS 18+ - Create MoodEntryModel as @Model class replacing MoodEntry entity - Create SharedModelContainer for App Group container sharing - Create DataController with CRUD extensions replacing PersistenceController - Update all views and view models to use MoodEntryModel - Update widget extension to use SwiftData - Remove old Core Data files (Persistence*.swift, .xcdatamodeld) - Add EntryType enum with all entry type cases - Fix widget label truncation with proper spacing and text scaling 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
52 lines
1.7 KiB
Swift
52 lines
1.7 KiB
Swift
//
|
|
// FilterViewModel.swift
|
|
// Feels
|
|
//
|
|
// Created by Trey Tartt on 1/17/22.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
@MainActor
|
|
class YearViewModel: ObservableObject {
|
|
@Published public var entryStartDate: Date = Date()
|
|
@Published public var entryEndDate: Date = Date()
|
|
@Published var selectedDays = [Int]()
|
|
|
|
// year, month, items
|
|
@Published public private(set) var data = [Int: [Int: [DayChartView]]]()
|
|
@Published public private(set) var numberOfRatings: Int = 0
|
|
public private(set) var uncategorizedData = [MoodEntryModel]() {
|
|
didSet {
|
|
self.numberOfRatings = uncategorizedData.count
|
|
}
|
|
}
|
|
|
|
init() {
|
|
updateData()
|
|
}
|
|
|
|
private func updateData() {
|
|
let filteredEntries = DataController.shared.getData(startDate: Date(timeIntervalSince1970: 0),
|
|
endDate: Date(),
|
|
includedDays: selectedDays)
|
|
|
|
if let firstDate = filteredEntries.sorted(by: { $0.forDate < $1.forDate }).first?.forDate {
|
|
self.entryStartDate = firstDate
|
|
}
|
|
self.entryEndDate = Date()
|
|
}
|
|
|
|
private let chartViewBuilder = DayChartViewChartBuilder()
|
|
|
|
public func filterEntries(startDate: Date, endDate: Date) {
|
|
let filteredEntries = DataController.shared.getData(startDate: startDate,
|
|
endDate: endDate,
|
|
includedDays: selectedDays)
|
|
data.removeAll()
|
|
let filledOutData = chartViewBuilder.buildGridData(withData: filteredEntries)
|
|
data = filledOutData
|
|
uncategorizedData = filteredEntries
|
|
}
|
|
}
|