Minor cleanup
This commit is contained in:
parent
d9335ee0f0
commit
918cda96cf
1 changed files with 20 additions and 18 deletions
|
|
@ -24,22 +24,23 @@ when defined(js):
|
||||||
name.strip().replace(" ", "-").toLowerAscii
|
name.strip().replace(" ", "-").toLowerAscii
|
||||||
|
|
||||||
proc onCategoryLoad(state: CategoryPicker): proc (httpStatus: int, response: kstring) =
|
proc onCategoryLoad(state: CategoryPicker): proc (httpStatus: int, response: kstring) =
|
||||||
return proc (httpStatus: int, response: kstring) =
|
return
|
||||||
state.loading = false
|
proc (httpStatus: int, response: kstring) =
|
||||||
state.status = httpStatus.HttpCode
|
state.loading = false
|
||||||
if state.status != Http200: return
|
state.status = httpStatus.HttpCode
|
||||||
|
if state.status != Http200: return
|
||||||
|
|
||||||
let parsed = parseJson($response)
|
let parsed = parseJson($response)
|
||||||
let list = parsed.to(CategoryList)
|
let list = parsed.to(CategoryList)
|
||||||
list.categories.sort(cmpNames)
|
list.categories.sort(cmpNames)
|
||||||
|
|
||||||
if state.list.isSome:
|
if state.list.isSome:
|
||||||
state.list.get().categories.add(list.categories)
|
state.list.get().categories.add(list.categories)
|
||||||
else:
|
else:
|
||||||
state.list = some(list)
|
state.list = some(list)
|
||||||
|
|
||||||
if state.selectedCategoryID > state.list.get().categories.len():
|
if state.selectedCategoryID > state.list.get().categories.len():
|
||||||
state.selectedCategoryID = 0
|
state.selectedCategoryID = 0
|
||||||
|
|
||||||
proc loadCategories(state: CategoryPicker) =
|
proc loadCategories(state: CategoryPicker) =
|
||||||
if not state.loading:
|
if not state.loading:
|
||||||
|
|
@ -81,10 +82,11 @@ when defined(js):
|
||||||
proc onCategoryClick(state: CategoryPicker, category: Category): proc (ev: Event, n: VNode) =
|
proc onCategoryClick(state: CategoryPicker, category: Category): proc (ev: Event, n: VNode) =
|
||||||
# this is necessary to capture the right value
|
# this is necessary to capture the right value
|
||||||
let cat = category
|
let cat = category
|
||||||
return proc (ev: Event, n: VNode) =
|
return
|
||||||
let oldCategory = state[state.selectedCategoryID]
|
proc (ev: Event, n: VNode) =
|
||||||
state.select(cat.id)
|
let oldCategory = state[state.selectedCategoryID]
|
||||||
state.onCategoryChange(oldCategory, cat)
|
state.select(cat.id)
|
||||||
|
state.onCategoryChange(oldCategory, cat)
|
||||||
|
|
||||||
proc onAddCategoryPost(httpStatus: int, response: kstring, state: CategoryPicker) =
|
proc onAddCategoryPost(httpStatus: int, response: kstring, state: CategoryPicker) =
|
||||||
postFinished:
|
postFinished:
|
||||||
|
|
@ -181,4 +183,4 @@ when defined(js):
|
||||||
onClick=onCategoryClick(state, category)):
|
onClick=onCategoryClick(state, category)):
|
||||||
render(category)
|
render(category)
|
||||||
if state.addEnabled:
|
if state.addEnabled:
|
||||||
genAddCategory(state)
|
genAddCategory(state)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue