Keep search query on reload
This commit is contained in:
parent
8ba89d3e05
commit
c02f7c039a
@ -57,10 +57,11 @@ class NoteController(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun search(request: Request, jwtPayload: JwtPayload): Response {
|
fun search(request: Request, jwtPayload: JwtPayload): Response {
|
||||||
val terms = request.searchTerms()
|
val query = request.form("search") ?: ""
|
||||||
|
val terms = parseSearchTerms(query)
|
||||||
val notes = noteService.search(jwtPayload.userId, terms)
|
val notes = noteService.search(jwtPayload.userId, terms)
|
||||||
val deletedCount = noteService.countDeleted(jwtPayload.userId)
|
val deletedCount = noteService.countDeleted(jwtPayload.userId)
|
||||||
return Response(OK).html(view.search(jwtPayload, notes, deletedCount))
|
return Response(OK).html(view.search(jwtPayload, notes, query, deletedCount))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun note(request: Request, jwtPayload: JwtPayload): Response {
|
fun note(request: Request, jwtPayload: JwtPayload): Response {
|
||||||
@ -132,6 +133,4 @@ class NoteController(
|
|||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Request.searchTerms(): SearchTerms = parseSearchTerms(form("search") ?: "")
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -71,10 +71,11 @@ class NoteView(staticFileResolver: StaticFileResolver) : View(staticFileResolver
|
|||||||
fun search(
|
fun search(
|
||||||
jwtPayload: JwtPayload,
|
jwtPayload: JwtPayload,
|
||||||
notes: List<PersistedNoteMetadata>,
|
notes: List<PersistedNoteMetadata>,
|
||||||
|
query: String,
|
||||||
numberOfDeletedNotes: Int,
|
numberOfDeletedNotes: Int,
|
||||||
) = renderPage("Notes", jwtPayload = jwtPayload) {
|
) = renderPage("Notes", jwtPayload = jwtPayload) {
|
||||||
div("container mx-auto p-4") {
|
div("container mx-auto p-4") {
|
||||||
noteListHeader(numberOfDeletedNotes)
|
noteListHeader(numberOfDeletedNotes, query)
|
||||||
noteTable(notes)
|
noteTable(notes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import kotlinx.html.*
|
|||||||
import kotlinx.html.ButtonType.submit
|
import kotlinx.html.ButtonType.submit
|
||||||
import kotlinx.html.FormMethod.post
|
import kotlinx.html.FormMethod.post
|
||||||
|
|
||||||
fun DIV.noteListHeader(numberOfDeletedNotes: Int) {
|
fun DIV.noteListHeader(numberOfDeletedNotes: Int, query: String = "") {
|
||||||
div("flex justify-between mb-4") {
|
div("flex justify-between mb-4") {
|
||||||
h1("text-2xl underline") { +"Notes" }
|
h1("text-2xl underline") { +"Notes" }
|
||||||
span {
|
span {
|
||||||
@ -23,7 +23,9 @@ fun DIV.noteListHeader(numberOfDeletedNotes: Int) {
|
|||||||
input(
|
input(
|
||||||
name = "search",
|
name = "search",
|
||||||
classes = "$colors rounded w-3/4 border appearance-none focus:outline-none text-base p-2"
|
classes = "$colors rounded w-3/4 border appearance-none focus:outline-none text-base p-2"
|
||||||
)
|
) {
|
||||||
|
attributes["value"] = query
|
||||||
|
}
|
||||||
button(type = submit, classes = "btn btn-green w-1/4") {
|
button(type = submit, classes = "btn btn-green w-1/4") {
|
||||||
+"search"
|
+"search"
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user