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

View File

@ -71,16 +71,8 @@ struct ProfileRowView: View, Routable, SizeClassProviding {
}
Spacer()
HStack(spacing: 8) {
ProfileAttributesView(
attributes: attributes,
isRemoteImportingEnabled: profileManager.isRemoteImportingEnabled
)
.imageScale(isBigDevice ? .large : .medium)
ProfileInfoButton(preview: preview) {
flow?.onEditProfile($0)
}
.imageScale(.large)
attributesView
infoButton
}
}
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)
private struct MarkerView: View {
@ -114,10 +133,6 @@ private struct MarkerView: View {
}
private extension ProfileRowView {
var profile: Profile? {
profileManager.profile(withId: preview.id)
}
var markerView: some View {
MarkerView(
profileId: preview.id,
@ -152,25 +167,36 @@ private extension ProfileRowView {
.foregroundStyle(.primary)
}
var attributes: [ProfileAttributesView.Attribute] {
if isTV {
return [.tv]
} else if isShared {
return [.shared]
var attributesView: some View {
ProfileAttributesView(
attributes: attributes,
isRemoteImportingEnabled: profileManager.isRemoteImportingEnabled
)
.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 []
}
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)
// TODO: #584, necessary to avoid cell selection
#if os(iOS)
.menuStyle(.borderlessButton)
#else
.foregroundStyle(.secondary)
.buttonStyle(.plain)
#endif
}
}