mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-26 02:48:25 +00:00
Add a load-more button to item list
This commit is contained in:
@ -2,13 +2,19 @@ module Page.Home.Data exposing
|
||||
( Model
|
||||
, Msg(..)
|
||||
, ViewMode(..)
|
||||
, emptyModel
|
||||
, doSearchCmd
|
||||
, init
|
||||
, itemNav
|
||||
, resultsBelowLimit
|
||||
, searchLimit
|
||||
)
|
||||
|
||||
import Api
|
||||
import Api.Model.ItemLightList exposing (ItemLightList)
|
||||
import Comp.ItemCardList
|
||||
import Comp.SearchMenu
|
||||
import Data.Flags exposing (Flags)
|
||||
import Data.Items
|
||||
import Http
|
||||
|
||||
|
||||
@ -18,16 +24,22 @@ type alias Model =
|
||||
, searchInProgress : Bool
|
||||
, viewMode : ViewMode
|
||||
, menuCollapsed : Bool
|
||||
, searchOffset : Int
|
||||
, moreAvailable : Bool
|
||||
, moreInProgress : Bool
|
||||
}
|
||||
|
||||
|
||||
emptyModel : Model
|
||||
emptyModel =
|
||||
init : Flags -> Model
|
||||
init _ =
|
||||
{ searchMenuModel = Comp.SearchMenu.emptyModel
|
||||
, itemListModel = Comp.ItemCardList.init
|
||||
, searchInProgress = False
|
||||
, viewMode = Listing
|
||||
, menuCollapsed = False
|
||||
, searchOffset = 0
|
||||
, moreAvailable = True
|
||||
, moreInProgress = False
|
||||
}
|
||||
|
||||
|
||||
@ -39,6 +51,7 @@ type Msg
|
||||
| ItemSearchResp (Result Http.Error ItemLightList)
|
||||
| DoSearch
|
||||
| ToggleSearchMenu
|
||||
| LoadMore
|
||||
|
||||
|
||||
type ViewMode
|
||||
@ -58,3 +71,32 @@ itemNav id model =
|
||||
{ prev = Maybe.map .id prev
|
||||
, next = Maybe.map .id next
|
||||
}
|
||||
|
||||
|
||||
searchLimit : Int
|
||||
searchLimit =
|
||||
90
|
||||
|
||||
|
||||
doSearchCmd : Flags -> Int -> Comp.SearchMenu.Model -> Cmd Msg
|
||||
doSearchCmd flags offset model =
|
||||
let
|
||||
smask =
|
||||
Comp.SearchMenu.getItemSearch model
|
||||
|
||||
mask =
|
||||
{ smask
|
||||
| limit = searchLimit
|
||||
, offset = offset
|
||||
}
|
||||
in
|
||||
Api.itemSearch flags mask ItemSearchResp
|
||||
|
||||
|
||||
resultsBelowLimit : Model -> Bool
|
||||
resultsBelowLimit model =
|
||||
let
|
||||
len =
|
||||
Data.Items.length model.itemListModel.results
|
||||
in
|
||||
len < searchLimit
|
||||
|
Reference in New Issue
Block a user