Fix using magic number as default category id
This commit is contained in:
parent
0d63fef0f7
commit
7a7a7145ee
3 changed files with 18 additions and 12 deletions
|
|
@ -93,7 +93,7 @@ proc render(): VNode =
|
|||
),
|
||||
r("/c/@id",
|
||||
(params: Params) =>
|
||||
(renderThreadList(getLoggedInUser(), params["id"].parseInt))
|
||||
(renderThreadList(getLoggedInUser(), some(params["id"].parseInt)))
|
||||
),
|
||||
r("/newthread",
|
||||
(params: Params) =>
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ when defined(js):
|
|||
|
||||
let state = newState()
|
||||
|
||||
proc renderMainButtons*(currentUser: Option[User], categoryId = -1): VNode =
|
||||
proc renderMainButtons*(currentUser: Option[User], categoryIdOption = none(int)): VNode =
|
||||
result = buildHtml():
|
||||
section(class="navbar container grid-xl", id="main-buttons"):
|
||||
section(class="navbar-section"):
|
||||
|
|
@ -38,8 +38,8 @@ when defined(js):
|
|||
ul(class="menu"):
|
||||
li: text "community"
|
||||
li: text "dev" ]#
|
||||
if categoryId != -1:
|
||||
state.categoryPicker.selectedCategoryID = categoryId
|
||||
if categoryIdOption.isSome:
|
||||
state.categoryPicker.selectedCategoryID = categoryIdOption.get()
|
||||
render(state.categoryPicker, currentUser, compact=false)
|
||||
|
||||
for btn in buttons:
|
||||
|
|
|
|||
|
|
@ -147,10 +147,13 @@ when defined(js):
|
|||
else:
|
||||
state.list = some(list)
|
||||
|
||||
proc onLoadMore(ev: Event, n: VNode, categoryId: int) =
|
||||
proc onLoadMore(ev: Event, n: VNode, categoryIdOption: Option[int]) =
|
||||
state.loading = true
|
||||
let start = state.list.get().threads.len
|
||||
ajaxGet(makeUri("threads.json?start=" & $start & "&categoryId=" & $categoryId), @[], onThreadList)
|
||||
if categoryIdOption.isSome:
|
||||
ajaxGet(makeUri("threads.json?start=" & $start & "&categoryId=" & $categoryIdOption.get()), @[], onThreadList)
|
||||
else:
|
||||
ajaxGet(makeUri("threads.json?start=" & $start), @[], onThreadList)
|
||||
|
||||
proc getInfo(
|
||||
list: seq[Thread], i: int, currentUser: Option[User]
|
||||
|
|
@ -175,14 +178,17 @@ when defined(js):
|
|||
isNew: thread.creation > previousVisitAt
|
||||
)
|
||||
|
||||
proc genThreadList(currentUser: Option[User], categoryId: int): VNode =
|
||||
proc genThreadList(currentUser: Option[User], categoryIdOption: Option[int]): VNode =
|
||||
if state.status != Http200:
|
||||
return renderError("Couldn't retrieve threads.", state.status)
|
||||
|
||||
if state.list.isNone:
|
||||
if not state.loading:
|
||||
state.loading = true
|
||||
ajaxGet(makeUri("threads.json?categoryId=" & $categoryId), @[], onThreadList)
|
||||
if categoryIdOption.isSome:
|
||||
ajaxGet(makeUri("threads.json?categoryId=" & $categoryIdOption.get()), @[], onThreadList)
|
||||
else:
|
||||
ajaxGet(makeUri("threads.json"), @[], onThreadList)
|
||||
|
||||
return buildHtml(tdiv(class="loading loading-lg"))
|
||||
|
||||
|
|
@ -223,10 +229,10 @@ when defined(js):
|
|||
tdiv(class="loading loading-lg")
|
||||
else:
|
||||
td(colspan="6",
|
||||
onClick = (ev: Event, n: VNode) => (onLoadMore(ev, n, categoryId))):
|
||||
onClick = (ev: Event, n: VNode) => (onLoadMore(ev, n, categoryIdOption))):
|
||||
span(text "load more threads")
|
||||
|
||||
proc renderThreadList*(currentUser: Option[User], categoryId = -1): VNode =
|
||||
proc renderThreadList*(currentUser: Option[User], categoryIdOption = none(int)): VNode =
|
||||
result = buildHtml(tdiv):
|
||||
renderMainButtons(currentUser, categoryId=categoryId)
|
||||
genThreadList(currentUser, categoryId)
|
||||
renderMainButtons(currentUser, categoryIdOption=categoryIdOption)
|
||||
genThreadList(currentUser, categoryIdOption)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue