Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Sjmarf committed Oct 6, 2023
1 parent 343ef1c commit 45bac5f
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 7 deletions.
16 changes: 12 additions & 4 deletions Mlem.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,9 @@
CD18DC6F2A5209C3002C56BC /* MarkPrivateMessageAsReadRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD18DC6E2A5209C3002C56BC /* MarkPrivateMessageAsReadRequest.swift */; };
CD18DC732A522A7C002C56BC /* CreatePrivateMessageRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD18DC722A522A7C002C56BC /* CreatePrivateMessageRequest.swift */; };
CD2053102AC878B50000AA38 /* UpdatedTimestampView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD20530F2AC878B50000AA38 /* UpdatedTimestampView.swift */; };
CD2053122ACB72190000AA38 /* AccountTransitionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD2053112ACB72190000AA38 /* AccountTransitionView.swift */; };
CD2053142ACBAF150000AA38 /* AvatarType.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD2053132ACBAF150000AA38 /* AvatarType.swift */; };
CD2053172ACBBB5A0000AA38 /* DefaultAvatarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD2053162ACBBB5A0000AA38 /* DefaultAvatarView.swift */; };
CD2053122ACB72190000AA38 /* AccountTransitionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD2053112ACB72190000AA38 /* AccountTransitionView.swift */; };
CD2BD6782A79F55800ECFF89 /* ImageSize.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD2BD6772A79F55800ECFF89 /* ImageSize.swift */; };
CD2E182B2A3B708500224F8A /* Settings Options.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD2E182A2A3B708500224F8A /* Settings Options.swift */; };
CD309C462A93FBD300988F95 /* Logo View.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD309C452A93FBD300988F95 /* Logo View.swift */; };
Expand Down Expand Up @@ -808,9 +808,9 @@
CD18DC6E2A5209C3002C56BC /* MarkPrivateMessageAsReadRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarkPrivateMessageAsReadRequest.swift; sourceTree = "<group>"; };
CD18DC722A522A7C002C56BC /* CreatePrivateMessageRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreatePrivateMessageRequest.swift; sourceTree = "<group>"; };
CD20530F2AC878B50000AA38 /* UpdatedTimestampView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpdatedTimestampView.swift; sourceTree = "<group>"; };
CD2053112ACB72190000AA38 /* AccountTransitionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountTransitionView.swift; sourceTree = "<group>"; };
CD2053132ACBAF150000AA38 /* AvatarType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AvatarType.swift; sourceTree = "<group>"; };
CD2053162ACBBB5A0000AA38 /* DefaultAvatarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultAvatarView.swift; sourceTree = "<group>"; };
CD2053112ACB72190000AA38 /* AccountTransitionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountTransitionView.swift; sourceTree = "<group>"; };
CD2BD6772A79F55800ECFF89 /* ImageSize.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageSize.swift; sourceTree = "<group>"; };
CD2E182A2A3B708500224F8A /* Settings Options.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Settings Options.swift"; sourceTree = "<group>"; };
CD309C452A93FBD300988F95 /* Logo View.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Logo View.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1082,6 +1082,15 @@
path = User;
sourceTree = "<group>";
};
030D00832AD0842900953B1D /* Results */ = {
isa = PBXGroup;
children = (
03EEEAF22AB8DCDF0087F8D8 /* CommunityResultView.swift */,
03B7AAF42ABEFA7A00068B23 /* UserResultView.swift */,
);
path = Results;
sourceTree = "<group>";
};
030E86422AC6F6CB000283A6 /* Search Bar */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1941,8 +1950,7 @@
03EC92942AC064AE007BBE7E /* SearchHomeView.swift */,
036ED3BB2ABF1058009664BC /* SearchModel.swift */,
03EEEAF62AB8ED3C0087F8D8 /* SearchTabPicker.swift */,
03EEEAF22AB8DCDF0087F8D8 /* CommunityResultView.swift */,
03B7AAF42ABEFA7A00068B23 /* UserResultView.swift */,
030D00832AD0842900953B1D /* Results */,
);
path = Search;
sourceTree = "<group>";
Expand Down
7 changes: 7 additions & 0 deletions Mlem/Models/Trackers/RecentSearchesTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ class RecentSearchesTracker: ObservableObject {
saveRecentSearches(accountId: accountId)
}

func removeRecentSearch(_ item: AnyContentModel, accountId: String?) {
if let index = recentSearches.firstIndex(of: item) {
recentSearches.remove(at: index)
}
saveRecentSearches(accountId: accountId)
}

func clearRecentSearches(accountId: String?) {
recentSearches.removeAll()
saveRecentSearches(accountId: accountId)
Expand Down
17 changes: 16 additions & 1 deletion Mlem/Views/Tabs/Search/RecentSearchesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ struct RecentSearchesView: View {
@EnvironmentObject var recentSearchesTracker: RecentSearchesTracker
@StateObject var contentTracker: ContentTracker<AnyContentModel> = .init()

func deleteSwipeAction(_ item: AnyContentModel) -> SwipeAction {
return SwipeAction(
symbol: .init(emptyName: Icons.close, fillName: Icons.close),
color: .red,
action: {
recentSearchesTracker.removeRecentSearch(item, accountId: appState.currentActiveAccount?.stableIdString)
}
)
}

var body: some View {
Group {
if !recentSearchesTracker.recentSearches.isEmpty {
Expand Down Expand Up @@ -62,11 +72,16 @@ struct RecentSearchesView: View {
ForEach(contentTracker.items, id: \.uid) { contentModel in
Group {
if let community = contentModel.wrappedValue as? CommunityModel {
CommunityResultView(community: community, showTypeLabel: true)
CommunityResultView(
community: community,
showTypeLabel: true,
hasSwipeActions: false
)
} else if let user = contentModel.wrappedValue as? UserModel {
UserResultView(user: user, showTypeLabel: true)
}
}
.addSwipeyActions(trailing: [deleteSwipeAction(contentModel)])
.simultaneousGesture(TapGesture().onEnded {
recentSearchesTracker.addRecentSearch(contentModel, accountId: appState.currentActiveAccount?.stableIdString)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ struct CommunityResultView: View {
let community: CommunityModel
let showTypeLabel: Bool

var hasSwipeActions: Bool = true

var subscribeSwipeAction: SwipeAction {
let (emptySymbolName, fullSymbolName) = community.subscribed
? (Icons.unsubscribePerson, Icons.unsubscribePersonFill)
Expand Down Expand Up @@ -50,6 +52,14 @@ 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 @@ -82,7 +92,6 @@ struct CommunityResultView: View {
.buttonStyle(.plain)
.padding(.vertical, 8)
.background(.background)
.addSwipeyActions(trailing: [subscribeSwipeAction])
.draggable(community.community.actorId) {
HStack {
AvatarView(community: community.community, avatarSize: 24)
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion Mlem/Views/Tabs/Search/SearchTabPicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct SearchTabPicker: View {
}
}
)
.animation(.spring(response: 0.15, dampingFraction: 0.825), value: selected)
.animation(.spring(response: 0.15, dampingFraction: 0.7), value: selected)
}
.buttonStyle(EmptyButtonStyle())
}
Expand Down

0 comments on commit 45bac5f

Please sign in to comment.