link-view: in pagination logic, only +lent once

Also just use +swag instead of chaining +scag and +slag manually.
This commit is contained in:
Fang 2020-04-13 21:26:44 +02:00
parent 8f3d174c94
commit 4da0d636d3
No known key found for this signature in database
GPG Key ID: EB035760C1BBA972

View File

@ -161,15 +161,16 @@
::
++ page-size 25
++ get-paginated
|* [p=(unit @ud) l=(list)]
^- [total=@ud pages=@ud page=_l]
:+ (lent l)
%+ add (div (lent l) page-size)
(min 1 (mod (lent l) page-size))
?~ p l
%+ scag page-size
%+ slag (mul u.p page-size)
l
|* [page=(unit @ud) list=(list)]
^- [total=@ud pages=@ud page=_list]
=/ l=@ud (lent list)
:+ l
%+ add (div l page-size)
(min 1 (mod l page-size))
?~ page list
%+ swag
[(mul u.page page-size) page-size]
list
::
++ page-to-json
=, enjs:format