Skip to content

Commit

Permalink
Implement requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sjmarf committed Oct 8, 2023
1 parent 45bac5f commit 10c6147
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
7 changes: 7 additions & 0 deletions Mlem/Extensions/Swipey Actions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -363,4 +363,11 @@ extension View {
)
)
}

@ViewBuilder
func addSwipeyActions(_ configuration: SwipeConfiguration) -> some View {
modifier(
SwipeyView(configuration: configuration)
)
}
}
9 changes: 6 additions & 3 deletions Mlem/Views/Tabs/Search/RecentSearchesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,16 @@ struct RecentSearchesView: View {
CommunityResultView(
community: community,
showTypeLabel: true,
hasSwipeActions: false
swipeActions: .init(trailingActions: [deleteSwipeAction(contentModel)])
)
} else if let user = contentModel.wrappedValue as? UserModel {
UserResultView(user: user, showTypeLabel: true)
UserResultView(
user: user,
showTypeLabel: true,
swipeActions: .init(trailingActions: [deleteSwipeAction(contentModel)])
)
}
}
.addSwipeyActions(trailing: [deleteSwipeAction(contentModel)])
.simultaneousGesture(TapGesture().onEnded {
recentSearchesTracker.addRecentSearch(contentModel, accountId: appState.currentActiveAccount?.stableIdString)
})
Expand Down
21 changes: 12 additions & 9 deletions Mlem/Views/Tabs/Search/Results/CommunityResultView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,20 @@ struct CommunityResultView: View {
@Dependency(\.hapticManager) var hapticManager

@EnvironmentObject var contentTracker: ContentTracker<AnyContentModel>

let community: CommunityModel
let showTypeLabel: Bool
var swipeActions: SwipeConfiguration = .init()

var hasSwipeActions: Bool = true
init(
community: CommunityModel,
showTypeLabel: Bool = false,
swipeActions: SwipeConfiguration? = nil
) {
self.community = community
self.showTypeLabel = showTypeLabel
self.swipeActions = swipeActions ?? .init(trailingActions: [subscribeSwipeAction])
}

var subscribeSwipeAction: SwipeAction {
let (emptySymbolName, fullSymbolName) = community.subscribed
Expand Down Expand Up @@ -52,14 +62,6 @@ struct CommunityResultView: View {
}

var body: some View {
if hasSwipeActions {
content
.addSwipeyActions(trailing: [subscribeSwipeAction])
} else {
content
}
}
var content: some View {
NavigationLink(value: NavigationRoute.apiCommunity(community.community)) {
HStack(spacing: 10) {
AvatarView(community: community.community, avatarSize: 48)
Expand Down Expand Up @@ -110,5 +112,6 @@ struct CommunityResultView: View {
systemImage: community.subscribed ? Icons.unsubscribe : Icons.subscribe)
}
}
.addSwipeyActions(swipeActions)
}
}
3 changes: 3 additions & 0 deletions Mlem/Views/Tabs/Search/Results/UserResultView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ struct UserResultView: View {
@Dependency(\.hapticManager) var hapticManager

@EnvironmentObject var contentTracker: ContentTracker<AnyContentModel>

let user: UserModel
let showTypeLabel: Bool
var swipeActions: SwipeConfiguration = .init()

var caption: String {
if let host = user.user.actorId.host {
Expand Down Expand Up @@ -87,5 +89,6 @@ struct UserResultView: View {
.background(.background)
.clipShape(RoundedRectangle(cornerRadius: 8))
}
.addSwipeyActions(swipeActions)
}
}

0 comments on commit 10c6147

Please sign in to comment.