A music player that connects to your cloud/distributed storage.
at main 3.4 kB view raw
1module Notifications exposing (Action, Kind(..), Notification, Options, casual, contents, dismiss, error, errorWithCode, id, kind, options, stickyCasual, stickyError, stickySuccess, success) 2 3import Chunky exposing (..) 4import Html exposing (Html) 5import Markdown 6import Murmur3 exposing (..) 7 8 9 10-- 🌳 11 12 13type Notification msg 14 = Notification Kind Int Options (Html msg) 15 16 17type alias Action msg = 18 { label : String, msg : msg } 19 20 21type alias Options = 22 { sticky : Bool, wasDismissed : Bool } 23 24 25type Kind 26 = Casual 27 | Error 28 | Success 29 30 31 32-- 🔱 33 34 35id : Notification msg -> Int 36id (Notification _ i _ _) = 37 i 38 39 40contents : Notification msg -> Html msg 41contents (Notification _ _ _ c) = 42 c 43 44 45kind : Notification msg -> Kind 46kind (Notification k _ _ _) = 47 k 48 49 50options : Notification msg -> Options 51options (Notification _ _ o _) = 52 o 53 54 55 56-- ⚗️ 57 58 59dismiss : Notification msg -> Notification msg 60dismiss (Notification k i o c) = 61 Notification k i { o | wasDismissed = True } c 62 63 64 65-- 🚨 66 67 68error : String -> Notification msg 69error content = 70 Notification 71 Error 72 (hashString 0 content) 73 { sticky = False 74 , wasDismissed = False 75 } 76 (render content) 77 78 79stickyError : String -> Notification msg 80stickyError content = 81 Notification 82 Error 83 (hashString 0 content) 84 { sticky = True 85 , wasDismissed = False 86 } 87 (render content) 88 89 90errorWithCode : String -> String -> List (Action msg) -> Notification msg 91errorWithCode content code _ = 92 Notification 93 Error 94 (hashString 0 content) 95 { sticky = True 96 , wasDismissed = False 97 } 98 (Html.div 99 [] 100 [ render content 101 , if String.isEmpty (String.trim code) then 102 nothing 103 104 else 105 chunk 106 [ "bg-black-50" 107 , "break-all" 108 , "rounded" 109 , "mb-0" 110 , "mt-3" 111 , "p-2" 112 , "text-xxs" 113 ] 114 [ slab 115 Html.code 116 [] 117 [ "align-middle" ] 118 [ Html.text code ] 119 ] 120 ] 121 ) 122 123 124 125-- 💚 126 127 128success : String -> Notification msg 129success content = 130 Notification 131 Success 132 (hashString 0 content) 133 { sticky = False 134 , wasDismissed = False 135 } 136 (render content) 137 138 139stickySuccess : String -> Notification msg 140stickySuccess content = 141 Notification 142 Success 143 (hashString 0 content) 144 { sticky = True 145 , wasDismissed = False 146 } 147 (render content) 148 149 150 151-- 🦉 152 153 154casual : String -> Notification msg 155casual content = 156 Notification 157 Casual 158 (hashString 0 content) 159 { sticky = False 160 , wasDismissed = False 161 } 162 (render content) 163 164 165stickyCasual : String -> Notification msg 166stickyCasual content = 167 Notification 168 Casual 169 (hashString 0 content) 170 { sticky = True 171 , wasDismissed = False 172 } 173 (render content) 174 175 176 177-- ⚗️ 178 179 180render : String -> Html msg 181render content = 182 content 183 |> String.lines 184 |> List.map String.trimLeft 185 |> String.join "\n" 186 |> Markdown.toHtml []