-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Guillaume Hivert <[email protected]>
- Loading branch information
Showing
10 changed files
with
2,965 additions
and
6,830 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
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 |
---|---|---|
@@ -1,3 +1,13 @@ | ||
export function is_dev() { | ||
return import.meta.env.DEV | ||
} | ||
|
||
export function scrollTo(id) { | ||
const elem = document.getElementById(id) | ||
if (!elem) return | ||
const elemRect = elem.getBoundingClientRect() | ||
const navbarRect = document.getElementsByClassName('navbar')?.[0]?.getBoundingClientRect() | ||
const bodyRect = document.body.getBoundingClientRect() | ||
const offset = elemRect.top - bodyRect.top - (navbarRect?.height ?? 0) - 12 | ||
window.scrollTo({ top: offset, behavior: 'smooth' }) | ||
} |
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 |
---|---|---|
@@ -1,21 +1,57 @@ | ||
import data/decoders/search_result.{type SearchResults} | ||
import data/decoders/search_result.{type SearchResult, type SearchResults} | ||
import data/model/mock | ||
import gleam/io | ||
import gleam/list | ||
import gleam/pair | ||
import gleam/result | ||
|
||
pub type Index = | ||
List(#(#(String, String), List(#(String, String)))) | ||
|
||
pub type Model { | ||
Model(input: String, search_results: SearchResults) | ||
Model(input: String, search_results: SearchResults, index: Index) | ||
} | ||
|
||
pub fn init() { | ||
Model(input: "", search_results: search_result.Start) | ||
let search_results = | ||
mock.mock() | ||
|> result.unwrap(search_result.Start) | ||
let index = compute_index(search_results) | ||
Model(input: "", search_results: search_results, index: index) | ||
} | ||
|
||
pub fn update_input(model: Model, content: String) { | ||
Model(..model, input: content) | ||
} | ||
|
||
pub fn update_search_results(model: Model, search_results: SearchResults) { | ||
Model(..model, search_results: search_results) | ||
let index = compute_index(search_results) | ||
Model(..model, search_results: search_results, index: index) | ||
} | ||
|
||
pub fn reset(_model: Model) { | ||
Model(search_results: search_result.Start, input: "") | ||
Model(search_results: search_result.Start, input: "", index: []) | ||
} | ||
|
||
fn compute_index(search_results: SearchResults) -> Index { | ||
case search_results { | ||
search_result.Start -> [] | ||
search_result.NoSearchResults -> [] | ||
search_result.SearchResults(exact, others) -> { | ||
[] | ||
|> insert_module_names(exact) | ||
|> insert_module_names(others) | ||
|> list.map(fn(i) { pair.map_second(i, list.reverse) }) | ||
} | ||
} | ||
} | ||
|
||
fn insert_module_names(index: Index, search_results: List(SearchResult)) { | ||
use acc, val <- list.fold(search_results, index) | ||
let key = #(val.package_name, val.version) | ||
list.key_find(acc, key) | ||
|> result.unwrap([]) | ||
|> fn(i) { list.prepend(i, #(val.module_name, val.name)) } | ||
|> io.debug() | ||
|> fn(i) { list.key_set(acc, key, i) } | ||
} |
Oops, something went wrong.