mirror of
https://github.com/yattee/yattee.git
synced 2025-08-05 02:04:07 +00:00
Add button to add public instance to custom list
This commit is contained in:
29
Shared/Settings/AddPublicInstanceButton.swift
Normal file
29
Shared/Settings/AddPublicInstanceButton.swift
Normal file
@@ -0,0 +1,29 @@
|
||||
import SwiftUI
|
||||
|
||||
struct AddPublicInstanceButton: View {
|
||||
@ObservedObject private var accounts = AccountsModel.shared
|
||||
|
||||
@State private var id = UUID().uuidString
|
||||
|
||||
var body: some View {
|
||||
if let account = accounts.current, let app = account.app, account.isPublic, !account.isPublicAddedToCustom {
|
||||
Button {
|
||||
_ = InstancesModel.shared.add(app: app, name: "", url: account.urlString)
|
||||
regenerateID()
|
||||
} label: {
|
||||
Label("Add \(account.urlString)", systemImage: "plus")
|
||||
}
|
||||
.id(id)
|
||||
}
|
||||
}
|
||||
|
||||
private func regenerateID() {
|
||||
id = UUID().uuidString
|
||||
}
|
||||
}
|
||||
|
||||
struct AddPublicInstanceButton_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
AddPublicInstanceButton()
|
||||
}
|
||||
}
|
@@ -93,6 +93,7 @@ struct LocationsSettings: View {
|
||||
ForEach(instances) { instance in
|
||||
AccountsNavigationLink(instance: instance)
|
||||
}
|
||||
AddPublicInstanceButton()
|
||||
addInstanceButton
|
||||
#endif
|
||||
}
|
||||
|
Reference in New Issue
Block a user