Files
Reflect/Shared/Views/EntryListView.swift
Trey t aaaf04f05e Migrate from Core Data to SwiftData
- 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>
2025-12-10 15:08:05 -06:00

128 lines
4.6 KiB
Swift

//
// EntryListView.swift
// Feels (iOS)
//
// Created by Trey Tartt on 3/6/22.
//
import SwiftUI
struct EntryListView: View {
@AppStorage(UserDefaultsStore.Keys.moodImages.rawValue, store: GroupUserDefaults.groupDefaults) private var imagePack: MoodImages = .FontAwesome
@AppStorage(UserDefaultsStore.Keys.moodTint.rawValue, store: GroupUserDefaults.groupDefaults) private var moodTint: MoodTints = .Default
@AppStorage(UserDefaultsStore.Keys.textColor.rawValue, store: GroupUserDefaults.groupDefaults) private var textColor: Color = DefaultTextColor.textColor
@Environment(\.colorScheme) private var colorScheme
public let entry: MoodEntryModel
private var moodColor: Color {
moodTint.color(forMood: entry.mood)
}
private var isMissing: Bool {
entry.moodValue == Mood.missing.rawValue
}
var body: some View {
HStack(spacing: 16) {
// Large mood icon with gradient background
ZStack {
// Gradient circle background
Circle()
.fill(
LinearGradient(
colors: isMissing
? [Color.gray.opacity(0.3), Color.gray.opacity(0.1)]
: [moodColor.opacity(0.8), moodColor.opacity(0.4)],
startPoint: .topLeading,
endPoint: .bottomTrailing
)
)
.frame(width: 56, height: 56)
// Icon
imagePack.icon(forMood: entry.mood)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 32, height: 32)
.foregroundColor(isMissing ? .gray : .white)
}
.shadow(color: isMissing ? .clear : moodColor.opacity(0.4), radius: 8, x: 0, y: 4)
// Content
VStack(alignment: .leading, spacing: 6) {
// Date row
HStack(spacing: 6) {
Text(Random.weekdayName(fromDate: entry.forDate))
.font(.system(size: 17, weight: .semibold))
.foregroundColor(textColor)
Text("")
.foregroundColor(textColor.opacity(0.4))
Text(Random.dayFormat(fromDate: entry.forDate))
.font(.system(size: 17, weight: .medium))
.foregroundColor(textColor.opacity(0.8))
}
// Mood label with colored badge
if isMissing {
Text(String(localized: "mood_value_missing_tap_to_add"))
.font(.system(size: 14, weight: .medium))
.foregroundColor(.gray)
} else {
Text(entry.moodString)
.font(.system(size: 14, weight: .semibold))
.foregroundColor(moodColor)
.padding(.horizontal, 10)
.padding(.vertical, 4)
.background(
Capsule()
.fill(moodColor.opacity(0.15))
)
}
}
Spacer()
// Chevron indicator
Image(systemName: "chevron.right")
.font(.system(size: 14, weight: .semibold))
.foregroundColor(textColor.opacity(0.3))
}
.padding(.horizontal, 18)
.padding(.vertical, 16)
.background(
RoundedRectangle(cornerRadius: 18)
.fill(colorScheme == .dark ? Color(.systemGray6) : .white)
.shadow(
color: isMissing ? .clear : moodColor.opacity(colorScheme == .dark ? 0.2 : 0.12),
radius: 12,
x: 0,
y: 4
)
)
.overlay(
RoundedRectangle(cornerRadius: 18)
.stroke(
isMissing
? Color.gray.opacity(0.2)
: moodColor.opacity(0.2),
lineWidth: 1
)
)
}
}
struct EntryListView_Previews: PreviewProvider {
@MainActor static let fakeData = DataController.shared.randomEntries(count: 1).first!
static var previews: some View {
VStack(spacing: 8) {
EntryListView(entry: EntryListView_Previews.fakeData)
EntryListView(entry: EntryListView_Previews.fakeData)
}
.padding()
}
}