Show item position in detail view

This commit is contained in:
Eike Kettner
2021-02-17 22:18:22 +01:00
parent a79fa6f74a
commit e07d732193
3 changed files with 51 additions and 11 deletions

View File

@ -1,7 +1,43 @@
module Data.ItemNav exposing (ItemNav)
module Data.ItemNav exposing (ItemNav, fromList)
import Api.Model.ItemLight exposing (ItemLight)
import Api.Model.ItemLightList exposing (ItemLightList)
import Util.List
type alias ItemNav =
{ prev : Maybe String
, next : Maybe String
, index : Maybe Int
, length : Int
}
fromList : ItemLightList -> String -> ItemNav
fromList list id =
let
all : List ItemLight
all =
List.concatMap .items list.groups
next =
Util.List.findNext (\i -> i.id == id) all
|> Maybe.map .id
prev =
Util.List.findPrev (\i -> i.id == id) all
|> Maybe.map .id
len =
List.length all
index : Maybe Int
index =
Util.List.findIndexed (.id >> (==) id) all
|> Maybe.map Tuple.second
in
{ prev = prev
, next = next
, index = index
, length = len
}