wip
This commit is contained in:
parent
acf2807056
commit
bec095e8de
|
@ -1,32 +0,0 @@
|
||||||
import Combine
|
|
||||||
import Foundation
|
|
||||||
import GRDB
|
|
||||||
import Photos
|
|
||||||
import SwiftUI
|
|
||||||
|
|
||||||
@MainActor
|
|
||||||
final class GlobalSettingsStore: ObservableObject {
|
|
||||||
static let shared = GlobalSettingsStore()
|
|
||||||
|
|
||||||
@Published var credentials: [Credentials] = []
|
|
||||||
|
|
||||||
private var credentialsCancellable: AnyCancellable?
|
|
||||||
|
|
||||||
init() {
|
|
||||||
subscribe()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private extension GlobalSettingsStore {
|
|
||||||
func subscribe() {
|
|
||||||
credentialsCancellable = ValueObservation.tracking(Credentials
|
|
||||||
.fetchAll
|
|
||||||
)
|
|
||||||
.publisher(in: Database.shared.dbQueue, scheduling: .immediate)
|
|
||||||
.receive(on: DispatchQueue.main)
|
|
||||||
.sink { _ in
|
|
||||||
} receiveValue: { [weak self] credentials in
|
|
||||||
self?.credentials = credentials
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -5,7 +5,6 @@ import SwiftUI
|
||||||
@MainActor
|
@MainActor
|
||||||
struct ConversationsClassic: App {
|
struct ConversationsClassic: App {
|
||||||
private let clientsStore = ClientsStore.shared
|
private let clientsStore = ClientsStore.shared
|
||||||
private let globalSettingsStore = GlobalSettingsStore.shared
|
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
// There's a bug on iOS 17 where sheet may not load with large title, even if modifiers are set, which causes some tests to fail
|
// There's a bug on iOS 17 where sheet may not load with large title, even if modifiers are set, which causes some tests to fail
|
||||||
|
@ -17,7 +16,6 @@ struct ConversationsClassic: App {
|
||||||
WindowGroup {
|
WindowGroup {
|
||||||
RootView()
|
RootView()
|
||||||
.environmentObject(clientsStore)
|
.environmentObject(clientsStore)
|
||||||
.environmentObject(globalSettingsStore)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct WelcomeScreen: View {
|
struct WelcomeScreen: View {
|
||||||
@EnvironmentObject var globalSettingsStore: GlobalSettingsStore
|
@EnvironmentObject var clientsStore: ClientsStore
|
||||||
@Environment(\.router) var router
|
@Environment(\.router) var router
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
|
@ -10,22 +10,22 @@ struct WelcomeScreen: View {
|
||||||
Color.Material.Background.light
|
Color.Material.Background.light
|
||||||
.ignoresSafeArea()
|
.ignoresSafeArea()
|
||||||
|
|
||||||
if !globalSettingsStore.credentials.isEmpty && globalSettingsStore.credentials.allSatisfy({ !$0.isActive }) {
|
// if !clientsStore.clients.isEmpty && clientsStore.clients.allSatisfy({ $0.state != .enabled(.connected) }) {
|
||||||
VStack {
|
// VStack {
|
||||||
HStack {
|
// HStack {
|
||||||
Spacer()
|
// Spacer()
|
||||||
Image(systemName: "gear")
|
// Image(systemName: "gear")
|
||||||
.foregroundColor(.Material.Elements.active)
|
// .foregroundColor(.Material.Elements.active)
|
||||||
.tappablePadding(.symmetric(10)) {
|
// .tappablePadding(.symmetric(10)) {
|
||||||
router.showScreen(.push) { _ in
|
// router.showScreen(.push) { _ in
|
||||||
SettingsScreen()
|
// SettingsScreen()
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
.padding()
|
// .padding()
|
||||||
Spacer()
|
// Spacer()
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// content
|
// content
|
||||||
VStack(spacing: 32) {
|
VStack(spacing: 32) {
|
||||||
|
|
|
@ -2,7 +2,6 @@ import SwiftUI
|
||||||
|
|
||||||
struct SettingsScreen: View {
|
struct SettingsScreen: View {
|
||||||
@EnvironmentObject var clientsStore: ClientsStore
|
@EnvironmentObject var clientsStore: ClientsStore
|
||||||
@EnvironmentObject var settingsStore: GlobalSettingsStore
|
|
||||||
@Environment(\.router) var router
|
@Environment(\.router) var router
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
|
@ -23,23 +22,23 @@ struct SettingsScreen: View {
|
||||||
// Accounts section
|
// Accounts section
|
||||||
SharedSectionTitle(text: L10n.Settings.Section.Accounts.title)
|
SharedSectionTitle(text: L10n.Settings.Section.Accounts.title)
|
||||||
|
|
||||||
ForEach(settingsStore.credentials) { creds in
|
// ForEach(settingsStore.credentials) { creds in
|
||||||
SharedListRow(
|
// SharedListRow(
|
||||||
iconType: .charCircle(creds.bareJid),
|
// iconType: .charCircle(creds.bareJid),
|
||||||
text: creds.bareJid,
|
// text: creds.bareJid,
|
||||||
controlType: .switcher(isOn: Binding(
|
// controlType: .switcher(isOn: Binding(
|
||||||
get: { creds.isActive },
|
// get: { creds.isActive },
|
||||||
set: { new in
|
// set: { new in
|
||||||
Task {
|
// Task {
|
||||||
try? await creds.setActive(flag: new)
|
// try? await creds.setActive(flag: new)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
))
|
// ))
|
||||||
)
|
// )
|
||||||
.onTapGesture {
|
// .onTapGesture {
|
||||||
print("Tapped account \(creds.bareJid)")
|
// print("Tapped account \(creds.bareJid)")
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
SharedListRow(
|
SharedListRow(
|
||||||
iconType: .image(Image(systemName: "plus"), .Material.Elements.active),
|
iconType: .image(Image(systemName: "plus"), .Material.Elements.active),
|
||||||
|
|
|
@ -3,12 +3,11 @@ import SwiftUI
|
||||||
|
|
||||||
struct RootView: View {
|
struct RootView: View {
|
||||||
@EnvironmentObject var clientsStore: ClientsStore
|
@EnvironmentObject var clientsStore: ClientsStore
|
||||||
@EnvironmentObject var globalSettingsStore: GlobalSettingsStore
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Group {
|
Group {
|
||||||
if clientsStore.ready {
|
if clientsStore.ready {
|
||||||
if clientsStore.clients.isEmpty || globalSettingsStore.credentials.allSatisfy({ !$0.isActive }) {
|
if clientsStore.clients.isEmpty {
|
||||||
RouterView { _ in
|
RouterView { _ in
|
||||||
WelcomeScreen()
|
WelcomeScreen()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue