mirror of
https://github.com/metabolist/metatext.git
synced 2025-01-08 21:15:24 +00:00
Delete identities
This commit is contained in:
parent
8d584b55da
commit
97de884213
5 changed files with 53 additions and 11 deletions
|
@ -5,6 +5,7 @@
|
||||||
"oauth.error.code-not-found" = "OAuth error: code not found";
|
"oauth.error.code-not-found" = "OAuth error: code not found";
|
||||||
"secondary-navigation.accounts" = "Accounts";
|
"secondary-navigation.accounts" = "Accounts";
|
||||||
"secondary-navigation.preferences" = "Preferences";
|
"secondary-navigation.preferences" = "Preferences";
|
||||||
|
"identities.add" = "Add";
|
||||||
"preferences" = "Preferences";
|
"preferences" = "Preferences";
|
||||||
"preferences.posting-reading" = "Posting and Reading";
|
"preferences.posting-reading" = "Posting and Reading";
|
||||||
"preferences.posting" = "Posting";
|
"preferences.posting" = "Posting";
|
||||||
|
|
|
@ -41,6 +41,12 @@ extension IdentityDatabase {
|
||||||
.eraseToAnyPublisher()
|
.eraseToAnyPublisher()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func deleteIdentity(id: UUID) -> AnyPublisher<Void, Error> {
|
||||||
|
return databaseQueue.writePublisher(updates: StoredIdentity.filter(Column("id") == id).deleteAll)
|
||||||
|
.map { _ in () }
|
||||||
|
.eraseToAnyPublisher()
|
||||||
|
}
|
||||||
|
|
||||||
func updateLastUsedAt(identityID: UUID) -> AnyPublisher<Void, Error> {
|
func updateLastUsedAt(identityID: UUID) -> AnyPublisher<Void, Error> {
|
||||||
databaseQueue.writePublisher {
|
databaseQueue.writePublisher {
|
||||||
try StoredIdentity
|
try StoredIdentity
|
||||||
|
@ -110,8 +116,8 @@ extension IdentityDatabase {
|
||||||
.eraseToAnyPublisher()
|
.eraseToAnyPublisher()
|
||||||
}
|
}
|
||||||
|
|
||||||
func identitiesObservation(excluding: UUID) -> AnyPublisher<[Identity], Error> {
|
func identitiesObservation() -> AnyPublisher<[Identity], Error> {
|
||||||
ValueObservation.tracking(Self.identitiesRequest(excluding: excluding).fetchAll)
|
ValueObservation.tracking(Self.identitiesRequest().fetchAll)
|
||||||
.removeDuplicates()
|
.removeDuplicates()
|
||||||
.publisher(in: databaseQueue, scheduling: .immediate)
|
.publisher(in: databaseQueue, scheduling: .immediate)
|
||||||
.map { $0.map(Identity.init(result:)) }
|
.map { $0.map(Identity.init(result:)) }
|
||||||
|
@ -119,7 +125,11 @@ extension IdentityDatabase {
|
||||||
}
|
}
|
||||||
|
|
||||||
func recentIdentitiesObservation(excluding: UUID) -> AnyPublisher<[Identity], Error> {
|
func recentIdentitiesObservation(excluding: UUID) -> AnyPublisher<[Identity], Error> {
|
||||||
ValueObservation.tracking(Self.identitiesRequest(excluding: excluding).limit(9).fetchAll)
|
ValueObservation.tracking(
|
||||||
|
Self.identitiesRequest()
|
||||||
|
.filter(Column("id") != excluding)
|
||||||
|
.limit(9)
|
||||||
|
.fetchAll)
|
||||||
.removeDuplicates()
|
.removeDuplicates()
|
||||||
.publisher(in: databaseQueue, scheduling: .immediate)
|
.publisher(in: databaseQueue, scheduling: .immediate)
|
||||||
.map { $0.map(Identity.init(result:)) }
|
.map { $0.map(Identity.init(result:)) }
|
||||||
|
@ -132,9 +142,8 @@ extension IdentityDatabase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private extension IdentityDatabase {
|
private extension IdentityDatabase {
|
||||||
private static func identitiesRequest(excluding: UUID) -> QueryInterfaceRequest<IdentityResult> {
|
private static func identitiesRequest() -> QueryInterfaceRequest<IdentityResult> {
|
||||||
StoredIdentity
|
StoredIdentity
|
||||||
.filter(Column("id") != excluding)
|
|
||||||
.order(Column("lastUsedAt").desc)
|
.order(Column("lastUsedAt").desc)
|
||||||
.including(optional: StoredIdentity.instance)
|
.including(optional: StoredIdentity.instance)
|
||||||
.including(optional: StoredIdentity.account)
|
.including(optional: StoredIdentity.account)
|
||||||
|
|
|
@ -69,7 +69,7 @@ extension IdentityRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
func identitiesObservation() -> AnyPublisher<[Identity], Error> {
|
func identitiesObservation() -> AnyPublisher<[Identity], Error> {
|
||||||
appEnvironment.identityDatabase.identitiesObservation(excluding: identity.id)
|
appEnvironment.identityDatabase.identitiesObservation()
|
||||||
}
|
}
|
||||||
|
|
||||||
func recentIdentitiesObservation() -> AnyPublisher<[Identity], Error> {
|
func recentIdentitiesObservation() -> AnyPublisher<[Identity], Error> {
|
||||||
|
|
|
@ -24,6 +24,12 @@ extension RootViewModel {
|
||||||
.store(in: &cancellables)
|
.store(in: &cancellables)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func deleteIdentity(id: UUID) {
|
||||||
|
environment.identityDatabase.deleteIdentity(id: id)
|
||||||
|
.sink(receiveCompletion: { _ in }, receiveValue: {})
|
||||||
|
.store(in: &cancellables)
|
||||||
|
}
|
||||||
|
|
||||||
func addIdentityViewModel() -> AddIdentityViewModel {
|
func addIdentityViewModel() -> AddIdentityViewModel {
|
||||||
AddIdentityViewModel(environment: environment)
|
AddIdentityViewModel(environment: environment)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
// Copyright © 2020 Metabolist. All rights reserved.
|
// Copyright © 2020 Metabolist. All rights reserved.
|
||||||
|
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
import KingfisherSwiftUI
|
||||||
|
|
||||||
struct IdentitiesView: View {
|
struct IdentitiesView: View {
|
||||||
@StateObject var viewModel: IdentitiesViewModel
|
@StateObject var viewModel: IdentitiesViewModel
|
||||||
@EnvironmentObject var rootViewModel: RootViewModel
|
@EnvironmentObject var rootViewModel: RootViewModel
|
||||||
|
@Environment(\.displayScale) var displayScale: CGFloat
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Form {
|
Form {
|
||||||
|
@ -12,19 +14,43 @@ struct IdentitiesView: View {
|
||||||
NavigationLink(
|
NavigationLink(
|
||||||
destination: AddIdentityView(viewModel: rootViewModel.addIdentityViewModel()),
|
destination: AddIdentityView(viewModel: rootViewModel.addIdentityViewModel()),
|
||||||
label: {
|
label: {
|
||||||
Label("add new account", systemImage: "plus")
|
Label("identities.add", systemImage: "plus.circle")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
Section {
|
Section {
|
||||||
List(viewModel.identities) { identity in
|
List {
|
||||||
Button(identity.handle) {
|
ForEach(viewModel.identities) { identity in
|
||||||
withAnimation {
|
Button {
|
||||||
rootViewModel.newIdentitySelected(id: identity.id)
|
withAnimation {
|
||||||
|
rootViewModel.newIdentitySelected(id: identity.id)
|
||||||
|
}
|
||||||
|
} label: {
|
||||||
|
HStack {
|
||||||
|
KFImage(identity.image,
|
||||||
|
options: .downsampled(dimension: 28, scaleFactor: displayScale))
|
||||||
|
Text(identity.handle)
|
||||||
|
Spacer()
|
||||||
|
if identity.id == viewModel.identity.id {
|
||||||
|
Image(systemName: "checkmark.circle")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
.disabled(identity.id == viewModel.identity.id)
|
||||||
|
.buttonStyle(PlainButtonStyle())
|
||||||
|
}
|
||||||
|
.onDelete {
|
||||||
|
guard let index = $0.first else { return }
|
||||||
|
|
||||||
|
rootViewModel.deleteIdentity(id: viewModel.identities[index].id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.toolbar {
|
||||||
|
ToolbarItem(placement: ToolbarItemPlacement.navigationBarTrailing) {
|
||||||
|
EditButton()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue