Add button to add public instance to custom list

This commit is contained in:
Arkadiusz Fal
2023-07-25 13:08:21 +02:00
parent 548908b26f
commit 19d11a3ad9
6 changed files with 54 additions and 2 deletions

View File

@@ -60,6 +60,10 @@ struct Account: Defaults.Serializable, Hashable, Identifiable {
instanceID.isNil
}
var isPublicAddedToCustom: Bool {
InstancesModel.shared.findByURLString(urlString) != nil
}
var description: String {
guard !isPublic else {
return name

View File

@@ -32,6 +32,12 @@ final class InstancesModel: ObservableObject {
return Defaults[.instances].first { $0.id == id }
}
func findByURLString(_ urlString: String?) -> Instance? {
guard let urlString else { return nil }
return Defaults[.instances].first { $0.apiURLString == urlString }
}
func accounts(_ id: Instance.ID?) -> [Account] {
Defaults[.accounts].filter { $0.instanceID == id }
}