···11// IMPORTS ---------------------------------------------------------------------
2233import chilp
44-import chilp/widget
55-import chilp/widget/anchors
64import gleam/option
75import lustre
88-import lustre/effect.{type Effect}
96import lustre/element.{type Element}
107import lustre/element/html
118129// MAIN ------------------------------------------------------------------------
13101411pub fn main() {
1515- // In this example, we're not making much sense. Just showing off Chilp!
1616-1717- let assert Ok(_) = widget.register()
1818-1919- let app = lustre.application(init, update, view)
1212+ // In this example we're just showing off Chilp, so
1313+ // `lustre.simple()` does the trick!
1414+ let assert Ok(_) = chilp.register()
1515+ let app = lustre.simple(init, update, view)
2016 let assert Ok(_) = lustre.start(app, "#app", Nil)
2121-2217 Nil
2318}
2419···2823 Model(string: String, num: Int)
2924}
30253131-fn init(_) -> #(Model, Effect(Msg)) {
3232- let model = Model(string: "Hi", num: 4)
3333- // No effects, though you could force Chilp to pre-fetch a post with widget.force()!
3434- let effect = effect.none()
3535-3636- #(model, effect)
2626+fn init(_) -> Model {
2727+ Model(string: "Hi", num: 4)
3728}
38293930// UPDATE ----------------------------------------------------------------------
···4233 SetString(String)
4334}
44354545-// You can't usually make `ChilpMsg`s, with a few exceptions.
4646-//
4747-// One of them being `widget.trigger()`, which does what `widget.force()` does but instead of an effect it returns a `ChilpMsg`!
4848-fn update(model: Model, msg: Msg) -> #(Model, Effect(Msg)) {
3636+fn update(model: Model, msg: Msg) -> Model {
4937 case msg {
5050- SetString(string) -> #(Model(string: string, num: model.num), effect.none())
3838+ SetString(string) -> Model(string: string, num: model.num)
5139 }
5240}
5341···5644fn view(model: Model) -> Element(Msg) {
5745 html.div([], [
5846 element.text(model.string),
5959- // Let's render comments under https://pony.social/@strawmelonjuice/115911235653686237
4747+ // And right underneath that string, we put a comment widget!
6048 chilp.widget(
6161- // A post on a sharkey instance
6262- mastodon: option.Some(anchors.Mastodon(
4949+ // Any Mastodon post, including ones on a Sharkey instance should work here.
5050+ mastodon: option.Some(chilp.mastodon(
6351 instance: "procial.tchncs.de",
6464- postid: "alf5j0fozrnl0002",
5252+ post_id: "alf5j0fozrnl0002",
6553 )),
6666- // A post on a regular instance
6767- // mastodon: option.Some(anchors.Mastodon(
6868- // instance: "pony.social",
6969- // postid: "115911235653686237",
7070- // )),
7171- bluesky: option.Some(anchors.Bluesky(
5454+ bluesky: option.Some(chilp.bluesky(
7255 did: "did:plc:tydnkicz4pafvkt3jspzldn6",
7373- postid: "3mhwwbldyjc2o",
5656+ post_id: "3mhwwbldyjc2o",
7457 )),
7558 ),
7659 ])
+5-24
src/chilp.gleam
···507507 case comment.source, bsky_op_profile, mastodon_op_profile {
508508 "Mastodon", _, Some(op) -> op == comment.author_profile_link
509509510510- "Bluesky", Some(op), _ -> {
510510+ "Bluesky", Some(op), _ ->
511511 // Had some mismatches here, but decided it is of no importance what hostname we use.
512512- {
513513- op
514514- |> string.replace("https://bsky.app", "")
515515- |> string.replace("https://bluesky.app", "")
516516- }
517517- == {
518518- comment.author_profile_link
519519- |> string.replace("https://bsky.app", "")
520520- |> string.replace("https://bluesky.app", "")
521521- }
522522- }
512512+ op == comment.author_profile_link
513513+523514 _, _, _ -> False
524515 }
525516 }
···531522 "Mastodon", _, Some(op) -> op == child.author_profile_link
532523533524 "Bluesky", Some(op), _ -> {
534534- // Had some mismatches here, but decided it is of no importance what hostname we use.
535535- {
536536- op
537537- |> string.replace("https://bsky.app", "")
538538- |> string.replace("https://bluesky.app", "")
539539- }
540540- == {
541541- child.author_profile_link
542542- |> string.replace("https://bsky.app", "")
543543- |> string.replace("https://bluesky.app", "")
544544- }
525525+ op == child.author_profile_link
545526 }
546527 _, _, _ -> False
547528 }
···13851366 |> string.replace("at://", "")
13861367 },
13871368 created_at:,
13881388- author_profile_link: "https://bluesky.app/profile/" <> author_did,
13691369+ author_profile_link: "https://bsky.app/profile/" <> author_did,
13891370 source: "Bluesky",
13901371 agreeability: like_count,
13911372 content: element.text(body_text),