feat: save latest summary in session storage to prevent loss of input
This commit is contained in:
@ -80,7 +80,12 @@ templ IssuePage(vmodel IssuePageVModel) {
|
||||
"hx-push-url", "true",
|
||||
),
|
||||
)
|
||||
@common.FormTextarea(vmodel.SummaryForm, "issue-summary", "summary", "Summary")
|
||||
@common.FormTextarea(
|
||||
vmodel.SummaryForm, "issue-summary", "summary", "Summary",
|
||||
common.WithTextareaAttrs(
|
||||
"hx-on:change", "onSummaryChange(event)",
|
||||
),
|
||||
)
|
||||
</form>
|
||||
</div>
|
||||
<div class="column">
|
||||
@ -104,6 +109,23 @@ templ IssuePage(vmodel IssuePageVModel) {
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
function onSummaryChange(evt) {
|
||||
const summary = evt.currentTarget.value;
|
||||
const projectId = document.getElementById("issue-project").value;
|
||||
sessionStorage.setItem(`summary-${projectId}`, summary);
|
||||
}
|
||||
htmx.onLoad(function(){
|
||||
const summaryTextarea = document.getElementById("issue-summary");
|
||||
const summary = summaryTextarea.value;
|
||||
if (summary !== "") return;
|
||||
const projectId = document.getElementById("issue-project").value;
|
||||
if (!projectId) return;
|
||||
const savedSummary = sessionStorage.getItem(`summary-${projectId}`);
|
||||
if (!savedSummary) return;
|
||||
summaryTextarea.value = savedSummary;
|
||||
})
|
||||
</script>
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user