Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 1 addition & 84 deletions RIADigiDoc/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,93 +19,10 @@

import FactoryKit
import SwiftUI
import OSLog
import UtilsLib

struct ContentView: View {
@Environment(\.scenePhase) private var scenePhase
@AppTheme private var theme
@AppTypography private var typography
@Environment(LanguageSettings.self) private var languageSettings

@Environment(NavigationPathManager.self) private var pathManager

@State private var viewModel: ContentViewModel

@State private var openedUrls: [URL] = []
@State private var showHomeMenuBottomSheetFromButton = false
@State private var showSettingsBottomSheetFromButton = false

@State private var navigateToAccessibility = false
@State private var navigateToInfo = false
@State private var navigateToDiagnostics = false

@State private var sharedFilesLoadingTask: Task<Void, Never>?

private var homeMenuBottomSheetActions: [BottomSheetButton] {
HomeMenuBottomSheetActions.actions(
onInfoClick: {
pathManager.navigate(to: .infoView)
},
onAccessibilityClick: {
pathManager.navigate(to: .accessibilityView)
},
onDiagnosticsClick: {
pathManager.navigate(to: .diagnosticsView)
}
)
}

init() {
_viewModel = State(wrappedValue: Container.shared.contentViewModel())
}

var body: some View {
TopBarContainer(
leftIcon: "ic_m3_menu_48pt_wght400",
leftIconAccessibility: "Menu",
onLeftClick: {
showHomeMenuBottomSheetFromButton = true
},
content: {
ScrollView {
VStack {
HomeView(externalFiles: $openedUrls)
Spacer()
}
}
.background(theme.surface)
.onOpenURL { url in
openedUrls = [url]
}
.onAppear {
if scenePhase == .active {
sharedFilesLoadingTask = Task {
let sharedFiles = await viewModel.getSharedFiles()
if !sharedFiles.isEmpty {
openedUrls = sharedFiles
}
}
}
}
.onChange(of: scenePhase) { _, newPhase in
if newPhase == .active {
sharedFilesLoadingTask?.cancel()

sharedFilesLoadingTask = Task {
let sharedFiles = await viewModel.getSharedFiles()
if !sharedFiles.isEmpty {
openedUrls = sharedFiles
}
}
}
}
.onDisappear {
sharedFilesLoadingTask?.cancel()
}
}
)
.bottomSheet(isPresented: $showHomeMenuBottomSheetFromButton, actions: homeMenuBottomSheetActions)
HomeView()
}
}

Expand Down
14 changes: 2 additions & 12 deletions RIADigiDoc/DI/AppContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ extension Container {
self { @MainActor in
HomeViewModel(
sharedContainerViewModel: self.sharedContainerViewModel(),
fileManager: self.fileManager()
fileManager: self.fileManager(),
fileUtil: self.fileUtil()
)
}
}
Expand Down Expand Up @@ -205,17 +206,6 @@ extension Container {
}
}

@MainActor
var contentViewModel: Factory<ContentViewModel> {
self {
@MainActor in
ContentViewModel(
fileUtil: self.fileUtil(),
fileManager: self.fileManager()
)
}
}

@MainActor
var recentDocumentsViewModel: Factory<RecentDocumentsViewModel> {
self {
Expand Down
Loading