Load more button works.
This commit is contained in:
parent
032d70a233
commit
656b679a51
1 changed files with 15 additions and 3 deletions
|
|
@ -39,10 +39,12 @@ when defined(js):
|
||||||
type
|
type
|
||||||
State = ref object
|
State = ref object
|
||||||
list: Option[ThreadList]
|
list: Option[ThreadList]
|
||||||
|
loading: bool
|
||||||
|
|
||||||
proc newState(): State =
|
proc newState(): State =
|
||||||
State(
|
State(
|
||||||
list: none[ThreadList]()
|
list: none[ThreadList](),
|
||||||
|
loading: false
|
||||||
)
|
)
|
||||||
|
|
||||||
var
|
var
|
||||||
|
|
@ -119,6 +121,7 @@ when defined(js):
|
||||||
text renderActivity(thread.activity)
|
text renderActivity(thread.activity)
|
||||||
|
|
||||||
proc onThreadList(httpStatus: int, response: kstring) =
|
proc onThreadList(httpStatus: int, response: kstring) =
|
||||||
|
state.loading = false
|
||||||
let parsed = parseJson($response)
|
let parsed = parseJson($response)
|
||||||
let list = to(parsed, ThreadList)
|
let list = to(parsed, ThreadList)
|
||||||
|
|
||||||
|
|
@ -129,6 +132,11 @@ when defined(js):
|
||||||
else:
|
else:
|
||||||
state.list = some(list)
|
state.list = some(list)
|
||||||
|
|
||||||
|
proc onLoadMore(ev: Event, n: VNode) =
|
||||||
|
state.loading = true
|
||||||
|
let start = state.list.get().threads.len
|
||||||
|
ajaxGet(baseUrl & "threads.json?start=" & $start, @[], onThreadList)
|
||||||
|
|
||||||
proc genThreadList(): VNode =
|
proc genThreadList(): VNode =
|
||||||
if state.list.isNone:
|
if state.list.isNone:
|
||||||
ajaxGet(baseUrl & "threads.json", @[], onThreadList)
|
ajaxGet(baseUrl & "threads.json", @[], onThreadList)
|
||||||
|
|
@ -163,8 +171,12 @@ when defined(js):
|
||||||
|
|
||||||
if list.moreCount > 0:
|
if list.moreCount > 0:
|
||||||
tr(class="load-more-separator"):
|
tr(class="load-more-separator"):
|
||||||
td(colspan="6"):
|
if state.loading:
|
||||||
span(text "load more threads")
|
td(colspan="6"):
|
||||||
|
tdiv(class="loading loading-lg")
|
||||||
|
else:
|
||||||
|
td(colspan="6", onClick=onLoadMore):
|
||||||
|
span(text "load more threads")
|
||||||
|
|
||||||
proc renderThreadList*(): VNode =
|
proc renderThreadList*(): VNode =
|
||||||
result = buildHtml(tdiv):
|
result = buildHtml(tdiv):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue