saasitone/templ/pages/cache.templ

47 lines
1.3 KiB
Plaintext

package pages
import (
"git.grosinger.net/tgrosinger/saasitone/templ/components"
"git.grosinger.net/tgrosinger/saasitone/pkg/form"
"git.grosinger.net/tgrosinger/saasitone/pkg/page"
)
type CacheForm struct {
Value string `form:"value"`
form.Submission
}
templ Cache(p page.Page, f *CacheForm, value *string) {
<form id="task" method="post" hx-post={ p.ToURL("cache.submit") }>
<article class="message">
<div class="message-header">
<p>Test the cache</p>
</div>
<div class="message-body">
This route handler shows how the default in-memory cache works. Try updating the value using the form below and see how it persists after you reload the page.
HTMX makes it easy to re-render the cached value after the form is submitted.
</div>
</article>
<label for="value" class="label">Value in cache: </label>
if value != nil {
<span class="tag is-success">{ *value }</span>
} else {
<i>(empty)</i>
}
<br/>
<br/>
<div class="field">
<label for="value" class="label">Value</label>
<div class="control">
<input id="value" name="value" class="input" value={ f.Value }/>
</div>
</div>
<div class="field is-grouped">
<div class="control">
<button class="button is-link">Update cache</button>
</div>
</div>
@components.CSRF(p.CSRF)
</form>
}