From ce673caba1fdfb4bf86187a42ce99646d4a89214 Mon Sep 17 00:00:00 2001 From: Steven Vandevelde Date: Sun, 9 Aug 2020 11:25:50 +0200 Subject: [PATCH] Closes #236 --- src/Applications/UI/Notifications.elm | 36 +++++++++++++++-------- src/Applications/UI/Other/State.elm | 2 +- src/Applications/UI/Queue/State.elm | 8 ++--- src/Applications/UI/Sources/State.elm | 2 +- src/Applications/UI/Tracks/State.elm | 8 ++--- src/Applications/UI/User/State/Import.elm | 2 +- src/Applications/UI/View.elm | 2 +- src/Library/Notifications.elm | 20 ++++++------- 8 files changed, 46 insertions(+), 34 deletions(-) diff --git a/src/Applications/UI/Notifications.elm b/src/Applications/UI/Notifications.elm index 69abdce2..25b349e0 100644 --- a/src/Applications/UI/Notifications.elm +++ b/src/Applications/UI/Notifications.elm @@ -1,12 +1,15 @@ module UI.Notifications exposing (Model, dismiss, show, showWithModel, view) import Chunky exposing (..) +import Color exposing (Color) +import Color.Manipulate import Conditional exposing (ifThenElse) import Css.Classes as C import Html exposing (Html, text) -import Html.Attributes exposing (class, rel) +import Html.Attributes exposing (class, rel, style) import Html.Ext exposing (onDoubleTap, onTap) import Html.Lazy +import Maybe.Extra as Maybe import Notifications exposing (..) import Process import Task @@ -77,11 +80,17 @@ showWithModel model notification = -- 🗺 -view : Model -> Html Msg -view collection = +view : Maybe Color -> Model -> Html Msg +view extractedBackdropColor collection = + let + manipulatedColor = + Maybe.map + (Color.Manipulate.darken 0.125) + extractedBackdropColor + in collection |> List.reverse - |> List.map (Html.Lazy.lazy notificationView) + |> List.map (Html.Lazy.lazy2 notificationView manipulatedColor) |> Html.div [ class "notifications" @@ -92,7 +101,7 @@ view collection = , C.flex_col , C.items_end , C.leading_snug - , C.mb_3 + , C.mb_4 , C.mr_3 , C.right_0 , C.text_sm @@ -100,8 +109,8 @@ view collection = ] -notificationView : Notification Msg -> Html Msg -notificationView notification = +notificationView : Maybe Color -> Notification Msg -> Html Msg +notificationView extractedBackdropColor notification = let kind = Notifications.kind notification @@ -139,21 +148,24 @@ notificationView notification = -- , case kind of + Casual -> + Maybe.unwrap + C.bg_white_20 + (style "background-color" << Color.toCssString) + extractedBackdropColor + Error -> C.bg_base08 Success -> C.bg_base0b - Warning -> - C.bg_white_20 - -- , if options.wasDismissed then C.transition else - C.transition_none + C.transition_colors -- , if options.wasDismissed then @@ -167,7 +179,7 @@ notificationView notification = [ contents notification ] -- - , if options.sticky && kind /= Warning then + , if options.sticky && kind /= Casual then Html.div [ C.cursor_pointer , C.italic diff --git a/src/Applications/UI/Other/State.elm b/src/Applications/UI/Other/State.elm index 5f68b498..a5db612e 100644 --- a/src/Applications/UI/Other/State.elm +++ b/src/Applications/UI/Other/State.elm @@ -62,5 +62,5 @@ setCurrentTime time model = syncHypaethralData : Manager syncHypaethralData model = model - |> Common.showNotification (Notifications.warning "Syncing") + |> Common.showNotification (Notifications.casual "Syncing") |> Return.command (Ports.toBrain <| Alien.trigger Alien.SyncHypaethralData) diff --git a/src/Applications/UI/Queue/State.elm b/src/Applications/UI/Queue/State.elm index e89a006b..a5426a21 100644 --- a/src/Applications/UI/Queue/State.elm +++ b/src/Applications/UI/Queue/State.elm @@ -304,14 +304,14 @@ injectFirst { showNotification } identifiedTracks model = case tracks of [ t ] -> ("__" ++ t.tags.title ++ "__ will be played next") - |> Notifications.success + |> Notifications.casual list -> list |> List.length |> String.fromInt |> (\s -> "__" ++ s ++ " tracks__ will be played next") - |> Notifications.success + |> Notifications.casual in { model | playingNext = items ++ cleanedFuture } |> (if showNotification then @@ -362,14 +362,14 @@ injectLast { showNotification } identifiedTracks model = case tracks of [ t ] -> ("__" ++ t.tags.title ++ "__ was added to the queue") - |> Notifications.success + |> Notifications.casual list -> list |> List.length |> String.fromInt |> (\s -> "__" ++ s ++ " tracks__ were added to the queue") - |> Notifications.success + |> Notifications.casual in { model | playingNext = newFuture } |> (if showNotification then diff --git a/src/Applications/UI/Sources/State.elm b/src/Applications/UI/Sources/State.elm index 0e17bfca..6da30d93 100644 --- a/src/Applications/UI/Sources/State.elm +++ b/src/Applications/UI/Sources/State.elm @@ -189,7 +189,7 @@ processSpecific : List Source -> Manager processSpecific toProcess model = let notification = - Notifications.stickyWarning "Processing sources ..." + Notifications.stickyCasual "Processing sources ..." notificationId = Notifications.id notification diff --git a/src/Applications/UI/Tracks/State.elm b/src/Applications/UI/Tracks/State.elm index dcc1015b..3479a2f4 100644 --- a/src/Applications/UI/Tracks/State.elm +++ b/src/Applications/UI/Tracks/State.elm @@ -218,7 +218,7 @@ clearCache model = |> andThen User.saveEnclosedUserData |> andThen ("Tracks cache was cleared" - |> Notifications.warning + |> Notifications.casual |> Common.showNotification ) @@ -239,7 +239,7 @@ download : String -> List Track -> Manager download zipName tracks model = let notification = - Notifications.stickyWarning "Downloading tracks ..." + Notifications.stickyCasual "Downloading tracks ..." downloading = Just { notificationId = Notifications.id notification } @@ -675,14 +675,14 @@ storeInCache tracks model = case tracks of [ t ] -> ("__" ++ t.tags.title ++ "__ will be stored in the cache") - |> Notifications.success + |> Notifications.casual list -> list |> List.length |> String.fromInt |> (\s -> "__" ++ s ++ " tracks__ will be stored in the cache") - |> Notifications.success + |> Notifications.casual in tracks |> Json.Encode.list diff --git a/src/Applications/UI/User/State/Import.elm b/src/Applications/UI/User/State/Import.elm index b8b36e39..9c1563f7 100644 --- a/src/Applications/UI/User/State/Import.elm +++ b/src/Applications/UI/User/State/Import.elm @@ -77,7 +77,7 @@ importLegacyData model = I'll try to import data from Diffuse version one. If this was successful, you'll get a notification. """ - |> Notifications.warning + |> Notifications.casual |> Common.showNotification ) diff --git a/src/Applications/UI/View.elm b/src/Applications/UI/View.elm index 9e0a5ae4..45ccc426 100644 --- a/src/Applications/UI/View.elm +++ b/src/Applications/UI/View.elm @@ -108,7 +108,7 @@ body model = ----------------------------------------- -- Notifications ----------------------------------------- - , Lazy.lazy UI.Notifications.view model.notifications + , Lazy.lazy2 UI.Notifications.view model.extractedBackdropColor model.notifications ----------------------------------------- -- Overlay diff --git a/src/Library/Notifications.elm b/src/Library/Notifications.elm index 96a6d05e..dc737ed6 100644 --- a/src/Library/Notifications.elm +++ b/src/Library/Notifications.elm @@ -1,4 +1,4 @@ -module Notifications exposing (Action, Kind(..), Notification, Options, contents, dismiss, error, errorWithCode, id, kind, options, stickyError, stickySuccess, stickyWarning, success, warning) +module Notifications exposing (Action, Kind(..), Notification, Options, casual, contents, dismiss, error, errorWithCode, id, kind, options, stickyCasual, stickyError, stickySuccess, success) import Chunky exposing (..) import Css.Classes as C @@ -24,9 +24,9 @@ type alias Options = type Kind - = Error + = Casual + | Error | Success - | Warning @@ -149,13 +149,13 @@ stickySuccess content = --- ⚠️ +-- 🦉 -warning : String -> Notification msg -warning content = +casual : String -> Notification msg +casual content = Notification - Warning + Casual (hashString 0 content) { sticky = False , wasDismissed = False @@ -163,10 +163,10 @@ warning content = (render content) -stickyWarning : String -> Notification msg -stickyWarning content = +stickyCasual : String -> Notification msg +stickyCasual content = Notification - Warning + Casual (hashString 0 content) { sticky = True , wasDismissed = False -- 2.51.2