Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: SearchView #680

Merged
merged 12 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions Mail/Views/Search/SearchContactsSectionView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
Infomaniak Mail - iOS App
Copyright (C) 2022 Infomaniak Network SA

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import MailCore
import MailResources
import SwiftUI

struct SearchContactsSectionView: View {
@AppStorage(UserDefaults.shared.key(.threadDensity)) private var threadDensity = DefaultPreferences.threadDensity

let viewModel: SearchViewModel

var body: some View {
Section {
ForEach(viewModel.contacts) { contact in
RecipientAutocompletionCell(recipient: contact)
.onTapGesture {
viewModel.matomo.track(eventWithCategory: .search, name: "selectContact")
Constants.globallyResignFirstResponder()
viewModel.searchThreadsForContact(contact)
}
}
.padding(.horizontal, 4)
.padding(.vertical, threadDensity.cellVerticalPadding)
} header: {
if !viewModel.contacts.isEmpty {
Text(MailResourcesStrings.Localizable.contactsSearch)
.textStyle(.bodySmallSecondary)
}
}
.listRowInsets(.init(top: 0, leading: 12, bottom: 0, trailing: 12))
.listRowSeparator(.hidden)
.listRowBackground(MailResourcesAsset.backgroundColor.swiftUIColor)
}
}
2 changes: 1 addition & 1 deletion Mail/Views/Search/SearchFilterFolderCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ struct SearchFilterFolderCell: View {
HStack {
allFoldersItem.icon
Text(allFoldersItem.name)
.tag(allFoldersItem.id)
}
.tag(allFoldersItem.id)

ForEach(sortedFolders) { folder in
HStack {
Expand Down
75 changes: 75 additions & 0 deletions Mail/Views/Search/SearchHistorySectionView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
Infomaniak Mail - iOS App
Copyright (C) 2022 Infomaniak Network SA

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import MailCore
import MailResources
import SwiftUI

struct SearchHistorySectionView: View {
let viewModel: SearchViewModel

var body: some View {
Section {
ForEach(viewModel.searchHistory.history, id: \.self) { searchItem in
HStack(spacing: 8) {
Text(searchItem)
.frame(maxWidth: .infinity, alignment: .leading)
Button {
deleteSearchTapped(searchItem: searchItem)
} label: {
MailResourcesAsset.close.swiftUIImage
.resizable()
.scaledToFit()
.foregroundColor(.accentColor)
.frame(width: 17, height: 17)
}
.buttonStyle(BorderlessButtonStyle())
}
.contentShape(Rectangle())
.onTapGesture {
viewModel.matomo.track(eventWithCategory: .search, name: "fromHistory")
Constants.globallyResignFirstResponder()
viewModel.searchValue = searchItem
Task {
await viewModel.fetchThreads()
}
}
}
.padding(.horizontal, 4)
} header: {
Text(MailResourcesStrings.Localizable.recentSearchesTitle)
.textStyle(.bodySmallSecondary)
}
.listRowSeparator(.hidden)
.listRowBackground(MailResourcesAsset.backgroundColor.swiftUIColor)
.listRowInsets(.init(top: 0, leading: 12, bottom: 0, trailing: 12))
}

@MainActor
private func deleteSearchTapped(searchItem: String) {
viewModel.matomo.track(eventWithCategory: .search, name: "deleteFromHistory")
Task {
await tryOrDisplayError {
viewModel.searchHistory = await viewModel.mailboxManager.delete(
searchHistory: viewModel.searchHistory,
with: searchItem
)
}
}
}
}
38 changes: 38 additions & 0 deletions Mail/Views/Search/SearchNoHistoryView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
Infomaniak Mail - iOS App
Copyright (C) 2022 Infomaniak Network SA

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import MailResources
import SwiftUI

struct SearchNoHistoryView: View {
var body: some View {
Text(MailResourcesStrings.Localizable.emptyStateHistoryDescription)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top)
.padding(.top, 16)
.textStyle(.bodySmallSecondary)
.listRowSeparator(.hidden)
.listRowBackground(MailResourcesAsset.backgroundColor.swiftUIColor)
.listRowInsets(.init(top: 0, leading: 12, bottom: 0, trailing: 12))
}
}

struct SearchNoHistoryView_Previews: PreviewProvider {
static var previews: some View {
SearchNoHistoryView()
}
}
88 changes: 88 additions & 0 deletions Mail/Views/Search/SearchThreadsSectionView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
Infomaniak Mail - iOS App
Copyright (C) 2022 Infomaniak Network SA

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import MailCore
import MailResources
import SwiftUI

struct SearchThreadsSectionView: View {
@AppStorage(UserDefaults.shared.key(.threadDensity)) private var threadDensity = DefaultPreferences.threadDensity

let viewModel: SearchViewModel
@Binding var editedMessageDraft: Draft?

var body: some View {
Section {
ForEach(viewModel.threads) { thread in
Group {
if thread.shouldPresentAsDraft {
Button(action: {
DraftUtils.editDraft(
from: thread,
mailboxManager: viewModel.mailboxManager,
editedMessageDraft: $editedMessageDraft
)
}, label: {
ThreadCell(thread: thread,
mailboxManager: viewModel.mailboxManager,
density: threadDensity)
})
} else {
ZStack {
NavigationLink(destination: {
ThreadView(
mailboxManager: viewModel.mailboxManager,
thread: thread
)
.onAppear {
viewModel.selectedThread = thread
}
}, label: {
EmptyView()
})
.opacity(0)

ThreadCell(thread: thread,
mailboxManager: viewModel.mailboxManager,
density: threadDensity)
}
}
}
.listRowInsets(EdgeInsets())
.padding(.leading, -4)
.onAppear {
viewModel.loadNextPageIfNeeded(currentItem: thread)
}
}
} header: {
if threadDensity != .compact && !viewModel.threads.isEmpty {
Text(MailResourcesStrings.Localizable.searchAllMessages)
.textStyle(.bodySmallSecondary)
}
} footer: {
if viewModel.isLoading {
ProgressView()
.frame(maxWidth: .infinity)
.id(UUID())
}
}
.listRowInsets(.init(top: 0, leading: 12, bottom: 0, trailing: 12))
.listRowSeparator(.hidden)
.listRowBackground(MailResourcesAsset.backgroundColor.swiftUIColor)
}
}
Loading