diff --git a/web/Makefile b/web/Makefile index 1a4dff8..c1bd9d3 100644 --- a/web/Makefile +++ b/web/Makefile @@ -6,6 +6,7 @@ dependencies: go get -u github.com/gopherjs/gopherjs go get -u github.com/bep/debounce go get -u github.com/gopherjs/jquery + go get -u go get github.com/go-humble/locstor go get -u gitlab.com/chrissexton/togoist togoist: togoist.go web.go dependencies diff --git a/web/web.go b/web/web.go index f857d4b..cc537d0 100644 --- a/web/web.go +++ b/web/web.go @@ -4,6 +4,7 @@ import ( "time" "github.com/bep/debounce" + "github.com/go-humble/locstor" "github.com/gopherjs/jquery" "gitlab.com/chrissexton/togoist" ) @@ -25,13 +26,25 @@ func handleChange() { jQuery("#output").SetText(err.Error()) return } + locstor.SetItem("tmpl", tmpl) + locstor.SetItem("input", input) jQuery("#output").SetText(out) }) } +func getLocalStorage() { + if tmpl, err := locstor.GetItem("tmpl"); err == nil { + jQuery("#tmpl").SetText(tmpl) + } + if input, err := locstor.GetItem("input"); err == nil { + jQuery("#input").SetText(input) + } + handleChange() +} + func main() { debounced, _ := debounce.New(time.Second) jQuery("#tmpl").On(jquery.KEYUP, func() { debounced(handleChange) }) jQuery("#input").On(jquery.KEYUP, func() { debounced(handleChange) }) - handleChange() + getLocalStorage() }