ccoverstreet / Jablko

Smart Home Interface powered by Go.
MIT License
1 stars 0 forks source link

Frontend Library Functions #126

Open ccoverstreet opened 2 years ago

ccoverstreet commented 2 years ago

There is some functionality that would be helpful to include in the front-end. For instance, custom popups/alerts would make Jablko feel more cohesive and allow for modules on the front-end to more uniformly interact with users.

A cool idea would be to specify a prompt format using a JavaScript object to specify a format with outputs.

{
  fields: [
    {
      label: "Some prompt",
      id: "input1",
      type: "input"
    },
    {
      label: "Second prompt",
      id: "checkbox1",
      type: "checkbox"
    }
  ]
}

A good example usage for this type of library would be the prompts needed for Jarmuz-Status and Jablko-Cookbook. Right now, they are implemented by swapping the displayed content of the dashboard card to a prompt like screen. Both of these JMODs have almost the exact same implementation, which leads to a lot of redundant and tedious display code. By having a Jablko-Frontend Library, much of the effort with unifying appearance and making sure data appears as requested could be removed from JMOD development. This would greatly reduce potential bugs in code for both behavior and appearance of JMODs and reduce the amount of layout shifts that occur when a JMOD swaps visible content.

ccoverstreet commented 2 years ago

It might also be helpful to pass a submit handler function to JPrompt. The submit handler would receive the output JSON object and the HTML node. This way, remove is called by the callback function and individual JMODs have the opportunity to validate the output. If the output is invalid, JAlert could be used to prompt the user on what to change.

ccoverstreet commented 2 years ago

Proof of concept works pretty well. Just need to namespace and add to template.html

ccoverstreet commented 2 years ago

Initial version has been added with jablko.prompt, jablko.alert, and jablko.confirm. jablko.alert implementation may change a little.