Keep references to identity context in view models

This commit is contained in:
Justin Mazzocchi 2021-01-25 16:45:18 -08:00
parent fe093d7e33
commit a291f3114a
No known key found for this signature in database
GPG key ID: E223E6937AAFB01C
29 changed files with 52 additions and 65 deletions

View file

@ -7,13 +7,11 @@ import ViewModels
final class ExploreViewController: UICollectionViewController { final class ExploreViewController: UICollectionViewController {
private let viewModel: ExploreViewModel private let viewModel: ExploreViewModel
private let rootViewModel: RootViewModel private let rootViewModel: RootViewModel
private let identityContext: IdentityContext
private var cancellables = Set<AnyCancellable>() private var cancellables = Set<AnyCancellable>()
init(viewModel: ExploreViewModel, rootViewModel: RootViewModel, identityContext: IdentityContext) { init(viewModel: ExploreViewModel, rootViewModel: RootViewModel) {
self.viewModel = viewModel self.viewModel = viewModel
self.rootViewModel = rootViewModel self.rootViewModel = rootViewModel
self.identityContext = identityContext
super.init(collectionViewLayout: UICollectionViewFlowLayout()) super.init(collectionViewLayout: UICollectionViewFlowLayout())
@ -36,7 +34,6 @@ final class ExploreViewController: UICollectionViewController {
let searchResultsController = TableViewController( let searchResultsController = TableViewController(
viewModel: viewModel.searchViewModel, viewModel: viewModel.searchViewModel,
rootViewModel: rootViewModel, rootViewModel: rootViewModel,
identityContext: identityContext,
insetBottom: false, insetBottom: false,
parentNavigationController: navigationController) parentNavigationController: navigationController)

View file

@ -60,15 +60,13 @@ private extension MainNavigationViewController {
rootViewModel: rootViewModel), rootViewModel: rootViewModel),
ExploreViewController( ExploreViewController(
viewModel: viewModel.exploreViewModel, viewModel: viewModel.exploreViewModel,
rootViewModel: rootViewModel, rootViewModel: rootViewModel)
identityContext: viewModel.identityContext)
] ]
if let notificationsViewModel = viewModel.notificationsViewModel { if let notificationsViewModel = viewModel.notificationsViewModel {
let notificationsViewController = TableViewController( let notificationsViewController = TableViewController(
viewModel: notificationsViewModel, viewModel: notificationsViewModel,
rootViewModel: rootViewModel, rootViewModel: rootViewModel)
identityContext: viewModel.identityContext)
notificationsViewController.tabBarItem = NavigationViewModel.Tab.notifications.tabBarItem notificationsViewController.tabBarItem = NavigationViewModel.Tab.notifications.tabBarItem
@ -78,8 +76,7 @@ private extension MainNavigationViewController {
if let conversationsViewModel = viewModel.conversationsViewModel { if let conversationsViewModel = viewModel.conversationsViewModel {
let conversationsViewController = TableViewController( let conversationsViewController = TableViewController(
viewModel: conversationsViewModel, viewModel: conversationsViewModel,
rootViewModel: rootViewModel, rootViewModel: rootViewModel)
identityContext: viewModel.identityContext)
conversationsViewController.tabBarItem = NavigationViewModel.Tab.messages.tabBarItem conversationsViewController.tabBarItem = NavigationViewModel.Tab.messages.tabBarItem
conversationsViewController.navigationItem.title = NavigationViewModel.Tab.messages.title conversationsViewController.navigationItem.title = NavigationViewModel.Tab.messages.title

View file

@ -19,7 +19,6 @@ final class ProfileViewController: TableViewController {
super.init( super.init(
viewModel: viewModel, viewModel: viewModel,
rootViewModel: rootViewModel, rootViewModel: rootViewModel,
identityContext: identityContext,
parentNavigationController: parentNavigationController) parentNavigationController: parentNavigationController)
} }

View file

@ -13,7 +13,6 @@ class TableViewController: UITableViewController {
private let viewModel: CollectionViewModel private let viewModel: CollectionViewModel
private let rootViewModel: RootViewModel private let rootViewModel: RootViewModel
private let identityContext: IdentityContext
private let loadingTableFooterView = LoadingTableFooterView() private let loadingTableFooterView = LoadingTableFooterView()
private let webfingerIndicatorView = WebfingerIndicatorView() private let webfingerIndicatorView = WebfingerIndicatorView()
@Published private var loading = false @Published private var loading = false
@ -30,12 +29,10 @@ class TableViewController: UITableViewController {
init(viewModel: CollectionViewModel, init(viewModel: CollectionViewModel,
rootViewModel: RootViewModel, rootViewModel: RootViewModel,
identityContext: IdentityContext,
insetBottom: Bool = true, insetBottom: Bool = true,
parentNavigationController: UINavigationController? = nil) { parentNavigationController: UINavigationController? = nil) {
self.viewModel = viewModel self.viewModel = viewModel
self.rootViewModel = rootViewModel self.rootViewModel = rootViewModel
self.identityContext = identityContext
self.insetBottom = insetBottom self.insetBottom = insetBottom
self.parentNavigationController = parentNavigationController self.parentNavigationController = parentNavigationController
@ -130,7 +127,7 @@ class TableViewController: UITableViewController {
return cellHeightCaches[tableView.frame.width]?[item] return cellHeightCaches[tableView.frame.width]?[item]
?? item.estimatedHeight(width: tableView.readableContentGuide.layoutFrame.width, ?? item.estimatedHeight(width: tableView.readableContentGuide.layoutFrame.width,
identityContext: identityContext) identityContext: viewModel.identityContext)
} }
override func tableView(_ tableView: UITableView, shouldHighlightRowAt indexPath: IndexPath) -> Bool { override func tableView(_ tableView: UITableView, shouldHighlightRowAt indexPath: IndexPath) -> Bool {
@ -346,9 +343,8 @@ private extension TableViewController {
let vc = TableViewController( let vc = TableViewController(
viewModel: CollectionItemsViewModel( viewModel: CollectionItemsViewModel(
collectionService: collectionService, collectionService: collectionService,
identityContext: identityContext), identityContext: viewModel.identityContext),
rootViewModel: rootViewModel, rootViewModel: rootViewModel,
identityContext: identityContext,
parentNavigationController: parentNavigationController) parentNavigationController: parentNavigationController)
if let parentNavigationController = parentNavigationController { if let parentNavigationController = parentNavigationController {
@ -360,9 +356,9 @@ private extension TableViewController {
let vc = ProfileViewController( let vc = ProfileViewController(
viewModel: ProfileViewModel( viewModel: ProfileViewModel(
profileService: profileService, profileService: profileService,
identityContext: identityContext), identityContext: viewModel.identityContext),
rootViewModel: rootViewModel, rootViewModel: rootViewModel,
identityContext: identityContext, identityContext: viewModel.identityContext,
parentNavigationController: parentNavigationController) parentNavigationController: parentNavigationController)
if let parentNavigationController = parentNavigationController { if let parentNavigationController = parentNavigationController {
@ -420,7 +416,7 @@ private extension TableViewController {
func compose(inReplyToViewModel: StatusViewModel?, redraft: Status?) { func compose(inReplyToViewModel: StatusViewModel?, redraft: Status?) {
let newStatusViewModel = rootViewModel.newStatusViewModel( let newStatusViewModel = rootViewModel.newStatusViewModel(
identityContext: identityContext, identityContext: viewModel.identityContext,
inReplyTo: inReplyToViewModel, inReplyTo: inReplyToViewModel,
redraft: redraft) redraft: redraft)
let newStatusViewController = NewStatusViewController(viewModel: newStatusViewModel) let newStatusViewController = NewStatusViewController(viewModel: newStatusViewModel)

View file

@ -21,8 +21,7 @@ final class TimelinesViewController: UIPageViewController {
timelineViewControllers.append( timelineViewControllers.append(
TableViewController( TableViewController(
viewModel: viewModel.viewModel(timeline: timeline), viewModel: viewModel.viewModel(timeline: timeline),
rootViewModel: rootViewModel, rootViewModel: rootViewModel))
identityContext: viewModel.identityContext))
segmentedControl.insertSegment(withTitle: timeline.title, at: index, animated: false) segmentedControl.insertSegment(withTitle: timeline.title, at: index, animated: false)
} }
@ -76,8 +75,7 @@ final class TimelinesViewController: UIPageViewController {
let vc = TableViewController( let vc = TableViewController(
viewModel: self.viewModel.viewModel(timeline: $0), viewModel: self.viewModel.viewModel(timeline: $0),
rootViewModel: self.rootViewModel, rootViewModel: self.rootViewModel)
identityContext: self.viewModel.identityContext)
vc.navigationItem.title = $0.title vc.navigationItem.title = $0.title

View file

@ -7,9 +7,9 @@ import ServiceLayer
public struct AccountViewModel: CollectionItemViewModel { public struct AccountViewModel: CollectionItemViewModel {
public let events: AnyPublisher<AnyPublisher<CollectionItemEvent, Error>, Never> public let events: AnyPublisher<AnyPublisher<CollectionItemEvent, Error>, Never>
public let identityContext: IdentityContext
private let accountService: AccountService private let accountService: AccountService
private let identityContext: IdentityContext
private let eventsSubject = PassthroughSubject<AnyPublisher<CollectionItemEvent, Error>, Never>() private let eventsSubject = PassthroughSubject<AnyPublisher<CollectionItemEvent, Error>, Never>()
init(accountService: AccountService, identityContext: IdentityContext) { init(accountService: AccountService, identityContext: IdentityContext) {

View file

@ -10,8 +10,8 @@ public final class AttachmentViewModel: ObservableObject {
@Published public var editingDescription: String @Published public var editingDescription: String
@Published public var editingFocus: Attachment.Meta.Focus @Published public var editingFocus: Attachment.Meta.Focus
@Published public private(set) var descriptionRemainingCharacters = AttachmentViewModel.descriptionMaxCharacters @Published public private(set) var descriptionRemainingCharacters = AttachmentViewModel.descriptionMaxCharacters
public let identityContext: IdentityContext
private let identityContext: IdentityContext
private let status: Status? private let status: Status?
init(attachment: Attachment, identityContext: IdentityContext, status: Status? = nil) { init(attachment: Attachment, identityContext: IdentityContext, status: Status? = nil) {

View file

@ -7,6 +7,7 @@ import ServiceLayer
// swiftlint:disable file_length // swiftlint:disable file_length
public class CollectionItemsViewModel: ObservableObject { public class CollectionItemsViewModel: ObservableObject {
public let identityContext: IdentityContext
@Published public var alertItem: AlertItem? @Published public var alertItem: AlertItem?
public private(set) var nextPageMaxId: String? public private(set) var nextPageMaxId: String?
@ -15,7 +16,6 @@ public class CollectionItemsViewModel: ObservableObject {
maintainScrollPositionItemId: nil, maintainScrollPositionItemId: nil,
shouldAdjustContentInset: false) shouldAdjustContentInset: false)
private let collectionService: CollectionService private let collectionService: CollectionService
private let identityContext: IdentityContext
private var viewModelCache = [CollectionItem: (viewModel: CollectionItemViewModel, events: AnyCancellable)]() private var viewModelCache = [CollectionItem: (viewModel: CollectionItemViewModel, events: AnyCancellable)]()
private let eventsSubject = PassthroughSubject<CollectionItemEvent, Never>() private let eventsSubject = PassthroughSubject<CollectionItemEvent, Never>()
private let loadingSubject = PassthroughSubject<Bool, Never>() private let loadingSubject = PassthroughSubject<Bool, Never>()

View file

@ -4,6 +4,7 @@ import Combine
import Foundation import Foundation
public protocol CollectionViewModel { public protocol CollectionViewModel {
var identityContext: IdentityContext { get }
var updates: AnyPublisher<CollectionUpdate, Never> { get } var updates: AnyPublisher<CollectionUpdate, Never> { get }
var title: AnyPublisher<String, Never> { get } var title: AnyPublisher<String, Never> { get }
var titleLocalizationComponents: AnyPublisher<[String], Never> { get } var titleLocalizationComponents: AnyPublisher<[String], Never> { get }

View file

@ -9,9 +9,9 @@ public final class ConversationViewModel: CollectionItemViewModel, ObservableObj
public let accountViewModels: [AccountViewModel] public let accountViewModels: [AccountViewModel]
public let statusViewModel: StatusViewModel? public let statusViewModel: StatusViewModel?
public let events: AnyPublisher<AnyPublisher<CollectionItemEvent, Error>, Never> public let events: AnyPublisher<AnyPublisher<CollectionItemEvent, Error>, Never>
public let identityContext: IdentityContext
private let conversationService: ConversationService private let conversationService: ConversationService
private let identityContext: IdentityContext
private let eventsSubject = PassthroughSubject<AnyPublisher<CollectionItemEvent, Error>, Never>() private let eventsSubject = PassthroughSubject<AnyPublisher<CollectionItemEvent, Error>, Never>()
init(conversationService: ConversationService, identityContext: IdentityContext) { init(conversationService: ConversationService, identityContext: IdentityContext) {

View file

@ -10,12 +10,12 @@ public final class EditFilterViewModel: ObservableObject {
@Published public var saving = false @Published public var saving = false
@Published public var alertItem: AlertItem? @Published public var alertItem: AlertItem?
public let saveCompleted: AnyPublisher<Void, Never> public let saveCompleted: AnyPublisher<Void, Never>
public let identityContext: IdentityContext
public var date: Date { public var date: Date {
didSet { filter.expiresAt = date } didSet { filter.expiresAt = date }
} }
private let identityContext: IdentityContext
private let saveCompletedSubject = PassthroughSubject<Void, Never>() private let saveCompletedSubject = PassthroughSubject<Void, Never>()
private var cancellables = Set<AnyCancellable>() private var cancellables = Set<AnyCancellable>()

View file

@ -5,9 +5,9 @@ import ServiceLayer
public final class ExploreViewModel: ObservableObject { public final class ExploreViewModel: ObservableObject {
public let searchViewModel: SearchViewModel public let searchViewModel: SearchViewModel
public let identityContext: IdentityContext
private let exploreService: ExploreService private let exploreService: ExploreService
private let identityContext: IdentityContext
init(service: ExploreService, identityContext: IdentityContext) { init(service: ExploreService, identityContext: IdentityContext) {
exploreService = service exploreService = service

View file

@ -9,8 +9,8 @@ public final class FiltersViewModel: ObservableObject {
@Published public var activeFilters = [Filter]() @Published public var activeFilters = [Filter]()
@Published public var expiredFilters = [Filter]() @Published public var expiredFilters = [Filter]()
@Published public var alertItem: AlertItem? @Published public var alertItem: AlertItem?
public let identityContext: IdentityContext
private let identityContext: IdentityContext
private var cancellables = Set<AnyCancellable>() private var cancellables = Set<AnyCancellable>()
public init(identityContext: IdentityContext) { public init(identityContext: IdentityContext) {

View file

@ -10,8 +10,8 @@ public final class IdentitiesViewModel: ObservableObject {
@Published public var unauthenticated = [Identity]() @Published public var unauthenticated = [Identity]()
@Published public var pending = [Identity]() @Published public var pending = [Identity]()
@Published public var alertItem: AlertItem? @Published public var alertItem: AlertItem?
public let identityContext: IdentityContext
private let identityContext: IdentityContext
private var cancellables = Set<AnyCancellable>() private var cancellables = Set<AnyCancellable>()
public init(identityContext: IdentityContext) { public init(identityContext: IdentityContext) {

View file

@ -9,8 +9,8 @@ public final class ListsViewModel: ObservableObject {
@Published public private(set) var lists = [List]() @Published public private(set) var lists = [List]()
@Published public private(set) var creatingList = false @Published public private(set) var creatingList = false
@Published public var alertItem: AlertItem? @Published public var alertItem: AlertItem?
public let identityContext: IdentityContext
private let identityContext: IdentityContext
private var cancellables = Set<AnyCancellable>() private var cancellables = Set<AnyCancellable>()
public init(identityContext: IdentityContext) { public init(identityContext: IdentityContext) {

View file

@ -5,7 +5,7 @@ import Foundation
import ServiceLayer import ServiceLayer
public final class MediaPreferencesViewModel: ObservableObject { public final class MediaPreferencesViewModel: ObservableObject {
private let identityContext: IdentityContext public let identityContext: IdentityContext
public init(identityContext: IdentityContext) { public init(identityContext: IdentityContext) {
self.identityContext = identityContext self.identityContext = identityContext

View file

@ -8,8 +8,8 @@ import ServiceLayer
public final class NotificationTypesPreferencesViewModel: ObservableObject { public final class NotificationTypesPreferencesViewModel: ObservableObject {
@Published public var pushSubscriptionAlerts: PushSubscription.Alerts @Published public var pushSubscriptionAlerts: PushSubscription.Alerts
@Published public var alertItem: AlertItem? @Published public var alertItem: AlertItem?
public let identityContext: IdentityContext
private let identityContext: IdentityContext
private var cancellables = Set<AnyCancellable>() private var cancellables = Set<AnyCancellable>()
public init(identityContext: IdentityContext) { public init(identityContext: IdentityContext) {

View file

@ -9,9 +9,9 @@ public final class NotificationViewModel: CollectionItemViewModel, ObservableObj
public let accountViewModel: AccountViewModel public let accountViewModel: AccountViewModel
public let statusViewModel: StatusViewModel? public let statusViewModel: StatusViewModel?
public let events: AnyPublisher<AnyPublisher<CollectionItemEvent, Error>, Never> public let events: AnyPublisher<AnyPublisher<CollectionItemEvent, Error>, Never>
public let identityContext: IdentityContext
private let notificationService: NotificationService private let notificationService: NotificationService
private let identityContext: IdentityContext
private let eventsSubject = PassthroughSubject<AnyPublisher<CollectionItemEvent, Error>, Never>() private let eventsSubject = PassthroughSubject<AnyPublisher<CollectionItemEvent, Error>, Never>()
init(notificationService: NotificationService, identityContext: IdentityContext) { init(notificationService: NotificationService, identityContext: IdentityContext) {

View file

@ -7,8 +7,8 @@ import ServiceLayer
public final class PostingReadingPreferencesViewModel: ObservableObject { public final class PostingReadingPreferencesViewModel: ObservableObject {
@Published public var preferences: Identity.Preferences @Published public var preferences: Identity.Preferences
@Published public var alertItem: AlertItem? @Published public var alertItem: AlertItem?
public let identityContext: IdentityContext
private let identityContext: IdentityContext
private var cancellables = Set<AnyCancellable>() private var cancellables = Set<AnyCancellable>()
public init(identityContext: IdentityContext) { public init(identityContext: IdentityContext) {

View file

@ -6,8 +6,7 @@ import ServiceLayer
public final class PreferencesViewModel: ObservableObject { public final class PreferencesViewModel: ObservableObject {
public let handle: String public let handle: String
public let shouldShowNotificationTypePreferences: Bool public let shouldShowNotificationTypePreferences: Bool
public let identityContext: IdentityContext
private let identityContext: IdentityContext
public init(identityContext: IdentityContext) { public init(identityContext: IdentityContext) {
self.identityContext = identityContext self.identityContext = identityContext

View file

@ -62,6 +62,10 @@ public extension ProfileViewModel {
} }
extension ProfileViewModel: CollectionViewModel { extension ProfileViewModel: CollectionViewModel {
public var identityContext: IdentityContext {
collectionViewModel.value.identityContext
}
public var updates: AnyPublisher<CollectionUpdate, Never> { public var updates: AnyPublisher<CollectionUpdate, Never> {
collectionViewModel.flatMap(\.updates).eraseToAnyPublisher() collectionViewModel.flatMap(\.updates).eraseToAnyPublisher()
} }

View file

@ -19,9 +19,9 @@ public final class StatusViewModel: CollectionItemViewModel, AttachmentsRenderin
@Published public var pollOptionSelections = Set<Int>() @Published public var pollOptionSelections = Set<Int>()
public var configuration = CollectionItem.StatusConfiguration.default public var configuration = CollectionItem.StatusConfiguration.default
public let events: AnyPublisher<AnyPublisher<CollectionItemEvent, Error>, Never> public let events: AnyPublisher<AnyPublisher<CollectionItemEvent, Error>, Never>
public let identityContext: IdentityContext
private let statusService: StatusService private let statusService: StatusService
private let identityContext: IdentityContext
private let eventsSubject = PassthroughSubject<AnyPublisher<CollectionItemEvent, Error>, Never>() private let eventsSubject = PassthroughSubject<AnyPublisher<CollectionItemEvent, Error>, Never>()
init(statusService: StatusService, identityContext: IdentityContext) { init(statusService: StatusService, identityContext: IdentityContext) {

View file

@ -6,13 +6,12 @@ import ViewModels
struct FiltersView: View { struct FiltersView: View {
@StateObject var viewModel: FiltersViewModel @StateObject var viewModel: FiltersViewModel
@EnvironmentObject var identityContext: IdentityContext
var body: some View { var body: some View {
Form { Form {
Section { Section {
NavigationLink(destination: EditFilterView( NavigationLink(destination: EditFilterView(
viewModel: .init(filter: .new, identityContext: identityContext))) { viewModel: .init(filter: .new, identityContext: viewModel.identityContext))) {
Label("add", systemImage: "plus.circle") Label("add", systemImage: "plus.circle")
} }
} }
@ -37,7 +36,7 @@ private extension FiltersView {
Section(header: Text(title)) { Section(header: Text(title)) {
ForEach(filters) { filter in ForEach(filters) { filter in
NavigationLink(destination: EditFilterView( NavigationLink(destination: EditFilterView(
viewModel: .init(filter: filter, identityContext: identityContext))) { viewModel: .init(filter: filter, identityContext: viewModel.identityContext))) {
HStack { HStack {
Text(filter.phrase) Text(filter.phrase)
Spacer() Spacer()

View file

@ -6,7 +6,6 @@ import ViewModels
struct MainNavigationView: UIViewControllerRepresentable { struct MainNavigationView: UIViewControllerRepresentable {
let viewModelClosure: () -> NavigationViewModel let viewModelClosure: () -> NavigationViewModel
@EnvironmentObject var rootViewModel: RootViewModel @EnvironmentObject var rootViewModel: RootViewModel
@EnvironmentObject var identityContext: IdentityContext
func makeUIViewController(context: Context) -> MainNavigationViewController { func makeUIViewController(context: Context) -> MainNavigationViewController {
MainNavigationViewController( MainNavigationViewController(
@ -25,7 +24,6 @@ import PreviewViewModels
struct MainNavigationView_Previews: PreviewProvider { struct MainNavigationView_Previews: PreviewProvider {
static var previews: some View { static var previews: some View {
MainNavigationView { NavigationViewModel(identityContext: .preview) } MainNavigationView { NavigationViewModel(identityContext: .preview) }
.environmentObject(IdentityContext.preview)
.environmentObject(RootViewModel.preview) .environmentObject(RootViewModel.preview)
} }
} }

View file

@ -5,9 +5,14 @@ import ViewModels
struct MediaPreferencesView: View { struct MediaPreferencesView: View {
@StateObject var viewModel: MediaPreferencesViewModel @StateObject var viewModel: MediaPreferencesViewModel
@EnvironmentObject var identityContext: IdentityContext @StateObject var identityContext: IdentityContext
@Environment(\.accessibilityReduceMotion) var accessibilityReduceMotion @Environment(\.accessibilityReduceMotion) var accessibilityReduceMotion
init(viewModel: MediaPreferencesViewModel) {
_viewModel = StateObject(wrappedValue: viewModel)
_identityContext = StateObject(wrappedValue: viewModel.identityContext)
}
var body: some View { var body: some View {
Form { Form {
if accessibilityReduceMotion { if accessibilityReduceMotion {

View file

@ -5,21 +5,20 @@ import ViewModels
struct PreferencesView: View { struct PreferencesView: View {
@StateObject var viewModel: PreferencesViewModel @StateObject var viewModel: PreferencesViewModel
@EnvironmentObject var identityContext: IdentityContext
var body: some View { var body: some View {
Form { Form {
Section(header: Text(viewModel.handle)) { Section(header: Text(viewModel.handle)) {
NavigationLink("preferences.posting-reading", NavigationLink("preferences.posting-reading",
destination: PostingReadingPreferencesView( destination: PostingReadingPreferencesView(
viewModel: .init(identityContext: identityContext))) viewModel: .init(identityContext: viewModel.identityContext)))
NavigationLink("preferences.filters", NavigationLink("preferences.filters",
destination: FiltersView( destination: FiltersView(
viewModel: .init(identityContext: identityContext))) viewModel: .init(identityContext: viewModel.identityContext)))
if viewModel.shouldShowNotificationTypePreferences { if viewModel.shouldShowNotificationTypePreferences {
NavigationLink("preferences.notification-types", NavigationLink("preferences.notification-types",
destination: NotificationTypesPreferencesView( destination: NotificationTypesPreferencesView(
viewModel: .init(identityContext: identityContext))) viewModel: .init(identityContext: viewModel.identityContext)))
} }
NavigationLink("preferences.muted-users", NavigationLink("preferences.muted-users",
destination: TableView(viewModelClosure: viewModel.mutedUsersViewModel) destination: TableView(viewModelClosure: viewModel.mutedUsersViewModel)
@ -33,9 +32,10 @@ struct PreferencesView: View {
Section(header: Text("preferences.app")) { Section(header: Text("preferences.app")) {
NavigationLink("preferences.media", NavigationLink("preferences.media",
destination: MediaPreferencesView( destination: MediaPreferencesView(
viewModel: .init(identityContext: identityContext))) viewModel: .init(identityContext: viewModel.identityContext)))
NavigationLink("preferences.startup-and-syncing", NavigationLink("preferences.startup-and-syncing",
destination: StartupAndSyncingPreferencesView()) destination: StartupAndSyncingPreferencesView(
identityContext: viewModel.identityContext))
} }
} }
.navigationTitle("preferences") .navigationTitle("preferences")

View file

@ -14,8 +14,7 @@ struct SecondaryNavigationView: View {
Section { Section {
NavigationLink( NavigationLink(
destination: IdentitiesView(viewModel: .init(identityContext: viewModel.identityContext)) destination: IdentitiesView(viewModel: .init(identityContext: viewModel.identityContext))
.environmentObject(rootViewModel) .environmentObject(rootViewModel),
.environmentObject(viewModel.identityContext),
label: { label: {
HStack { HStack {
KFImage(viewModel.identityContext.identity.image) KFImage(viewModel.identityContext.identity.image)
@ -55,8 +54,7 @@ struct SecondaryNavigationView: View {
} }
Section { Section {
NavigationLink(destination: ListsView(viewModel: .init(identityContext: viewModel.identityContext)) NavigationLink(destination: ListsView(viewModel: .init(identityContext: viewModel.identityContext))
.environmentObject(rootViewModel) .environmentObject(rootViewModel)) {
.environmentObject(viewModel.identityContext)) {
Label("secondary-navigation.lists", systemImage: "scroll") Label("secondary-navigation.lists", systemImage: "scroll")
} }
ForEach([Timeline.favorites, Timeline.bookmarks]) { timeline in ForEach([Timeline.favorites, Timeline.bookmarks]) { timeline in
@ -74,8 +72,7 @@ struct SecondaryNavigationView: View {
Section { Section {
NavigationLink( NavigationLink(
destination: PreferencesView(viewModel: .init(identityContext: viewModel.identityContext)) destination: PreferencesView(viewModel: .init(identityContext: viewModel.identityContext))
.environmentObject(rootViewModel) .environmentObject(rootViewModel)) {
.environmentObject(viewModel.identityContext)) {
Label("secondary-navigation.preferences", systemImage: "gear") Label("secondary-navigation.preferences", systemImage: "gear")
} }
} }

View file

@ -4,7 +4,7 @@ import SwiftUI
import ViewModels import ViewModels
struct StartupAndSyncingPreferencesView: View { struct StartupAndSyncingPreferencesView: View {
@EnvironmentObject var identityContext: IdentityContext @StateObject var identityContext: IdentityContext
var body: some View { var body: some View {
Form { Form {
@ -46,8 +46,7 @@ import PreviewViewModels
struct StartupAndSyncingPreferencesView_Previews: PreviewProvider { struct StartupAndSyncingPreferencesView_Previews: PreviewProvider {
static var previews: some View { static var previews: some View {
StartupAndSyncingPreferencesView() StartupAndSyncingPreferencesView(identityContext: .preview)
.environmentObject(IdentityContext.preview)
} }
} }
#endif #endif

View file

@ -4,14 +4,12 @@ import SwiftUI
import ViewModels import ViewModels
struct TableView: UIViewControllerRepresentable { struct TableView: UIViewControllerRepresentable {
@EnvironmentObject var identityContext: IdentityContext
@EnvironmentObject var rootViewModel: RootViewModel @EnvironmentObject var rootViewModel: RootViewModel
let viewModelClosure: () -> CollectionViewModel let viewModelClosure: () -> CollectionViewModel
func makeUIViewController(context: Context) -> TableViewController { func makeUIViewController(context: Context) -> TableViewController {
TableViewController(viewModel: viewModelClosure(), TableViewController(viewModel: viewModelClosure(),
rootViewModel: rootViewModel, rootViewModel: rootViewModel)
identityContext: identityContext)
} }
func updateUIViewController(_ uiViewController: TableViewController, context: Context) { func updateUIViewController(_ uiViewController: TableViewController, context: Context) {