-
Notifications
You must be signed in to change notification settings - Fork 4
Add support for latest in query string
#16
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -229,14 +229,44 @@ pub fn update_route(model: Model, route: uri.Uri) { | |||||
| case string.is_empty(q) { | ||||||
| True -> #(set_search_results(model, #(-1, [])), effect.none()) | ||||||
| False -> { | ||||||
| let latest = list.filter(packages, fn(p) { p.1 == "latest" }) | ||||||
| Model(..model, search_input: q, search_packages_filters: packages) | ||||||
| |> pair.new(effects.typesense_search(q, packages)) | ||||||
| |> pair.new({ | ||||||
| case latest { | ||||||
| [] -> effects.typesense_search(q, packages) | ||||||
| latest -> { | ||||||
| latest | ||||||
| |> list.map(pair.first) | ||||||
| |> effects.initial_latest_packages | ||||||
| } | ||||||
| } | ||||||
| }) | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| pub fn replace_search_packages(model: Model) { | ||||||
| let model = | ||||||
| Model(..model, search_packages_filters: { | ||||||
| use #(package, version) <- list.map(model.search_packages_filters) | ||||||
| use <- bool.guard(when: version != "latest", return: #(package, version)) | ||||||
| case dict.get(model.packages_versions, package) { | ||||||
| Error(_) -> #(package, version) | ||||||
| Ok(versions) -> { | ||||||
| case versions.releases { | ||||||
| [] -> #(package, version) | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps we should mark it as "not found" or something? Otherwise the version will be "latest" forever, which means the search never runs.
Suggested change
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I think this branch is not possible. All packages will have at least one version... but I posted a comment above to add packages with zero versions, so we can mark them as "not found" (or alternatively as "0.0.0"). Otherwise the search never runs if one package fails. |
||||||
| [release, ..] -> #(package, release.version) | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| }) | ||||||
| route.Search(q: model.search_input, packages: model.search_packages_filters) | ||||||
| |> route.replace | ||||||
| |> pair.new(model, _) | ||||||
| } | ||||||
|
|
||||||
| pub fn select_autocomplete_option(model: Model, package: String) { | ||||||
| case model.autocomplete, model.route { | ||||||
| None, _ -> model | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to mark that this package has no version in the error case. So we can go and mark it as not found later on. See comment below.