Skip to content

Commit

Permalink
fix: use correct handling for SubmitSearch
Browse files Browse the repository at this point in the history
  • Loading branch information
ghivert committed Jun 20, 2024
1 parent 1e8d3f3 commit 14171ca
Show file tree
Hide file tree
Showing 9 changed files with 3,133 additions and 1,702 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ Thumbs.db

*.logs
dist/
.yarn/
1 change: 1 addition & 0 deletions apps/frontend/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
2 changes: 1 addition & 1 deletion apps/frontend/gleam.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ gleam_javascript = "~> 0.8"
gleam_json = ">= 1.0.1 and < 2.0.0"
gleam_stdlib = "~> 0.34 or ~> 1.0"
grille_pain = ">= 1.0.0 and < 2.0.0"
lustre = ">= 4.2.0 and < 5.0.0"
lustre_http = "~> 0.5"
modem = ">= 1.1.0 and < 2.0.0"
plinth = ">= 0.2.0 and < 1.0.0"
sketch = ">= 2.2.2 and < 3.0.0"
tardis = ">= 0.1.0 and < 1.0.0"
lustre = ">= 4.3.0 and < 5.0.0"

[dev-dependencies]
gleeunit = "~> 1.0"
4 changes: 2 additions & 2 deletions apps/frontend/manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ packages = [
{ name = "gleam_stdlib", version = "0.37.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "5398BD6C2ABA17338F676F42F404B9B7BABE1C8DC7380031ACB05BBE1BCF3742" },
{ name = "gleeunit", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "72CDC3D3F719478F26C4E2C5FED3E657AC81EC14A47D2D2DEBB8693CA3220C3B" },
{ name = "grille_pain", version = "1.0.1", build_tools = ["gleam"], requirements = ["birl", "gleam_stdlib", "lustre", "plinth", "sketch", "tardis"], otp_app = "grille_pain", source = "hex", outer_checksum = "F0CA9AA0BD4D03B8E190AB4CBB9429DE9389BC2152CF566C3410261F5729827C" },
{ name = "lustre", version = "4.2.4", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_json", "gleam_otp", "gleam_stdlib"], otp_app = "lustre", source = "hex", outer_checksum = "09B94E1380CBC400DCD594B36A845E5CB2E143DF89E95460B2CA59E44499CAC9" },
{ name = "lustre", version = "4.3.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_json", "gleam_otp", "gleam_stdlib"], otp_app = "lustre", source = "hex", outer_checksum = "43642C0602D3E2D6FEC3E24173D68A1F8E646969B53A2B0A5EB61238DDA739C4" },
{ name = "lustre_http", version = "0.5.2", build_tools = ["gleam"], requirements = ["gleam_fetch", "gleam_http", "gleam_javascript", "gleam_json", "gleam_stdlib", "lustre"], otp_app = "lustre_http", source = "hex", outer_checksum = "FB0478CBFA6B16DBE8ECA326DAE2EC15645E04900595EF2C4F039ABFA0512ABA" },
{ name = "modem", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "lustre"], otp_app = "modem", source = "hex", outer_checksum = "4C6E448089B09A57C179455D44526A717E4E217D4000B91201617FD2D9F18E68" },
{ name = "plinth", version = "0.2.0", build_tools = ["gleam"], requirements = ["gleam_javascript", "gleam_json", "gleam_stdlib"], otp_app = "plinth", source = "hex", outer_checksum = "83211E672D83F3CE14681D0ECD3AD883EE7588E423E7C9DDDB460014AD60AC24" },
Expand All @@ -28,7 +28,7 @@ gleam_json = { version = ">= 1.0.1 and < 2.0.0" }
gleam_stdlib = { version = "~> 0.34 or ~> 1.0" }
gleeunit = { version = "~> 1.0" }
grille_pain = { version = ">= 1.0.0 and < 2.0.0" }
lustre = { version = ">= 4.2.0 and < 5.0.0" }
lustre = { version = ">= 4.3.0 and < 5.0.0"}
lustre_http = { version = "~> 0.5" }
modem = { version = ">= 1.1.0 and < 2.0.0" }
plinth = { version = ">= 0.2.0 and < 1.0.0" }
Expand Down
3 changes: 2 additions & 1 deletion apps/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@
"typescript": "^5.4.2",
"vite": "^5.1.6",
"vite-gleam": "^0.4.0"
}
},
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
19 changes: 18 additions & 1 deletion apps/frontend/src/frontend.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import data/package
import data/search_result
import frontend/router
import frontend/view
import frontend/view/body/cache
import gleam/bool
import gleam/dict
import gleam/dynamic
import gleam/io
import gleam/list
import gleam/option.{None}
import gleam/result
Expand Down Expand Up @@ -63,6 +65,8 @@ pub fn main() {
|> result.unwrap(app)
}

let assert Ok(_) = lustre.register(cache.component(), "cache-signatures")

let assert Ok(_) =
view.view
|> sketch.compose(cache)
Expand Down Expand Up @@ -138,7 +142,20 @@ fn submit_search(model: Model) {
use <- bool.guard(when: model.loading, return: #(model, effect.none()))
let new_model = model.update_submitted_input(model)
case dict.get(new_model.search_results, new_model.submitted_input) {
Ok(_) -> update.none(new_model)
Ok(_) ->
case new_model.route {
router.Search(old_input) if old_input == new_model.submitted_input ->
update.none(new_model)
_ ->
new_model
|> model.update_route(router.Search(new_model.submitted_input))
|> update.none()
|> update.add_effect({
uri.parse("/search?q=" <> new_model.submitted_input)
|> result.map(modem.push(_))
|> result.unwrap(effect.none())
})
}
Error(_) ->
http.expect_json(search_result.decode_search_results, {
msg.SearchResults(input: model.input, result: _)
Expand Down
31 changes: 19 additions & 12 deletions apps/frontend/src/frontend/view/body/body.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,24 @@ pub fn view_trending(model: Model) {
s.qualified_name([], [
item.repository
|> option.map(fn(r) {
h.a([a.href(r), a.target("_blank"), a.rel("noreferrer")], [
h.text("Code"),
])
})
h.a([a.href(r), a.target("_blank"), a.rel("noreferrer")], [
h.text("Code"),
])
})
|> option.unwrap(el.none()),
item.documentation
|> option.map(fn(d) {
h.a([a.href(d), a.target("_blank"), a.rel("noreferrer")], [
h.text("Docs"),
])
})
h.a([a.href(d), a.target("_blank"), a.rel("noreferrer")], [
h.text("Docs"),
])
})
|> option.unwrap(el.none()),
item.hex_url
|> option.map(fn(d) {
h.a([a.href(d), a.target("_blank"), a.rel("noreferrer")], [
h.text("Hex"),
])
})
h.a([a.href(d), a.target("_blank"), a.rel("noreferrer")], [
h.text("Hex"),
])
})
|> option.unwrap(el.none()),
]),
]),
Expand Down Expand Up @@ -159,6 +159,13 @@ pub fn body(model: Model) {
)
search_result.SearchResults(_, _, _, _, _) -> {
dict.get(model.view_cache, model.submitted_input)
|> result.map(fn(content) {
el.element(
"cache-signatures",
[a.property("content", content)],
[],
)
})
|> result.unwrap(el.none())
}
}
Expand Down
24 changes: 24 additions & 0 deletions apps/frontend/src/frontend/view/body/cache.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ import frontend/view/body/styles as s
import frontend/view/documentation
import frontend/view/types as t
import gleam/bool
import gleam/dict
import gleam/dynamic
import gleam/io
import gleam/list
import gleam/option
import lustre
import lustre/attribute as a
import lustre/effect as eff
import lustre/element as el
import lustre/element/html as h
import lustre/event as e
Expand Down Expand Up @@ -138,3 +143,22 @@ pub fn cache_search_results(
]),
])
}

pub type MsgComponent {
UpdateContent(el.Element(MsgComponent))
}

pub fn component() {
lustre.component(
fn(_flags) { #(el.none(), eff.none()) },
fn(_model, msg) {
case msg {
UpdateContent(c) -> #(c, eff.none())
}
},
fn(model) { model },
dict.from_list([
#("content", fn(dyn) { Ok(UpdateContent(dynamic.unsafe_coerce(dyn))) }),
]),
)
}
Loading

0 comments on commit 14171ca

Please sign in to comment.