-
-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fe76557
commit 6ef8691
Showing
21 changed files
with
304 additions
and
298 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// SortingOptions.swift | ||
// Applite | ||
// | ||
// Created by Milán Várady on 2025.01.12. | ||
// | ||
|
||
import SwiftUI | ||
|
||
enum SortingOptions: String, CaseIterable, Identifiable { | ||
case mostDownloaded | ||
case bestMatch | ||
case aToZ | ||
|
||
var id: SortingOptions { self } | ||
|
||
var description: LocalizedStringKey { | ||
switch self { | ||
case .mostDownloaded: return "Most downloaded (default)" | ||
case .bestMatch: return "Best match" | ||
case .aToZ: return "A to Z" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
Applite/Views/Content View/ContentView+SearchFunctions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// ContentView+SearchFunctions.swift | ||
// Applite | ||
// | ||
// Created by Milán Várady on 2025.01.12. | ||
// | ||
|
||
import SwiftUI | ||
|
||
extension ContentView { | ||
func searchAndSort() async { | ||
await caskManager.allCasks.search(query: searchInput, diffScroreThreshold: 0.3, limitResults: 25) | ||
if hideUnpopularApps { await filterUnpopular() } | ||
await sortCasks(ignoreBestMatch: true) | ||
} | ||
|
||
func filterUnpopular(threshold: Int = 500) async { | ||
caskManager.allCasks.filterSearch { casks in | ||
casks.filter { $0.downloadsIn365days > threshold } | ||
} | ||
} | ||
|
||
func sortCasks(ignoreBestMatch: Bool) async { | ||
switch sortBy { | ||
case .bestMatch: | ||
if !ignoreBestMatch { | ||
await caskManager.allCasks.search(query: searchInput) | ||
} | ||
case .aToZ: | ||
caskManager.allCasks.filterSearch { casks in | ||
casks.sorted { $0.info.name < $1.info.name } | ||
} | ||
case .mostDownloaded: | ||
caskManager.allCasks.filterSearch { casks in | ||
casks.sorted { $0.downloadsIn365days > $1.downloadsIn365days } | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.