split all the logic out of filter view into protocols and other shit
This commit is contained in:
33
Shared/Models/DayChartView.swift
Normal file
33
Shared/Models/DayChartView.swift
Normal file
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// CircleView.swift
|
||||
// Feels (iOS)
|
||||
//
|
||||
// Created by Trey Tartt on 1/13/22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
struct DayChartView: ChartViewItemBuildable, View, Hashable {
|
||||
var color: Color
|
||||
var weekDay: Int
|
||||
var viewType: ViewType
|
||||
|
||||
var body: some View {
|
||||
switch viewType {
|
||||
case .cicle:
|
||||
Circle()
|
||||
.fill(color)
|
||||
.frame(minWidth: 5, idealWidth: 50, maxWidth: 50, minHeight: 5, idealHeight: 20, maxHeight: 50, alignment: .center)
|
||||
.opacity(color == Mood.missing.color ? 0.5 : 1.0)
|
||||
case .square:
|
||||
Rectangle()
|
||||
.fill(color)
|
||||
.frame(minWidth: 5, idealWidth: 50, maxWidth: 50, minHeight: 5, idealHeight: 20, maxHeight: 50, alignment: .center)
|
||||
case .text(let value):
|
||||
Text(value)
|
||||
.font(.footnote)
|
||||
.frame(minWidth: 5, idealWidth: 50, maxWidth: 50, minHeight: 5, idealHeight: 20, maxHeight: 50, alignment: .center)
|
||||
}
|
||||
}
|
||||
}
|
||||
35
Shared/Models/FilterViewModel.swift
Normal file
35
Shared/Models/FilterViewModel.swift
Normal file
@@ -0,0 +1,35 @@
|
||||
//
|
||||
// FilterViewModel.swift
|
||||
// Feels
|
||||
//
|
||||
// Created by Trey Tartt on 1/17/22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
class FilterViewModel: 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 = [MoodEntry]() {
|
||||
didSet {
|
||||
self.numberOfRatings = uncategorizedData.count
|
||||
}
|
||||
}
|
||||
|
||||
private let chartViewBuilder = DayChartViewChartBuilder()
|
||||
|
||||
public func filterEntries(startDate: Date, endDate: Date) {
|
||||
let filteredEntries = PersistenceController.shared.getData(startDate: startDate,
|
||||
endDate: endDate,
|
||||
includedDays: selectedDays)
|
||||
data.removeAll()
|
||||
let filledOutData = chartViewBuilder.buildGridData(withData: filteredEntries)
|
||||
data = filledOutData
|
||||
uncategorizedData = filteredEntries
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user