Fix context menus in the library, add an Add link dialog
This commit is contained in:
@ -14,6 +14,7 @@ import Views
|
||||
@State private var itemToRemove: LinkedItem?
|
||||
@State private var confirmationShown = false
|
||||
@State private var presentProfileSheet = false
|
||||
@State private var addLinkPresented = false
|
||||
|
||||
@Namespace var mainNamespace
|
||||
|
||||
@ -62,6 +63,15 @@ import Views
|
||||
}
|
||||
}
|
||||
|
||||
var addLinkButton: some View {
|
||||
Button(
|
||||
action: {
|
||||
addLinkPresented = true
|
||||
},
|
||||
label: { Label("Add Link", systemImage: "plus") }
|
||||
)
|
||||
}
|
||||
|
||||
var refreshButton: some View {
|
||||
Button(
|
||||
action: {
|
||||
@ -98,7 +108,6 @@ import Views
|
||||
}
|
||||
Divider().padding(5)
|
||||
}
|
||||
.prefersDefaultFocus(true, in: mainNamespace)
|
||||
|
||||
if viewModel.isLoading {
|
||||
LoadingSection()
|
||||
@ -112,6 +121,7 @@ import Views
|
||||
}
|
||||
.toolbar {
|
||||
Spacer()
|
||||
addLinkButton
|
||||
refreshButton
|
||||
}
|
||||
}
|
||||
@ -150,6 +160,10 @@ import Views
|
||||
.sheet(isPresented: $presentProfileSheet) {
|
||||
ProfileView()
|
||||
}
|
||||
.sheet(isPresented: $addLinkPresented) {
|
||||
LibraryAddLinkView()
|
||||
.frame(width: 450, height: 160)
|
||||
}
|
||||
.onReceive(NSNotification.displayProfilePublisher) { _ in
|
||||
presentProfileSheet = true
|
||||
}
|
||||
|
||||
@ -10,6 +10,8 @@ import Views
|
||||
@Published var errorMessage: String = ""
|
||||
@Published var showErrorMessage: Bool = false
|
||||
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
|
||||
func addLink(dataService: DataService, newLinkURL: String, dismiss: DismissAction) {
|
||||
isLoading = true
|
||||
Task {
|
||||
@ -48,44 +50,21 @@ struct LibraryAddLinkView: View {
|
||||
@FocusState private var focusedField: FocusField?
|
||||
|
||||
var body: some View {
|
||||
innerBody
|
||||
.navigationTitle("Add Link")
|
||||
#if os(iOS)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
#endif
|
||||
Group {
|
||||
#if os(iOS)
|
||||
Form {
|
||||
innerBody
|
||||
.navigationTitle("Add Link")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
}
|
||||
#else
|
||||
innerBody
|
||||
#endif
|
||||
}
|
||||
.padding()
|
||||
.onAppear {
|
||||
focusedField = .addLinkEditor
|
||||
}
|
||||
}
|
||||
|
||||
var pasteboardString: String? {
|
||||
#if os(iOS)
|
||||
UIPasteboard.general.url?.absoluteString
|
||||
#else
|
||||
NSPasteboard.general.string(forType: NSPasteboard.PasteboardType.URL)
|
||||
#endif
|
||||
}
|
||||
|
||||
var innerBody: some View {
|
||||
Form {
|
||||
TextField("Add Link", text: $newLinkURL)
|
||||
#if os(iOS)
|
||||
.keyboardType(.URL)
|
||||
#endif
|
||||
.autocorrectionDisabled(true)
|
||||
.textFieldStyle(StandardTextFieldStyle())
|
||||
.focused($focusedField, equals: .addLinkEditor)
|
||||
|
||||
Button(action: {
|
||||
if let url = pasteboardString {
|
||||
newLinkURL = url
|
||||
} else {
|
||||
viewModel.error("No URL on pasteboard")
|
||||
}
|
||||
}, label: {
|
||||
Text("Get from pasteboard")
|
||||
})
|
||||
}
|
||||
.navigationTitle("Add Link")
|
||||
#if os(iOS)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
@ -104,6 +83,53 @@ struct LibraryAddLinkView: View {
|
||||
}
|
||||
}
|
||||
|
||||
var cancelButton: some View {
|
||||
Button(
|
||||
action: { dismiss() },
|
||||
label: { Text(LocalText.cancelGeneric).foregroundColor(.appGrayTextContrast) }
|
||||
)
|
||||
}
|
||||
|
||||
var pasteboardString: String? {
|
||||
#if os(iOS)
|
||||
UIPasteboard.general.url?.absoluteString
|
||||
#else
|
||||
NSPasteboard.general.string(forType: NSPasteboard.PasteboardType.URL)
|
||||
#endif
|
||||
}
|
||||
|
||||
var innerBody: some View {
|
||||
Group {
|
||||
TextField("Add Link", text: $newLinkURL)
|
||||
#if os(iOS)
|
||||
.keyboardType(.URL)
|
||||
#endif
|
||||
.autocorrectionDisabled(true)
|
||||
.textFieldStyle(StandardTextFieldStyle())
|
||||
.focused($focusedField, equals: .addLinkEditor)
|
||||
|
||||
Button(action: {
|
||||
if let url = pasteboardString {
|
||||
newLinkURL = url
|
||||
} else {
|
||||
viewModel.error("No URL on pasteboard")
|
||||
}
|
||||
}, label: {
|
||||
Text("Get from pasteboard")
|
||||
})
|
||||
|
||||
#if os(macOS)
|
||||
Spacer()
|
||||
HStack {
|
||||
cancelButton
|
||||
Spacer()
|
||||
addButton
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
var addButton: some View {
|
||||
Button(
|
||||
action: {
|
||||
@ -111,6 +137,10 @@ struct LibraryAddLinkView: View {
|
||||
},
|
||||
label: { Text("Add").bold() }
|
||||
)
|
||||
.keyboardShortcut(.defaultAction)
|
||||
.onSubmit {
|
||||
viewModel.addLink(dataService: dataService, newLinkURL: newLinkURL, dismiss: dismiss)
|
||||
}
|
||||
.disabled(viewModel.isLoading)
|
||||
}
|
||||
|
||||
|
||||
@ -45,7 +45,9 @@ struct LibraryTabView: View {
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
HomeView(viewModel: libraryViewModel)
|
||||
#if os(iOS)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -98,6 +98,12 @@ struct LinkedItemMetadataEditView: View {
|
||||
.navigationTitle("Edit Title and Description")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .barLeading) {
|
||||
Button(
|
||||
action: { presentationMode.wrappedValue.dismiss() },
|
||||
label: { Text(LocalText.cancelGeneric).foregroundColor(.appGrayTextContrast) }
|
||||
)
|
||||
}
|
||||
ToolbarItem(placement: .barTrailing) {
|
||||
Button(
|
||||
action: {
|
||||
@ -110,12 +116,6 @@ struct LinkedItemMetadataEditView: View {
|
||||
label: { Text(LocalText.genericSave).foregroundColor(.appGrayTextContrast) }
|
||||
)
|
||||
}
|
||||
ToolbarItem(placement: .barLeading) {
|
||||
Button(
|
||||
action: { presentationMode.wrappedValue.dismiss() },
|
||||
label: { Text(LocalText.cancelGeneric).foregroundColor(.appGrayTextContrast) }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -92,7 +92,9 @@ import Views
|
||||
.sheet(isPresented: $addLinkPresented) {
|
||||
NavigationView {
|
||||
LibraryAddLinkView()
|
||||
#if os(iOS)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user