Add a load-more button to item list

This commit is contained in:
Eike Kettner
2020-06-06 02:08:20 +02:00
parent e5b90eff34
commit b150269528
9 changed files with 251 additions and 16 deletions

View File

@ -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