Skip to content

Commit

Permalink
Add new sorting option on reading time
Browse files Browse the repository at this point in the history
  • Loading branch information
bourvill committed Aug 7, 2024
1 parent 66d2a84 commit 779901c
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 16 deletions.
18 changes: 16 additions & 2 deletions App/Features/Entry/EntriesListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,24 @@ struct EntriesListView: View {
@Environment(AppSync.self) var appSync: AppSync
@FetchRequest var entries: FetchedResults<Entry>

init(predicate: NSPredicate, entriesSortAscending: Bool) {
init(
predicate: NSPredicate,
entriesSortedById: Bool,
entriesSortedByReadingTime: Bool,
entriesSortedByAscending: Bool
) {
var sortDescriptors: [NSSortDescriptor] = []
if entriesSortedById {
sortDescriptors.append(NSSortDescriptor(key: "id", ascending: entriesSortedByAscending))
}

if entriesSortedByReadingTime {
sortDescriptors.append(NSSortDescriptor(key: "readingTime", ascending: entriesSortedByAscending))
}

_entries = FetchRequest(
entity: Entry.entity(),
sortDescriptors: [NSSortDescriptor(key: "id", ascending: entriesSortAscending)],
sortDescriptors: sortDescriptors,
predicate: predicate, animation: nil
)
}
Expand Down
34 changes: 22 additions & 12 deletions App/Features/Entry/EntriesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,37 @@ struct EntriesView: View {
@Environment(Router.self) var router: Router
@EnvironmentObject var appState: AppState
@StateObject var searchViewModel = SearchViewModel()
@State var entriesSortAscending = false
@State var entriesSortedById = true
@State var entriesSortedByReadingTime = false
@State var entriesSortedByAscending = false

var body: some View {
VStack {
#if os(iOS)
PasteBoardView()
#endif
SearchView(searchViewModel: searchViewModel)
EntriesListView(predicate: searchViewModel.predicate, entriesSortAscending: entriesSortAscending)
EntriesListView(
predicate: searchViewModel.predicate,
entriesSortedById: entriesSortedById,
entriesSortedByReadingTime: entriesSortedByReadingTime,
entriesSortedByAscending: entriesSortedByAscending
)
}
.onChange(of: entriesSortedByReadingTime) { _, _ in
entriesSortedById = false
}
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
HStack {
Button(action: {
entriesSortAscending.toggle()
}, label: {
Image(systemName: "line.3.horizontal.decrease.circle")
.rotationEffect(.degrees(entriesSortAscending ? 180 : 0))
})
RefreshButton()
}
ToolbarItemGroup(placement: .navigationBarTrailing) {
Menu(content: {
Toggle("Order by id", systemImage: "line.3.horizontal.decrease.circle", isOn: $entriesSortedById)
Toggle("Order by reading time", systemImage: "clock.arrow.circlepath", isOn: $entriesSortedByReadingTime)
Divider()
Toggle("Sorting", systemImage: entriesSortedByAscending ? "arrow.up.circle" : "arrow.down.circle", isOn: $entriesSortedByAscending)
}, label: {
Label("Sort options", systemImage: "line.3.horizontal.decrease.circle")
})
RefreshButton()
}
ToolbarItem(placement: .navigationBarLeading) {
Menu(content: {
Expand Down
4 changes: 4 additions & 0 deletions App/fr.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,7 @@
//Player
"Select one entry" = "Sélectionnez une entrée";
"Confirm delete?" = "Confirmer la suppression ?";

"Order by id" = "Trier par id";
"Order by reading time" = "Trier par temps de lecture";
"Sorting" = "Tri";
4 changes: 2 additions & 2 deletions wallabag.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1271,7 +1271,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
MARKETING_VERSION = 7.2.4;
MARKETING_VERSION = 7.3.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -1330,7 +1330,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
MARKETING_VERSION = 7.2.4;
MARKETING_VERSION = 7.3.0;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SWIFT_COMPILATION_MODE = wholemodule;
Expand Down

0 comments on commit 779901c

Please sign in to comment.