Show quick profile menu rather than just edit (#940)

"Edit" is a less frequent action than "Select provider server". Offer a
common place for quick actions.

One step towards #933
This commit is contained in:
Davide 2024-11-26 09:42:47 +01:00 committed by GitHub
parent 19da40d3f8
commit 1c1d2502c3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 62 additions and 40 deletions

View File

@ -73,7 +73,7 @@ private extension InstalledProfileView {
actionableNameView actionableNameView
Spacer(minLength: 10.0) Spacer(minLength: 10.0)
} else { } else {
nameView nameView()
} }
} }
statusView statusView
@ -82,14 +82,10 @@ private extension InstalledProfileView {
} }
var actionableNameView: some View { var actionableNameView: some View {
ThemeDisclosableMenu { ThemeDisclosableMenu(content: menuContent, label: nameView)
menuContent
} label: {
nameView
}
} }
var nameView: some View { func nameView() -> some View {
Text(profile?.name ?? Strings.Views.App.Rows.notInstalled) Text(profile?.name ?? Strings.Views.App.Rows.notInstalled)
.font(.title2) .font(.title2)
.fontWeight(theme.relevantWeight) .fontWeight(theme.relevantWeight)
@ -120,7 +116,7 @@ private extension InstalledProfileView {
) )
} }
var menuContent: some View { func menuContent() -> some View {
ProfileContextMenu( ProfileContextMenu(
profileManager: profileManager, profileManager: profileManager,
tunnel: tunnel, tunnel: tunnel,

View File

@ -71,16 +71,8 @@ struct ProfileRowView: View, Routable, SizeClassProviding {
} }
Spacer() Spacer()
HStack(spacing: 8) { HStack(spacing: 8) {
ProfileAttributesView( attributesView
attributes: attributes, infoButton
isRemoteImportingEnabled: profileManager.isRemoteImportingEnabled
)
.imageScale(isBigDevice ? .large : .medium)
ProfileInfoButton(preview: preview) {
flow?.onEditProfile($0)
}
.imageScale(.large)
} }
} }
Spacer(minLength: .zero) Spacer(minLength: .zero)
@ -88,6 +80,33 @@ struct ProfileRowView: View, Routable, SizeClassProviding {
} }
} }
private extension ProfileRowView {
var profile: Profile? {
profileManager.profile(withId: preview.id)
}
var attributes: [ProfileAttributesView.Attribute] {
if isTV {
return [.tv]
} else if isShared {
return [.shared]
}
return []
}
var requiredFeatures: Set<AppFeature>? {
profileManager.requiredFeatures(forProfileWithId: preview.id)
}
var isShared: Bool {
profileManager.isRemotelyShared(profileWithId: preview.id)
}
var isTV: Bool {
isShared && profileManager.isAvailableForTV(profileWithId: preview.id)
}
}
// MARK: - Subviews (observing) // MARK: - Subviews (observing)
private struct MarkerView: View { private struct MarkerView: View {
@ -114,10 +133,6 @@ private struct MarkerView: View {
} }
private extension ProfileRowView { private extension ProfileRowView {
var profile: Profile? {
profileManager.profile(withId: preview.id)
}
var markerView: some View { var markerView: some View {
MarkerView( MarkerView(
profileId: preview.id, profileId: preview.id,
@ -152,25 +167,36 @@ private extension ProfileRowView {
.foregroundStyle(.primary) .foregroundStyle(.primary)
} }
var attributes: [ProfileAttributesView.Attribute] { var attributesView: some View {
if isTV { ProfileAttributesView(
return [.tv] attributes: attributes,
} else if isShared { isRemoteImportingEnabled: profileManager.isRemoteImportingEnabled
return [.shared] )
.imageScale(isBigDevice ? .large : .medium)
}
var infoButton: some View {
Menu {
ProfileContextMenu(
profileManager: profileManager,
tunnel: tunnel,
preview: preview,
interactiveManager: interactiveManager,
errorHandler: errorHandler,
isInstalledProfile: false,
flow: flow
)
} label: {
ThemeImage(.moreDetails)
.imageScale(.large)
} }
return [] // TODO: #584, necessary to avoid cell selection
} #if os(iOS)
.menuStyle(.borderlessButton)
var requiredFeatures: Set<AppFeature>? { #else
profileManager.requiredFeatures(forProfileWithId: preview.id) .foregroundStyle(.secondary)
} .buttonStyle(.plain)
#endif
var isShared: Bool {
profileManager.isRemotelyShared(profileWithId: preview.id)
}
var isTV: Bool {
isShared && profileManager.isAvailableForTV(profileWithId: preview.id)
} }
} }