Skip to content

Commit

Permalink
feat: add packages on sidebar
Browse files Browse the repository at this point in the history
Signed-off-by: Guillaume Hivert <[email protected]>
  • Loading branch information
ghivert committed May 13, 2024
1 parent ffe2fda commit c1dad97
Show file tree
Hide file tree
Showing 10 changed files with 2,965 additions and 6,830 deletions.
4 changes: 2 additions & 2 deletions apps/backend/src/backend/postgres/queries.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ pub fn content_search(db: pgo.Connection, query: String) {
OR replace(s.signature_, ' ', '') ILIKE '%' || replace($1, ' ', '') || '%'
)
ORDER BY s.name, s.kind, m.name, ordering DESC
LIMIT 20"
LIMIT 40"
|> pgo.execute(db, [query], decode_type_search)
|> result.map_error(error.DatabaseError)
|> result.map(fn(r) { r.rows })
Expand Down Expand Up @@ -523,7 +523,7 @@ pub fn search(db: pgo.Connection, q: String) {
JOIN package p
ON p.id = r.package_id
WHERE to_tsvector(s.signature_) @@ to_tsquery($1)
LIMIT 20"
LIMIT 40"
|> pgo.execute(db, [query], decode_type_search)
|> result.map_error(error.DatabaseError)
|> result.map(fn(r) { r.rows })
Expand Down
21 changes: 15 additions & 6 deletions apps/frontend/public/hljs-theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -101,27 +101,36 @@ hue-6-2: #e6c07b

.documentation {
line-height: 1.3;
font-size: 14px;
}

.documentation * {
margin-bottom: 9px;
margin-top: 9px;
}

.documentation p {
margin-top: 1rem;
margin-bottom: 1rem;
.documentation *:last-child {
margin-bottom: 0px;
}

.documentation *:first-child {
margin-top: 0px;
}

.documentation h1 {
font-size: 1.3rem;
font-size: 1.1rem;
font-weight: 600;
}

.documentation h2 {
font-size: 1.2rem;
font-size: 1rem;
font-weight: 500;
}

.documentation h3,
.documentation h4,
.documentation h5,
.documentation h6 {
font-size: 1.1rem;
font-size: 0.9rem;
font-weight: 500;
}
10 changes: 10 additions & 0 deletions apps/frontend/src/config.ffi.mjs
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' })
}
46 changes: 41 additions & 5 deletions apps/frontend/src/data/model.gleam
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) }
}
Loading

0 comments on commit c1dad97

Please sign in to comment.