refactor(share): popover instead of modal sheet, redesigned layout

Share button now opens a popover anchored to the toolbar icon instead
of a full modal window. Redesigned the content as a narrow vertical
card (icon section headers, avatar-initial rows for members, link
card with collapsible title override) sized to fit the People section
without scrolling in the common case.
This commit is contained in:
2026-08-14 22:06:04 +01:00
parent 7216633299
commit 9ca1c77bb9
2 changed files with 168 additions and 81 deletions
@@ -111,6 +111,9 @@ struct DocumentReaderView: View {
Image(systemName: "square.and.arrow.up") Image(systemName: "square.and.arrow.up")
} }
.help("Share") .help("Share")
.popover(isPresented: $isShowingShareSheet, arrowEdge: .bottom) {
DocumentShareSheet(apiClient: apiClient, documentId: viewModel.documentId)
}
Button { Button {
Task { await viewModel.toggleEditing() } Task { await viewModel.toggleEditing() }
@@ -215,9 +218,6 @@ struct DocumentReaderView: View {
.sheet(isPresented: $isShowingSearchSheet) { .sheet(isPresented: $isShowingSearchSheet) {
DocumentSearchSheet(apiClient: apiClient, document: document) DocumentSearchSheet(apiClient: apiClient, document: document)
} }
.sheet(isPresented: $isShowingShareSheet) {
DocumentShareSheet(apiClient: apiClient, documentId: viewModel.documentId)
}
.sheet(isPresented: $isShowingNewDocumentSheet) { .sheet(isPresented: $isShowingNewDocumentSheet) {
NewDocumentSheet(apiClient: apiClient, initialParentDocument: document) { child in NewDocumentSheet(apiClient: apiClient, initialParentDocument: document) { child in
onDocumentCreated() onDocumentCreated()
@@ -3,10 +3,12 @@ import AppKit
import SwiftUI import SwiftUI
import OutlineKit import OutlineKit
/// Content of the Share popover anchored to the reader toolbar's Share
/// button (see `DocumentReaderView`'s `.popover(isPresented:)`). Was a
/// modal `.sheet` originally moved to a popover so it reads as "options
/// for this button" instead of interrupting the whole window.
@MainActor @MainActor
struct DocumentShareSheet: View { struct DocumentShareSheet: View {
@Environment(\.dismiss) private var dismiss
let apiClient: OutlineAPIClient let apiClient: OutlineAPIClient
let documentId: String let documentId: String
@@ -16,6 +18,7 @@ struct DocumentShareSheet: View {
@State private var isUpdatingShare = false @State private var isUpdatingShare = false
@State private var isRevoking = false @State private var isRevoking = false
@State private var isShowingRevokeConfirmation = false @State private var isShowingRevokeConfirmation = false
@State private var isShowingTitleField = false
@State private var shareErrorMessage: String? @State private var shareErrorMessage: String?
@State private var didCopy = false @State private var didCopy = false
@@ -30,22 +33,25 @@ struct DocumentShareSheet: View {
@State private var actionErrorMessage: String? @State private var actionErrorMessage: String?
var body: some View { var body: some View {
VStack(alignment: .leading, spacing: 16) { VStack(alignment: .leading, spacing: 0) {
HStack {
Text("Share") Text("Share")
.font(.headline) .font(.headline)
Spacer() .padding(.horizontal, 16)
Button("Done") { dismiss() } .padding(.top, 14)
} .padding(.bottom, 10)
shareLinkSection
Divider() Divider()
ScrollView {
VStack(alignment: .leading, spacing: 18) {
shareLinkSection
peopleSection peopleSection
} }
.padding(20) .padding(16)
.frame(width: 380) }
.frame(minHeight: 150, maxHeight: 900)
}
.frame(width: 280)
.task { await loadShare() } .task { await loadShare() }
.task { await loadMembers() } .task { await loadMembers() }
.task(id: userSearchQuery) { .task(id: userSearchQuery) {
@@ -72,70 +78,105 @@ struct DocumentShareSheet: View {
} }
} }
// MARK: - Link section
@ViewBuilder @ViewBuilder
private var shareLinkSection: some View { private var shareLinkSection: some View {
VStack(alignment: .leading, spacing: 8) {
sectionHeader(icon: "link", title: "Public Link")
if isLoadingShare { if isLoadingShare {
ProgressView().frame(maxWidth: .infinity) ProgressView()
.controlSize(.small)
.frame(maxWidth: .infinity, alignment: .center)
} else if let shareErrorMessage { } else if let shareErrorMessage {
Text(shareErrorMessage) Text(shareErrorMessage)
.font(.callout) .font(.callout)
.foregroundStyle(.red) .foregroundStyle(.red)
} else if let share { } else if let share {
VStack(alignment: .leading, spacing: 6) {
if let url = share.url { if let url = share.url {
HStack { HStack(spacing: 8) {
Image(systemName: "globe")
.foregroundStyle(.secondary)
.font(.callout)
Text(url) Text(url)
.font(.callout) .font(.callout)
.lineLimit(1) .lineLimit(1)
.truncationMode(.middle) .truncationMode(.middle)
Spacer() Spacer(minLength: 0)
Button { Button {
copyLink(url) copyLink(url)
} label: { } label: {
Image(systemName: didCopy ? "checkmark" : "doc.on.doc") Image(systemName: didCopy ? "checkmark" : "doc.on.doc")
.font(.callout)
} }
.buttonStyle(.plain) .buttonStyle(.plain)
.foregroundStyle(didCopy ? .green : .secondary)
.help("Copy link")
} }
.padding(8)
.background(.fill.tertiary, in: RoundedRectangle(cornerRadius: 6))
} }
VStack(alignment: .leading, spacing: 4) { if isShowingTitleField {
Text("Public page title") TextField("Public page title", text: $titleOverride)
.font(.caption)
.foregroundStyle(.secondary)
TextField("Uses the document's title if empty", text: $titleOverride)
.textFieldStyle(.roundedBorder) .textFieldStyle(.roundedBorder)
.font(.callout)
.disabled(isUpdatingShare) .disabled(isUpdatingShare)
.onSubmit { .onSubmit {
Task { await setTitle(titleOverride) } Task { await setTitle(titleOverride) }
} }
} }
}
.padding(10)
.background(.fill.tertiary, in: RoundedRectangle(cornerRadius: 8))
Button("Revoke Link", role: .destructive) { HStack(spacing: 12) {
Button(isShowingTitleField ? "Hide title field" : "Set public title") {
isShowingTitleField.toggle()
}
.buttonStyle(.plain)
.font(.caption)
.foregroundStyle(.secondary)
Spacer()
Button("Revoke", role: .destructive) {
isShowingRevokeConfirmation = true isShowingRevokeConfirmation = true
} }
.buttonStyle(.plain)
.font(.caption)
.foregroundStyle(.red)
.disabled(isRevoking) .disabled(isRevoking)
}
} else { } else {
Button("Create Share Link") { Button {
Task { await create() } Task { await create() }
} label: {
Label("Create Share Link", systemImage: "link.badge.plus")
.frame(maxWidth: .infinity)
}
.buttonStyle(.bordered)
.controlSize(.regular)
} }
} }
} }
// MARK: - People section
@ViewBuilder @ViewBuilder
private var peopleSection: some View { private var peopleSection: some View {
VStack(alignment: .leading, spacing: 8) { VStack(alignment: .leading, spacing: 8) {
HStack { HStack {
Text("People with access") sectionHeader(icon: "person.2", title: "People with Access")
.font(.caption)
.foregroundStyle(.secondary)
Spacer() Spacer()
Button { Button {
isShowingAddPerson.toggle() isShowingAddPerson.toggle()
} label: { } label: {
Image(systemName: "person.badge.plus") Image(systemName: isShowingAddPerson ? "xmark.circle.fill" : "person.badge.plus")
.font(.callout)
} }
.buttonStyle(.plain) .buttonStyle(.plain)
.foregroundStyle(.secondary)
.help("Add a person") .help("Add a person")
} }
@@ -144,21 +185,37 @@ struct DocumentShareSheet: View {
} }
if isLoadingMembers { if isLoadingMembers {
ProgressView().controlSize(.small) ProgressView()
.controlSize(.small)
.frame(maxWidth: .infinity, alignment: .center)
} else if members.isEmpty { } else if members.isEmpty {
Text("No one else has explicit access yet.") Text("No one else has explicit access yet.")
.font(.callout) .font(.callout)
.foregroundStyle(.secondary) .foregroundStyle(.secondary)
} else { } else {
VStack(spacing: 2) {
ForEach(members) { member in ForEach(members) { member in
memberRow(member) memberRow(member)
} }
} }
} }
} }
}
private func sectionHeader(icon: String, title: String) -> some View {
HStack(spacing: 6) {
Image(systemName: icon)
.font(.caption)
.foregroundStyle(.secondary)
Text(title)
.font(.caption.weight(.semibold))
.foregroundStyle(.secondary)
.textCase(.uppercase)
}
}
private var addPersonSection: some View { private var addPersonSection: some View {
VStack(alignment: .leading, spacing: 6) { VStack(alignment: .leading, spacing: 8) {
TextField("Search people by name or email", text: $userSearchQuery) TextField("Search people by name or email", text: $userSearchQuery)
.textFieldStyle(.roundedBorder) .textFieldStyle(.roundedBorder)
@@ -170,24 +227,30 @@ struct DocumentShareSheet: View {
.labelsHidden() .labelsHidden()
if isSearchingUsers { if isSearchingUsers {
ProgressView().controlSize(.small) ProgressView()
.controlSize(.small)
.frame(maxWidth: .infinity, alignment: .center)
} else if !userSearchQuery.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty { } else if !userSearchQuery.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
if userSearchResults.isEmpty { if userSearchResults.isEmpty {
Text("No matches.") Text("No matches.")
.font(.callout) .font(.callout)
.foregroundStyle(.secondary) .foregroundStyle(.secondary)
} else { } else {
VStack(spacing: 2) {
ForEach(userSearchResults) { user in ForEach(userSearchResults) { user in
Button { Button {
Task { await addUser(user) } Task { await addUser(user) }
} label: { } label: {
HStack { HStack(spacing: 8) {
avatar(for: user.name)
Text(user.name) Text(user.name)
.font(.callout) .font(.callout)
Spacer() Spacer(minLength: 0)
Image(systemName: "plus.circle") Image(systemName: "plus.circle")
.foregroundStyle(.secondary)
} }
.contentShape(Rectangle()) .contentShape(Rectangle())
.padding(.vertical, 4)
} }
.buttonStyle(.plain) .buttonStyle(.plain)
.disabled(isAddingUser) .disabled(isAddingUser)
@@ -195,19 +258,24 @@ struct DocumentShareSheet: View {
} }
} }
} }
.padding(8) }
.background(.fill.tertiary, in: RoundedRectangle(cornerRadius: 6)) .padding(10)
.background(.fill.tertiary, in: RoundedRectangle(cornerRadius: 8))
} }
private func memberRow(_ member: OutlineDocumentMember) -> some View { private func memberRow(_ member: OutlineDocumentMember) -> some View {
HStack { HStack(spacing: 8) {
avatar(for: member.name)
Text(member.name) Text(member.name)
.font(.callout) .font(.callout)
Spacer() Spacer(minLength: 0)
if let permission = member.permission { if let permission = member.permission {
Text(permission == "read_write" ? "Can edit" : "Can view") Text(permission == "read_write" ? "Can edit" : "Can view")
.font(.caption) .font(.caption)
.foregroundStyle(.secondary) .foregroundStyle(.secondary)
.padding(.horizontal, 6)
.padding(.vertical, 2)
.background(.fill.tertiary, in: Capsule())
} }
Button { Button {
Task { await removeUser(member) } Task { await removeUser(member) }
@@ -217,6 +285,24 @@ struct DocumentShareSheet: View {
} }
.buttonStyle(.plain) .buttonStyle(.plain)
} }
.padding(.vertical, 4)
}
private func avatar(for name: String) -> some View {
Circle()
.fill(.fill.secondary)
.frame(width: 22, height: 22)
.overlay {
Text(initials(for: name))
.font(.system(size: 10, weight: .semibold))
.foregroundStyle(.secondary)
}
}
private func initials(for name: String) -> String {
let parts = name.split(separator: " ").prefix(2)
let letters = parts.compactMap { $0.first }
return letters.isEmpty ? "?" : String(letters).uppercased()
} }
private func copyLink(_ url: String) { private func copyLink(_ url: String) {
@@ -275,6 +361,7 @@ struct DocumentShareSheet: View {
try await apiClient.revokeShare(id: share.id) try await apiClient.revokeShare(id: share.id)
self.share = nil self.share = nil
titleOverride = "" titleOverride = ""
isShowingTitleField = false
} catch { } catch {
actionErrorMessage = outlineErrorMessage(error, fallback: "Couldn't revoke this share link.") actionErrorMessage = outlineErrorMessage(error, fallback: "Couldn't revoke this share link.")
} }