2020-08-08 06:01:45 +00:00
|
|
|
// Copyright © 2020 Metabolist. All rights reserved.
|
|
|
|
|
|
|
|
import KingfisherSwiftUI
|
2020-09-05 02:31:43 +00:00
|
|
|
import SwiftUI
|
2020-09-01 07:33:49 +00:00
|
|
|
import ViewModels
|
2020-08-08 06:01:45 +00:00
|
|
|
|
|
|
|
struct SecondaryNavigationView: View {
|
2020-09-09 23:00:10 +00:00
|
|
|
@ObservedObject var viewModel: NavigationViewModel
|
2020-09-09 22:48:56 +00:00
|
|
|
@EnvironmentObject var rootViewModel: RootViewModel
|
2020-08-08 06:01:45 +00:00
|
|
|
@Environment(\.displayScale) var displayScale: CGFloat
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
NavigationView {
|
|
|
|
Form {
|
|
|
|
Section {
|
|
|
|
NavigationLink(
|
2020-09-09 23:40:40 +00:00
|
|
|
destination: IdentitiesView(viewModel: .init(identification: viewModel.identification)),
|
2020-08-08 06:01:45 +00:00
|
|
|
label: {
|
|
|
|
HStack {
|
2020-09-09 23:40:40 +00:00
|
|
|
KFImage(viewModel.identification.identity.image,
|
2020-10-12 05:37:34 +00:00
|
|
|
options: .downsampled(dimension: .avatarDimension, scaleFactor: displayScale))
|
2020-08-08 06:01:45 +00:00
|
|
|
VStack(alignment: .leading) {
|
2020-09-09 23:40:40 +00:00
|
|
|
if viewModel.identification.identity.authenticated {
|
|
|
|
if let account = viewModel.identification.identity.account {
|
2020-09-09 05:40:49 +00:00
|
|
|
CustomEmojiText(
|
|
|
|
text: account.displayName,
|
|
|
|
emoji: account.emojis,
|
|
|
|
textStyle: .headline)
|
|
|
|
}
|
2020-09-09 23:40:40 +00:00
|
|
|
Text(viewModel.identification.identity.handle)
|
2020-09-09 05:40:49 +00:00
|
|
|
.font(.subheadline)
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
.lineLimit(1)
|
|
|
|
.minimumScaleFactor(0.5)
|
|
|
|
} else {
|
2020-09-09 23:40:40 +00:00
|
|
|
Text(viewModel.identification.identity.handle)
|
2020-09-09 05:40:49 +00:00
|
|
|
.font(.headline)
|
2020-09-09 23:40:40 +00:00
|
|
|
if let instance = viewModel.identification.identity.instance {
|
2020-09-09 05:40:49 +00:00
|
|
|
Text(instance.uri)
|
|
|
|
.font(.subheadline)
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
.lineLimit(1)
|
|
|
|
.minimumScaleFactor(0.5)
|
|
|
|
}
|
2020-08-08 09:10:05 +00:00
|
|
|
}
|
2020-09-09 05:40:49 +00:00
|
|
|
|
2020-08-08 06:01:45 +00:00
|
|
|
Spacer()
|
2020-08-08 09:10:05 +00:00
|
|
|
Text("secondary-navigation.manage-accounts")
|
2020-08-08 06:01:45 +00:00
|
|
|
.font(.subheadline)
|
|
|
|
}
|
|
|
|
.padding()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2020-08-29 03:50:58 +00:00
|
|
|
Section {
|
2020-09-09 23:40:40 +00:00
|
|
|
NavigationLink(destination: ListsView(viewModel: .init(identification: viewModel.identification))) {
|
2020-08-29 03:50:58 +00:00
|
|
|
Label("secondary-navigation.lists", systemImage: "scroll")
|
|
|
|
}
|
|
|
|
}
|
2020-08-08 06:01:45 +00:00
|
|
|
Section {
|
|
|
|
NavigationLink(
|
|
|
|
"secondary-navigation.preferences",
|
|
|
|
destination: PreferencesView(
|
2020-09-09 23:40:40 +00:00
|
|
|
viewModel: .init(identification: viewModel.identification)))
|
2020-08-08 06:01:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
|
|
.toolbar {
|
|
|
|
ToolbarItem(placement: .cancellationAction) {
|
|
|
|
Button {
|
2020-09-09 22:48:56 +00:00
|
|
|
viewModel.presentingSecondaryNavigation = false
|
2020-08-08 06:01:45 +00:00
|
|
|
} label: {
|
|
|
|
Image(systemName: "xmark.circle.fill")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.navigationViewStyle(StackNavigationViewStyle())
|
2020-09-09 23:40:40 +00:00
|
|
|
.environmentObject(viewModel.identification)
|
2020-08-08 06:01:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if DEBUG
|
2020-09-01 07:33:49 +00:00
|
|
|
import PreviewViewModels
|
|
|
|
|
2020-08-08 06:01:45 +00:00
|
|
|
struct SecondaryNavigationView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
2020-09-09 23:00:10 +00:00
|
|
|
SecondaryNavigationView(viewModel: NavigationViewModel(identification: .preview))
|
2020-09-09 22:48:56 +00:00
|
|
|
.environmentObject(RootViewModel.preview)
|
2020-08-08 06:01:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|