2020-08-04 22:26:09 +02:00
|
|
|
// Copyright © 2020 Metabolist. All rights reserved.
|
|
|
|
|
2020-08-08 09:43:06 +02:00
|
|
|
import KingfisherSwiftUI
|
2020-09-05 04:31:43 +02:00
|
|
|
import SwiftUI
|
2020-09-01 09:33:49 +02:00
|
|
|
import ViewModels
|
2020-08-04 22:26:09 +02:00
|
|
|
|
|
|
|
struct IdentitiesView: View {
|
|
|
|
@StateObject var viewModel: IdentitiesViewModel
|
|
|
|
@EnvironmentObject var rootViewModel: RootViewModel
|
2020-08-08 09:43:06 +02:00
|
|
|
@Environment(\.displayScale) var displayScale: CGFloat
|
2020-08-04 22:26:09 +02:00
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
Form {
|
|
|
|
Section {
|
|
|
|
NavigationLink(
|
|
|
|
destination: AddIdentityView(viewModel: rootViewModel.addIdentityViewModel()),
|
|
|
|
label: {
|
2020-08-29 05:50:58 +02:00
|
|
|
Label("add", systemImage: "plus.circle")
|
2020-08-04 22:26:09 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
Section {
|
2020-08-08 09:43:06 +02:00
|
|
|
List {
|
|
|
|
ForEach(viewModel.identities) { identity in
|
|
|
|
Button {
|
|
|
|
withAnimation {
|
|
|
|
rootViewModel.newIdentitySelected(id: identity.id)
|
|
|
|
}
|
|
|
|
} label: {
|
|
|
|
HStack {
|
|
|
|
KFImage(identity.image,
|
2020-08-08 11:10:05 +02:00
|
|
|
options: .downsampled(dimension: 40, scaleFactor: displayScale))
|
|
|
|
VStack(alignment: .leading, spacing: 0) {
|
|
|
|
Spacer()
|
|
|
|
if let account = identity.account {
|
|
|
|
CustomEmojiText(
|
|
|
|
text: account.displayName,
|
|
|
|
emoji: account.emojis,
|
|
|
|
textStyle: .headline)
|
|
|
|
}
|
|
|
|
Text(identity.handle)
|
|
|
|
.font(.subheadline)
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
Spacer()
|
|
|
|
}
|
2020-08-08 09:43:06 +02:00
|
|
|
Spacer()
|
|
|
|
if identity.id == viewModel.identity.id {
|
|
|
|
Image(systemName: "checkmark.circle")
|
|
|
|
}
|
|
|
|
}
|
2020-08-07 03:41:59 +02:00
|
|
|
}
|
2020-08-08 09:43:06 +02:00
|
|
|
.disabled(identity.id == viewModel.identity.id)
|
|
|
|
.buttonStyle(PlainButtonStyle())
|
|
|
|
}
|
|
|
|
.onDelete {
|
|
|
|
guard let index = $0.first else { return }
|
|
|
|
|
2020-08-14 05:40:46 +02:00
|
|
|
rootViewModel.deleteIdentity(viewModel.identities[index])
|
2020-08-04 22:26:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-08-08 09:43:06 +02:00
|
|
|
.toolbar {
|
|
|
|
ToolbarItem(placement: ToolbarItemPlacement.navigationBarTrailing) {
|
|
|
|
EditButton()
|
|
|
|
}
|
|
|
|
}
|
2020-08-04 22:26:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-12 09:37:14 +02:00
|
|
|
#if DEBUG
|
2020-09-01 09:33:49 +02:00
|
|
|
import PreviewViewModels
|
|
|
|
|
2020-08-04 22:26:09 +02:00
|
|
|
struct IdentitiesView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
2020-09-01 09:33:49 +02:00
|
|
|
IdentitiesView(viewModel: .mock())
|
|
|
|
.environmentObject(RootViewModel.mock())
|
2020-08-04 22:26:09 +02:00
|
|
|
}
|
|
|
|
}
|
2020-08-12 09:37:14 +02:00
|
|
|
#endif
|