mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2025-04-27 02:14:45 +00:00
Make boost swipe buttons consistent with ones from inline & context menu (#999)
* Show different label and icon for boosting my followers-only post * Disable boost swipe actions on posts that can't be boosted * Remove unnecessary function calls
This commit is contained in:
parent
76b8de1dad
commit
40386d6312
2 changed files with 22 additions and 8 deletions
|
@ -7,7 +7,7 @@ public enum StatusAction: String, CaseIterable, Identifiable {
|
||||||
|
|
||||||
case none, reply, boost, favorite, bookmark, quote
|
case none, reply, boost, favorite, bookmark, quote
|
||||||
|
|
||||||
public func displayName(isReblogged: Bool = false, isFavorited: Bool = false, isBookmarked: Bool = false) -> LocalizedStringKey {
|
public func displayName(isReblogged: Bool = false, isFavorited: Bool = false, isBookmarked: Bool = false, privateBoost: Bool = false) -> LocalizedStringKey {
|
||||||
switch self {
|
switch self {
|
||||||
case .none:
|
case .none:
|
||||||
return "settings.swipeactions.status.action.none"
|
return "settings.swipeactions.status.action.none"
|
||||||
|
@ -16,6 +16,10 @@ public enum StatusAction: String, CaseIterable, Identifiable {
|
||||||
case .quote:
|
case .quote:
|
||||||
return "settings.swipeactions.status.action.quote"
|
return "settings.swipeactions.status.action.quote"
|
||||||
case .boost:
|
case .boost:
|
||||||
|
if privateBoost {
|
||||||
|
return isReblogged ? "status.action.unboost" : "status.action.boost-to-followers"
|
||||||
|
}
|
||||||
|
|
||||||
return isReblogged ? "status.action.unboost" : "settings.swipeactions.status.action.boost"
|
return isReblogged ? "status.action.unboost" : "settings.swipeactions.status.action.boost"
|
||||||
case .favorite:
|
case .favorite:
|
||||||
return isFavorited ? "status.action.unfavorite" : "settings.swipeactions.status.action.favorite"
|
return isFavorited ? "status.action.unfavorite" : "settings.swipeactions.status.action.favorite"
|
||||||
|
@ -24,7 +28,7 @@ public enum StatusAction: String, CaseIterable, Identifiable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func iconName(isReblogged: Bool = false, isFavorited: Bool = false, isBookmarked: Bool = false) -> String {
|
public func iconName(isReblogged: Bool = false, isFavorited: Bool = false, isBookmarked: Bool = false, privateBoost: Bool = false) -> String {
|
||||||
switch self {
|
switch self {
|
||||||
case .none:
|
case .none:
|
||||||
return "slash.circle"
|
return "slash.circle"
|
||||||
|
@ -33,6 +37,10 @@ public enum StatusAction: String, CaseIterable, Identifiable {
|
||||||
case .quote:
|
case .quote:
|
||||||
return "quote.bubble"
|
return "quote.bubble"
|
||||||
case .boost:
|
case .boost:
|
||||||
|
if privateBoost {
|
||||||
|
return isReblogged ? "arrow.left.arrow.right.circle.fill" : "lock.rotation"
|
||||||
|
}
|
||||||
|
|
||||||
return isReblogged ? "arrow.left.arrow.right.circle.fill" : "arrow.left.arrow.right.circle"
|
return isReblogged ? "arrow.left.arrow.right.circle.fill" : "arrow.left.arrow.right.circle"
|
||||||
case .favorite:
|
case .favorite:
|
||||||
return isFavorited ? "star.fill" : "star"
|
return isFavorited ? "star.fill" : "star"
|
||||||
|
|
|
@ -6,10 +6,15 @@ import SwiftUI
|
||||||
struct StatusRowSwipeView: View {
|
struct StatusRowSwipeView: View {
|
||||||
@EnvironmentObject private var theme: Theme
|
@EnvironmentObject private var theme: Theme
|
||||||
@EnvironmentObject private var preferences: UserPreferences
|
@EnvironmentObject private var preferences: UserPreferences
|
||||||
|
@EnvironmentObject private var currentAccount: CurrentAccount
|
||||||
|
|
||||||
enum Mode {
|
enum Mode {
|
||||||
case leading, trailing
|
case leading, trailing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func privateBoost() -> Bool {
|
||||||
|
return viewModel.status.visibility == .priv && viewModel.status.account.id == currentAccount.account?.id
|
||||||
|
}
|
||||||
|
|
||||||
let viewModel: StatusRowViewModel
|
let viewModel: StatusRowViewModel
|
||||||
let mode: Mode
|
let mode: Mode
|
||||||
|
@ -63,13 +68,14 @@ struct StatusRowSwipeView: View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case .boost:
|
case .boost:
|
||||||
makeSwipeButtonForTask(action: action) {
|
makeSwipeButtonForTask(action: action, privateBoost: privateBoost()) {
|
||||||
if viewModel.isReblogged {
|
if viewModel.isReblogged {
|
||||||
await viewModel.unReblog()
|
await viewModel.unReblog()
|
||||||
} else {
|
} else {
|
||||||
await viewModel.reblog()
|
await viewModel.reblog()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.disabled(viewModel.status.visibility == .direct || viewModel.status.visibility == .priv && viewModel.status.account.id != currentAccount.account?.id)
|
||||||
case .bookmark:
|
case .bookmark:
|
||||||
makeSwipeButtonForTask(action: action) {
|
makeSwipeButtonForTask(action: action) {
|
||||||
if viewModel.isBookmarked {
|
if viewModel.isBookmarked {
|
||||||
|
@ -95,26 +101,26 @@ struct StatusRowSwipeView: View {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
private func makeSwipeButtonForTask(action: StatusAction, task: @escaping () async -> Void) -> some View {
|
private func makeSwipeButtonForTask(action: StatusAction, privateBoost: Bool = false, task: @escaping () async -> Void) -> some View {
|
||||||
Button {
|
Button {
|
||||||
Task {
|
Task {
|
||||||
HapticManager.shared.fireHaptic(of: .notification(.success))
|
HapticManager.shared.fireHaptic(of: .notification(.success))
|
||||||
await task()
|
await task()
|
||||||
}
|
}
|
||||||
} label: {
|
} label: {
|
||||||
makeSwipeLabel(action: action, style: preferences.swipeActionsIconStyle)
|
makeSwipeLabel(action: action, style: preferences.swipeActionsIconStyle, privateBoost: privateBoost)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
private func makeSwipeLabel(action: StatusAction, style: UserPreferences.SwipeActionsIconStyle) -> some View {
|
private func makeSwipeLabel(action: StatusAction, style: UserPreferences.SwipeActionsIconStyle, privateBoost: Bool = false) -> some View {
|
||||||
switch style {
|
switch style {
|
||||||
case .iconOnly:
|
case .iconOnly:
|
||||||
Label(action.displayName(isReblogged: viewModel.isReblogged, isFavorited: viewModel.isFavorited, isBookmarked: viewModel.isBookmarked), systemImage: action.iconName(isReblogged: viewModel.isReblogged, isFavorited: viewModel.isFavorited, isBookmarked: viewModel.isBookmarked))
|
Label(action.displayName(isReblogged: viewModel.isReblogged, isFavorited: viewModel.isFavorited, isBookmarked: viewModel.isBookmarked, privateBoost: privateBoost), systemImage: action.iconName(isReblogged: viewModel.isReblogged, isFavorited: viewModel.isFavorited, isBookmarked: viewModel.isBookmarked, privateBoost: privateBoost))
|
||||||
.labelStyle(.iconOnly)
|
.labelStyle(.iconOnly)
|
||||||
.environment(\.symbolVariants, .none)
|
.environment(\.symbolVariants, .none)
|
||||||
case .iconWithText:
|
case .iconWithText:
|
||||||
Label(action.displayName(isReblogged: viewModel.isReblogged, isFavorited: viewModel.isFavorited, isBookmarked: viewModel.isBookmarked), systemImage: action.iconName(isReblogged: viewModel.isReblogged, isFavorited: viewModel.isFavorited, isBookmarked: viewModel.isBookmarked))
|
Label(action.displayName(isReblogged: viewModel.isReblogged, isFavorited: viewModel.isFavorited, isBookmarked: viewModel.isBookmarked, privateBoost: privateBoost), systemImage: action.iconName(isReblogged: viewModel.isReblogged, isFavorited: viewModel.isFavorited, isBookmarked: viewModel.isBookmarked, privateBoost: privateBoost))
|
||||||
.labelStyle(.titleAndIcon)
|
.labelStyle(.titleAndIcon)
|
||||||
.environment(\.symbolVariants, .none)
|
.environment(\.symbolVariants, .none)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue