▍ humdrum codex / ticktock v0.0.2
license AGPL-3.0
924 B raw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package day

import (
	"github.com/charmbracelet/huh"

	"ticktock/internal/store"
	"ticktock/internal/tui/form"
)

// formValues aliases the shared form value type so existing day code/tests keep
// their names.
type formValues = form.Values

// newEditForm builds the edit form bound to fv, prefilled from e, with history
// suggestions attached.
func newEditForm(e store.Entry, fv *formValues, sug form.Suggest) *huh.Form {
	return form.New(e, fv, sug)
}

// buildUpdated turns edited form values into a new Entry on the given date.
func buildUpdated(date string, orig store.Entry, f formValues) (store.Entry, error) {
	return form.BuildEntry(date, orig, f)
}

// applyEdit validates and writes an edit through the store.
func applyEdit(s store.Store, date string, orig store.Entry, f formValues) error {
	up, err := buildUpdated(date, orig, f)
	if err != nil {
		return err
	}
	return s.SafeReplace(orig.Key, up, orig)
}