chilp/widget/base

No-component widget This is the Mastodon Widget except much more customisable. This version might also influence your application logic a bit much. If you really want to customise, use this module, otherwise default to

Types

This stores metadata that is handled internally by Chilp You should store this on your model!

pub opaque type ChilpDataInYourModel(msg)
pub opaque type ChilpModel

Chilp’s widget needs to be able to send these messages to your update function, and you should handle them with chilp/widget.update(ChilpMsg).

pub opaque type ChilpMsg

Allows you to edit your widget, you can replace or append to any values here. Do note, removing stuff might remove functionality! By default, some Tailwind/DaisyUI classes are added.

pub type CommentWidget(msg) {
  CommentWidget(
    post: MastodonPost,
    recursion_limit: Int,
    emit_error: Bool,
    widget_header: #(String, List(attribute.Attribute(msg))),
    widget: List(attribute.Attribute(msg)),
    load_button: List(attribute.Attribute(msg)),
    comments_section: List(attribute.Attribute(msg)),
    children_section: List(attribute.Attribute(msg)),
    go_reply_form: List(attribute.Attribute(msg)),
    go_reply_label: List(attribute.Attribute(msg)),
    go_reply_text_box: List(attribute.Attribute(msg)),
    go_reply_button: List(attribute.Attribute(msg)),
    comment_article: List(attribute.Attribute(msg)),
    comment_article_by_op: List(attribute.Attribute(msg)),
    comment_header: List(attribute.Attribute(msg)),
    loading_span: List(attribute.Attribute(msg)),
    avatar_img: List(attribute.Attribute(msg)),
    error_element: List(attribute.Attribute(msg)),
    metadata_div: List(attribute.Attribute(msg)),
    displayname: List(attribute.Attribute(msg)),
    written_at: List(attribute.Attribute(msg)),
    content_section: List(attribute.Attribute(msg)),
    comment_link: List(attribute.Attribute(msg)),
    comment_footer: List(attribute.Attribute(msg)),
    widget_subheader: List(attribute.Attribute(msg)),
    widget_subheader_link: List(attribute.Attribute(msg)),
    or_create_an_account_link: List(attribute.Attribute(msg)),
    or_create_an_account_disclaimer: List(
      attribute.Attribute(msg),
    ),
    instancelist: List(String),
  )
}

Constructors

pub opaque type MastodonPost

Values

pub fn force(
  on on: CommentWidget(msg),
  chilp_model model: ChilpDataInYourModel(msg),
) -> effect.Effect(msg)

Force is like trigger, except returns the Effect instead of the message, allowing you to embed it in your init or update function instead of in your view. This is something you’ll want if you know beforehand which post comments to display.

pub fn init(
  message message: fn(ChilpMsg) -> msg,
) -> ChilpDataInYourModel(msg)
pub fn new(
  instance instance: String,
  post_id postid: String,
  chilp_model model: ChilpDataInYourModel(msg),
) -> CommentWidget(msg)

Creates a comment widget, this is where you should probably start!

This function takes three arguments:

  • instance: The instance name, e.g. mastodon.social
  • postid: A post id to bind to, you’ll find this in a post url https://mastodon.social/@<username>/[postid].
  • messages: Some messages that chilp needs to be able to send The resulting comment widget can be edited however you’d like, but is
pub fn show(
  from attributes: CommentWidget(msg),
  data model: ChilpDataInYourModel(msg),
) -> element.Element(msg)

This is what will show your comment block.

pub fn trigger(
  on on: CommentWidget(msg),
  chilp_model model: ChilpDataInYourModel(msg),
) -> msg

Trigger forces the widget to load in data before the user clicked the button. This is something you’ll want if you know beforehand which post comments to display.

pub fn update(
  message: ChilpMsg,
  model: ChilpDataInYourModel(msg),
  change_url: fn(String) -> effect.Effect(msg),
) -> #(ChilpDataInYourModel(msg), effect.Effect(msg))

The update handler for chilp-specific messages!

It takes in three values:

  • message: The message it handles
  • model: the chilp data from your model
  • change_url: A side-effect! This may not ever be called, but when it does, know that it should take that string, and browse the user to it.
Search Document