mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-04-04 10:29:34 +00:00
106 lines
2.3 KiB
Elm
106 lines
2.3 KiB
Elm
module Page.Home.Data exposing
|
|
( Model
|
|
, Msg(..)
|
|
, ViewMode(..)
|
|
, doSearchCmd
|
|
, init
|
|
, itemNav
|
|
, resultsBelowLimit
|
|
)
|
|
|
|
import Api
|
|
import Api.Model.ItemLightList exposing (ItemLightList)
|
|
import Comp.ItemCardList
|
|
import Comp.SearchMenu
|
|
import Data.Flags exposing (Flags)
|
|
import Data.Items
|
|
import Data.UiSettings exposing (UiSettings)
|
|
import Http
|
|
|
|
|
|
type alias Model =
|
|
{ searchMenuModel : Comp.SearchMenu.Model
|
|
, itemListModel : Comp.ItemCardList.Model
|
|
, searchInProgress : Bool
|
|
, viewMode : ViewMode
|
|
, menuCollapsed : Bool
|
|
, searchOffset : Int
|
|
, moreAvailable : Bool
|
|
, moreInProgress : Bool
|
|
, uiSettings : UiSettings
|
|
}
|
|
|
|
|
|
init : Flags -> Model
|
|
init _ =
|
|
{ searchMenuModel = Comp.SearchMenu.emptyModel
|
|
, itemListModel = Comp.ItemCardList.init
|
|
, searchInProgress = False
|
|
, viewMode = Listing
|
|
, menuCollapsed = False
|
|
, searchOffset = 0
|
|
, moreAvailable = True
|
|
, moreInProgress = False
|
|
, uiSettings = Data.UiSettings.defaults
|
|
}
|
|
|
|
|
|
type Msg
|
|
= Init
|
|
| SearchMenuMsg Comp.SearchMenu.Msg
|
|
| ResetSearch
|
|
| ItemCardListMsg Comp.ItemCardList.Msg
|
|
| ItemSearchResp (Result Http.Error ItemLightList)
|
|
| ItemSearchAddResp (Result Http.Error ItemLightList)
|
|
| DoSearch
|
|
| ToggleSearchMenu
|
|
| LoadMore
|
|
| GetUiSettings UiSettings
|
|
|
|
|
|
type ViewMode
|
|
= Listing
|
|
| Detail
|
|
|
|
|
|
itemNav : String -> Model -> { prev : Maybe String, next : Maybe String }
|
|
itemNav id model =
|
|
let
|
|
prev =
|
|
Comp.ItemCardList.prevItem model.itemListModel id
|
|
|
|
next =
|
|
Comp.ItemCardList.nextItem model.itemListModel id
|
|
in
|
|
{ prev = Maybe.map .id prev
|
|
, next = Maybe.map .id next
|
|
}
|
|
|
|
|
|
doSearchCmd : Flags -> Int -> Model -> Cmd Msg
|
|
doSearchCmd flags offset model =
|
|
let
|
|
smask =
|
|
Comp.SearchMenu.getItemSearch model.searchMenuModel
|
|
|
|
mask =
|
|
{ smask
|
|
| limit = model.uiSettings.itemSearchPageSize
|
|
, offset = offset
|
|
}
|
|
in
|
|
if offset == 0 then
|
|
Api.itemSearch flags mask ItemSearchResp
|
|
|
|
else
|
|
Api.itemSearch flags mask ItemSearchAddResp
|
|
|
|
|
|
resultsBelowLimit : Model -> Bool
|
|
resultsBelowLimit model =
|
|
let
|
|
len =
|
|
Data.Items.length model.itemListModel.results
|
|
in
|
|
len < model.uiSettings.itemSearchPageSize
|