Something went wrong. Try again.
A music player that connects to your cloud/distributed storage. forked from tokono.ma/diffuse
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667module UI.Notifications exposing (Model, dismiss, show, showWithModel)
import Notifications exposing (..)import Processimport Taskimport UI.Types exposing (Msg(..))
-- 🌳
type alias Model = List (Notification Msg)
-- 📣
dismiss : Model -> { id : Int } -> ( Model, Cmd Msg )dismiss collection { id } = ( List.map (\notification -> if Notifications.id notification == id then Notifications.dismiss notification
else notification ) collection , Task.perform (\_ -> RemoveNotification { id = id }) (Process.sleep 500) )
show : Notification Msg -> Model -> ( Model, Cmd Msg )show notification collection = let existingNotificationIds = List.map Notifications.id collection in if List.member (Notifications.id notification) existingNotificationIds then -- Don't show duplicate notifications ( collection , Cmd.none )
else ( notification :: collection -- Hide notification after a certain amount of time, -- unless it's a sticky notification. , if (Notifications.options notification).sticky then Cmd.none
else Task.perform (\_ -> DismissNotification { id = Notifications.id notification }) (Process.sleep 7500) )
showWithModel : Model -> Notification Msg -> ( Model, Cmd Msg )showWithModel model notification = show notification model