Functions
The plugin's code calls these functions, after a click for example. They show one of Hodi's windows or toasts: the plugin doesn't draw them itself, so they look the same as everywhere else in the app.
askToConfirm()
This function opens Hodi's window that asks a question before an action that can't be undone, such as clearing a history. The person confirms with a red button, or cancels.
With proof, the window also asks for the person's password. onConfirm then receives a proof, which the web part passes to a route marked proof: true with api(path, { proof }). Hodi checks the password before running the route.
import { askToConfirm, usePluginApi } from 'hodi:sdk'
const api = usePluginApi()
askToConfirm({
title: 'Clear the history?',
message: 'The last 30 hellos of this household will be deleted.',
label: 'Clear',
onConfirm: () => api('/history', { method: 'DELETE' })
})titlestringThe question asked, such as Clear the history?.
messageReactNodeWhat will happen, in full: what will be erased, for whom, and what will remain.
labelstringThe text of the button that confirms, a verb such as Clear or Delete.
onConfirm(proof: Proof) => void | Promise<void>What the click on that button does. With proof, it receives the password and code typed. If the promise fails, the window stays open.
look?'danger' | 'primary'The button's colour: red by default, primary for an action that adds instead of erasing.
proof?{}Asks for the person's password, and their app's code when they use two-step verification.
onCancel?() => voidWhat happens when the person closes the window without confirming: with Escape, the cross, Cancel or a click beside it.
showDone()
These functions show one of Hodi's toasts: a short message that says what just happened. A toast never asks a question and never holds a form. There are three:
showDonesays an action is done. Withundo, it adds an Undo button.showSavedsays a setting is saved.showErrorsays something failed, with a button to try again if needed.
- Greeting saved
- Greeting saved
import { showDone } from 'hodi:sdk'
showDone('Greeting saved')showDone(message: string, undo?: () => void) => voidShows the message of an action done. With undo, an Undo button calls that function.
showSaved(message?: string) => voidShows Saved, or the message given. Only one of these toasts stays on screen at a time.
showError(message: string, action?, id?: string) => voidShows a failure. The message, or the action button, says what to do next. With id, a new toast replaces the one with the same id.