wip
This commit is contained in:
parent
5fe8762e1f
commit
50d64cf96b
|
@ -10,6 +10,7 @@ typealias DBStorable = Codable & FetchableRecord & Identifiable & PersistableRec
|
|||
final class Database {
|
||||
static let shared = Database()
|
||||
let dbQueue: DatabaseQueue
|
||||
private var dbPath: String
|
||||
|
||||
private init() {
|
||||
do {
|
||||
|
@ -25,6 +26,7 @@ final class Database {
|
|||
// Open or create the database
|
||||
let databaseURL = directoryURL.appendingPathComponent("db.sqlite")
|
||||
dbQueue = try DatabaseQueue(path: databaseURL.path, configuration: Database.config)
|
||||
dbPath = databaseURL.path
|
||||
|
||||
// Some debug info
|
||||
#if DEBUG
|
||||
|
@ -53,3 +55,17 @@ private extension Database {
|
|||
return config
|
||||
}()
|
||||
}
|
||||
|
||||
// MARK: - flush all data for debug
|
||||
#if DEBUG
|
||||
extension Database {
|
||||
func flushAllData() {
|
||||
// nullable queue and remove db file
|
||||
do {
|
||||
try FileManager.default.removeItem(atPath: dbPath)
|
||||
} catch {
|
||||
print("Error: \(error)")
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -193,3 +193,16 @@ private extension ClientsStore {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Remove all data for debug
|
||||
#if DEBUG
|
||||
extension ClientsStore {
|
||||
func flushAllData() {
|
||||
clients.forEach { $0.disconnect() }
|
||||
clients.removeAll()
|
||||
actualRosters.removeAll()
|
||||
actualChats.removeAll()
|
||||
ready = false
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -59,7 +59,7 @@ struct ChatsCreateScreenMain: View {
|
|||
print("Tapped findChannel")
|
||||
}
|
||||
|
||||
// for contacts list
|
||||
// for contacts list (later)
|
||||
// let rosters = store.state.rostersState.rosters.filter { !$0.locallyDeleted }
|
||||
// if rosters.isEmpty {
|
||||
// ChatsCreateRowSeparator()
|
||||
|
|
|
@ -1,16 +1,26 @@
|
|||
import SwiftUI
|
||||
|
||||
struct SettingsScreen: View {
|
||||
@EnvironmentObject var clientsStore: ClientsStore
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
// bg
|
||||
Color.Material.Background.light
|
||||
.ignoresSafeArea()
|
||||
|
||||
// content
|
||||
Text("Soon!")
|
||||
.font(.head1l)
|
||||
// debug buttons
|
||||
#if DEBUG
|
||||
// clean all data
|
||||
Button {
|
||||
clientsStore.flushAllData()
|
||||
Database.shared.flushAllData()
|
||||
} label: {
|
||||
Text("Clean all (for test)")
|
||||
.font(.title)
|
||||
.foregroundColor(.Material.Elements.active)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue