SPB Git

Repository Public License

HomeView.swift 10.0 KB 216 lines swift

1// ORIX Scan2// File: App/Sources/Home/HomeView.swift3// Description: First screen: Scan Document as the primary action, then imports, recent documents, ORIX Actions and the library.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7import ORIXDesign8import ORIXKit9import SwiftData10import SwiftUI1112struct HomeView: View {13    @Environment(AppModel.self) private var model14    @Environment(\.orixAccent) private var accent15    @Environment(\.horizontalSizeClass) private var sizeClass16    @Environment(\.dynamicTypeSize) private var typeSize17    @Query private var records: [DocumentRecord]18    @Query private var folders: [FolderRecord]1920    private var recents: [DocumentRecord] { Array(Library.query(records, sort: .modified).prefix(8)) }21    private var live: [DocumentRecord] { records.filter { $0.deletedAt == nil } }2223    var body: some View {24        ScrollView {25            VStack(alignment: .leading, spacing: ORIX.Space.xl) {26                hero27                imports28                recentSection29                actionsSection30                librarySection31            }32            .padding(.horizontal, ORIX.Space.md)33            .padding(.bottom, ORIX.Space.xxl)34            .frame(maxWidth: 980)35            .frame(maxWidth: .infinity)36        }37        .background(ORIX.Palette.canvas)38        .navigationTitle("ORIX Scan")39        .toolbar {40            if sizeClass != .regular {41                ToolbarItem(placement: .topBarTrailing) {42                    Button { model.router.push(.settings) } label: { Label("Settings", systemImage: "gearshape") }43                        .accessibilityIdentifier("home.settings")44                }45            }46        }47    }4849    // MARK: Scan5051    private var hero: some View {52        Button { model.request(.scan) } label: {53            HStack(spacing: ORIX.Space.md) {54                VStack(alignment: .leading, spacing: ORIX.Space.xs) {55                    Text("Scan Document").font(.system(.title, design: .rounded, weight: .bold)).foregroundStyle(.white).multilineTextAlignment(.leading)56                        .fixedSize(horizontal: false, vertical: true)57                    Text("Edges, perspective and text are handled for you, on this device.")58                        .font(.orixCallout).foregroundStyle(.white.opacity(0.85)).multilineTextAlignment(.leading)59                        .fixedSize(horizontal: false, vertical: true)60                    HStack(spacing: 6) {61                        Image(systemName: "camera.viewfinder")62                        Text("Start Scanning")63                    }64                    .font(.orixHeadline)65                    .foregroundStyle(accent.primary)66                    .padding(.horizontal, ORIX.Space.md)67                    .frame(minHeight: ORIX.minimumTarget)68                    .background(.white, in: Capsule())69                    .padding(.top, ORIX.Space.xs)70                }71                Spacer(minLength: 0)72                if !typeSize.isAccessibilitySize {73                    ORIXMark(ring: .white)74                        .frame(width: sizeClass == .regular ? 150 : 92)75                        .orixScanBeam(active: false)76                }77            }78            .padding(ORIX.Space.lg)79            .frame(maxWidth: .infinity, alignment: .leading)80            .background(accent.gradient, in: RoundedRectangle(cornerRadius: ORIX.Radius.hero, style: .continuous))81            .overlay(alignment: .topTrailing) {82                Circle().fill(.white.opacity(0.08)).frame(width: 220, height: 220).offset(x: 70, y: -90).allowsHitTesting(false)83            }84            .clipShape(RoundedRectangle(cornerRadius: ORIX.Radius.hero, style: .continuous))85        }86        .buttonStyle(.plain)87        .keyboardShortcut("n", modifiers: .command)88        .accessibilityLabel("Scan Document")89        .accessibilityHint("Opens the camera to scan pages")90        .accessibilityIdentifier("home.scan")91    }9293    private var imports: some View {94        let layout = typeSize.isAccessibilitySize ? AnyLayout(VStackLayout(spacing: ORIX.Space.sm)) : AnyLayout(HStackLayout(spacing: ORIX.Space.sm))95        return layout {96            Button { model.request(.photos) } label: { tile("Import Photos", symbol: "photo.on.rectangle.angled", detail: "From your photo library") }97                .buttonStyle(.orixTile)98                .accessibilityIdentifier("home.importPhotos")99            Button { model.request(.files) } label: { tile("Import Files", symbol: "folder", detail: "PDFs and images") }100                .buttonStyle(.orixTile)101                .keyboardShortcut("i", modifiers: [.command, .shift])102                .accessibilityIdentifier("home.importFiles")103        }104    }105106    private func tile(_ title: LocalizedStringKey, symbol: String, detail: LocalizedStringKey) -> some View {107        HStack(spacing: ORIX.Space.sm) {108            ORIXGlyph(symbol, size: 42)109            VStack(alignment: .leading, spacing: 2) {110                Text(title).font(.orixHeadline).foregroundStyle(ORIX.Palette.textPrimary)111                Text(detail).font(.orixCaption).foregroundStyle(ORIX.Palette.textSecondary)112            }113            Spacer(minLength: 0)114        }115        .multilineTextAlignment(.leading)116    }117118    // MARK: Recents119120    private var recentSection: some View {121        VStack(alignment: .leading, spacing: ORIX.Space.sm) {122            ORIXSectionHeader("Recent Documents") {123                if !recents.isEmpty {124                    Button("See All") { model.router.showLibrary() }.font(.orixCallout.weight(.medium))125                }126            }127            if recents.isEmpty {128                HStack(spacing: ORIX.Space.md) {129                    ORIXGlyph("doc.text.viewfinder", size: 48)130                    VStack(alignment: .leading, spacing: 2) {131                        Text("No documents yet").font(.orixHeadline).foregroundStyle(ORIX.Palette.textPrimary)132                        Text("Your scans and imports appear here. They never leave this device unless you share them.")133                            .font(.orixCallout).foregroundStyle(ORIX.Palette.textSecondary)134                    }135                }136                .frame(maxWidth: .infinity, alignment: .leading)137                .orixCard()138                .accessibilityElement(children: .combine)139                .accessibilityIdentifier("home.empty")140            } else {141                ScrollView(.horizontal, showsIndicators: false) {142                    LazyHStack(alignment: .top, spacing: ORIX.Space.sm) {143                        ForEach(recents) { record in144                            Button { model.router.open(record.id) } label: {145                                DocumentCard(record: record).frame(width: 156)146                            }147                            .buttonStyle(.plain)148                            .accessibilityIdentifier("home.recent")149                        }150                    }151                    .padding(.horizontal, ORIX.Space.md)152                }153                .padding(.horizontal, -ORIX.Space.md)154            }155        }156    }157158    // MARK: Actions159160    private var actionsSection: some View {161        VStack(alignment: .leading, spacing: ORIX.Space.sm) {162            ORIXSectionHeader("ORIX Actions") {163                Button("All Actions") { model.router.showActions() }.font(.orixCallout.weight(.medium))164            }165            LazyVGrid(columns: [GridItem(.adaptive(minimum: typeSize.isAccessibilitySize ? 280 : 160), spacing: ORIX.Space.sm)], spacing: ORIX.Space.sm) {166                ForEach(Workflow.presets.prefix(4)) { workflow in167                    Button { WorkflowLauncher.start(workflow, model: model) } label: {168                        VStack(alignment: .leading, spacing: ORIX.Space.xs) {169                            ORIXGlyph(workflow.symbol, tint: accent.secondary)170                            Text(workflow.displayName).font(.orixHeadline).foregroundStyle(ORIX.Palette.textPrimary).multilineTextAlignment(.leading)171                            Text("\(workflow.steps.count) steps").font(.orixCaption).foregroundStyle(ORIX.Palette.textSecondary)172                        }173                        .frame(maxWidth: .infinity, alignment: .leading)174                    }175                    .buttonStyle(.orixTile)176                }177            }178        }179    }180181    // MARK: Library182183    private var librarySection: some View {184        VStack(alignment: .leading, spacing: ORIX.Space.sm) {185            ORIXSectionHeader("Document Library")186            VStack(spacing: 0) {187                libraryRow("All Documents", symbol: "books.vertical", count: live.count) { model.router.showLibrary(.all) }188                Divider().padding(.leading, 60)189                libraryRow("Favourites", symbol: "star", count: live.filter(\.isFavorite).count) { model.router.showLibrary(.favorites) }190                Divider().padding(.leading, 60)191                libraryRow("Folders", symbol: "folder", count: folders.count) { model.router.showLibrary(.all) }192                Divider().padding(.leading, 60)193                libraryRow("Recently Deleted", symbol: "trash", count: records.count - live.count) { model.router.showLibrary(.recentlyDeleted) }194                    .accessibilityIdentifier("home.library.trash")195            }196            .orixCard(padding: 0)197        }198    }199200    private func libraryRow(_ title: LocalizedStringKey, symbol: String, count: Int, action: @escaping () -> Void) -> some View {201        Button(action: action) {202            HStack(spacing: ORIX.Space.sm) {203                ORIXGlyph(symbol, size: 32)204                Text(title).font(.orixBody).foregroundStyle(ORIX.Palette.textPrimary)205                Spacer()206                Text(count, format: .number).font(.orixCallout).foregroundStyle(ORIX.Palette.textSecondary).monospacedDigit()207                Image(systemName: "chevron.right").font(.footnote.weight(.semibold)).foregroundStyle(ORIX.Palette.textTertiary)208            }209            .padding(.horizontal, ORIX.Space.md)210            .frame(minHeight: 52)211            .contentShape(Rectangle())212        }213        .buttonStyle(.plain)214    }215}216
Files main
Menu

Theme