diff --git a/mixins/Input.pixy b/mixins/Input.pixy index fadabc4d..5d97e398 100644 --- a/mixins/Input.pixy +++ b/mixins/Input.pixy @@ -18,9 +18,9 @@ component InputNumberWithButtons(id string, value float64, label string, placeho label(for=id)= label + ":" .number-input-container input.widget-ui-element.action(id=id, data-field=id, type="number", value=value, min=min, max=max, step=step, placeholder=placeholder, title=placeholder, data-action="save", data-trigger="change") - button + button.action(data-action="addNumber", data-trigger="click", data-id=id, data-add="1") RawIcon("plus") - button + button.action(data-action="addNumber", data-trigger="click", data-id=id, data-add="-1") RawIcon("minus") component InputSelection(id string, value string, label string, placeholder string, options []*arn.Option) diff --git a/scripts/Actions/Serialization.ts b/scripts/Actions/Serialization.ts index c575cb4f..f0dae5bf 100644 --- a/scripts/Actions/Serialization.ts +++ b/scripts/Actions/Serialization.ts @@ -5,7 +5,7 @@ export function save(arn: AnimeNotifier, input: HTMLElement) { let obj = {} let isContentEditable = input.isContentEditable let value = isContentEditable ? input.innerText : (input as HTMLInputElement).value - + if(value === undefined) { return } @@ -77,4 +77,17 @@ export function increaseEpisode(arn: AnimeNotifier, element: HTMLElement) { let episodes = parseInt(prev.innerText) prev.innerText = String(episodes + 1) save(arn, prev) +} + +// Add number +export function addNumber(arn: AnimeNotifier, element: HTMLElement) { + if(arn.isLoading) { + return + } + + let input = arn.app.find(element.dataset.id) as HTMLInputElement + let add = parseInt(element.dataset.add) + let num = parseInt(input.value) + input.value = (num + add).toString() + save(arn, input) } \ No newline at end of file