This repository has been archived by the owner on Oct 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
/
AccountView.swift
99 lines (86 loc) · 3.23 KB
/
AccountView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//
// AccountView.swift
// AccountView
//
// Created by Ethan Lipnik on 8/18/21.
//
import SwiftUI
struct AccountView: View {
// MARK: - Environment
@Environment(\.managedObjectContext) var viewContext
// MARK: - CoreData
@FetchRequest(
sortDescriptors: [],
animation: .default)
private var accounts: FetchedResults<Account>
// MARK: - Variables
let account: Account
@State var isEditing: Bool = false
@State var newNotes: String = ""
@State private var isAddingAlternateDomains: Bool = false
@State private var newAlternateDomains: String = ""
@State private var isSharing: Bool = false
// MARK: - Init
init(account: Account) {
self.account = account
let predicate = NSPredicate(format: "domain contains[c] %@", account.domain!)
self._accounts = FetchRequest(sortDescriptors: [], predicate: predicate, animation: .default)
self._newNotes = .init(initialValue: account.notes ?? "")
}
// MARK: - View
var body: some View {
// let otherAccounts = accounts.filter({ $0.username != account.username }).map({ $0 })
ScrollView {
content
// VStack {
// if !otherAccounts.isEmpty {
// Text("Other Accounts")
// .frame(maxWidth: .infinity, alignment: .leading)
// LazyVStack {
// ForEach(otherAccounts) { account in
// NavigationLink {
// AccountView(account: account)
// } label: {
// GroupBox {
// HStack {
// FaviconView(website: "https://" + account.domain)
// .frame(width: 40, height: 40)
// VStack(alignment: .leading) {
// Text(account.domain)
// .bold()
// .frame(maxWidth: .infinity, alignment: .leading)
// Text(account.username)
// .foregroundColor(Color.secondary)
// }
// }
// }
// }.buttonStyle(.plain)
// }
// }
// }
// }.padding()
}
.sheet(isPresented: $isSharing) {
MultipeerShareSheet(account: account)
}
#if os(iOS)
.navigationTitle(account.domain?.capitalizingFirstLetter() ?? "")
.toolbar {
ToolbarItem {
Button {
isSharing.toggle()
} label: {
Label("Share", systemImage: "square.and.arrow.up")
}
}
}
#else
.frame(minWidth: 300)
#endif
}
}
struct AccountView_Previews: PreviewProvider {
static var previews: some View {
AccountView(account: .init())
}
}