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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187module Notifications exposing (Action, Kind(..), Notification, Options, casual, contents, dismiss, error, errorWithCode, id, kind, options, stickyCasual, stickyError, stickySuccess, success)
import Chunky exposing (..)import Html exposing (Html)import Markdownimport Murmur3 exposing (..)
-- 🌳
type Notification msg = Notification Kind Int Options (Html msg)
type alias Action msg = { label : String, msg : msg }
type alias Options = { sticky : Bool, wasDismissed : Bool }
type Kind = Casual | Error | Success
-- 🔱
id : Notification msg -> Intid (Notification _ i _ _) = i
contents : Notification msg -> Html msgcontents (Notification _ _ _ c) = c
kind : Notification msg -> Kindkind (Notification k _ _ _) = k
options : Notification msg -> Optionsoptions (Notification _ _ o _) = o
-- ⚗️
dismiss : Notification msg -> Notification msgdismiss (Notification k i o c) = Notification k i { o | wasDismissed = True } c
-- 🚨
error : String -> Notification msgerror content = Notification Error (hashString 0 content) { sticky = False , wasDismissed = False } (render content)
stickyError : String -> Notification msgstickyError content = Notification Error (hashString 0 content) { sticky = True , wasDismissed = False } (render content)
errorWithCode : String -> String -> List (Action msg) -> Notification msgerrorWithCode content code _ = Notification Error (hashString 0 content) { sticky = True , wasDismissed = False } (Html.div [] [ render content , if String.isEmpty (String.trim code) then nothing
else chunk [ "bg-black-50" , "break-all" , "rounded" , "mb-0" , "mt-3" , "p-2" , "text-xxs" ] [ slab Html.code [] [ "align-middle" ] [ Html.text code ] ] ] )
-- 💚
success : String -> Notification msgsuccess content = Notification Success (hashString 0 content) { sticky = False , wasDismissed = False } (render content)
stickySuccess : String -> Notification msgstickySuccess content = Notification Success (hashString 0 content) { sticky = True , wasDismissed = False } (render content)
-- 🦉
casual : String -> Notification msgcasual content = Notification Casual (hashString 0 content) { sticky = False , wasDismissed = False } (render content)
stickyCasual : String -> Notification msgstickyCasual content = Notification Casual (hashString 0 content) { sticky = True , wasDismissed = False } (render content)
-- ⚗️
render : String -> Html msgrender content = content |> String.lines |> List.map String.trimLeft |> String.join "\n" |> Markdown.toHtml []