diff --git a/CHANGELOG.md b/CHANGELOG.md index 786d81fc..d5215e5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,9 @@ ## 3.4.0 -Allows you to make playlists public when using Fission / Webnative. +- Adjusted search behaviour, now searches while typing (with a small delay). +- Allows you to make playlists public when using Fission / Webnative. +- Fixes issue with Safari where reloading after a search caused the loader to be shown indefinitely. ## 3.3.0 diff --git a/src/Applications/UI.elm b/src/Applications/UI.elm index 560bf95f..3d1a4682 100644 --- a/src/Applications/UI.elm +++ b/src/Applications/UI.elm @@ -136,11 +136,16 @@ init flags url key = ----------------------------------------- -- Debouncing ----------------------------------------- - , debounce = + , resizeDebouncer = 0.25 |> Debouncer.fromSeconds |> Debouncer.debounce |> Debouncer.toDebouncer + , searchDebouncer = + 0.5 + |> Debouncer.fromSeconds + |> Debouncer.debounce + |> Debouncer.toDebouncer ----------------------------------------- -- Equalizer @@ -337,9 +342,6 @@ update msg = CopyToClipboard a -> Interface.copyToClipboard a - Debounce a -> - Interface.debounce update a - DismissNotification a -> Common.dismissNotification a @@ -370,9 +372,15 @@ update msg = RemoveTrackSelection -> Interface.removeTrackSelection + ResizeDebounce a -> + Interface.resizeDebounce update a + ResizedWindow a -> Interface.resizedWindow a + SearchDebounce a -> + Interface.searchDebounce update a + SetIsTouchDevice a -> Interface.setIsTouchDevice a diff --git a/src/Applications/UI/Common/State.elm b/src/Applications/UI/Common/State.elm index 623fdd55..db3a45fd 100644 --- a/src/Applications/UI/Common/State.elm +++ b/src/Applications/UI/Common/State.elm @@ -4,6 +4,7 @@ import Browser.Dom import Browser.Navigation as Nav import Common exposing (..) import ContextMenu exposing (ContextMenu) +import Debouncer.Basic as Debouncer exposing (Debouncer) import List.Extra as List import Monocle.Lens as Lens exposing (Lens) import Notifications exposing (Notification) @@ -16,7 +17,7 @@ import UI.Playlists.Directory import UI.Syncing.Types as Syncing import UI.Tracks.Scene.Covers import UI.Tracks.Scene.List -import UI.Types as UI exposing (Manager, Msg) +import UI.Types as UI exposing (Manager, Model, Msg) import User.Layer exposing (Method) @@ -32,6 +33,28 @@ changeUrlUsingPage page model = |> return model +debounce : (Model -> Debouncer Msg Msg) -> (Debouncer Msg Msg -> Model -> Model) -> (Debouncer.Msg Msg -> Msg) -> (Msg -> Model -> ( Model, Cmd Msg )) -> Debouncer.Msg Msg -> Manager +debounce getter setter debouncerMsgContainer update debouncerMsg model = + let + ( subModel, subCmd, emittedMsg ) = + Debouncer.update debouncerMsg (getter model) + + mappedCmd = + Cmd.map debouncerMsgContainer subCmd + + updatedModel = + setter subModel model + in + case emittedMsg of + Just emitted -> + updatedModel + |> update emitted + |> Return.command mappedCmd + + Nothing -> + return updatedModel mappedCmd + + dismissNotification : { id : Int } -> Manager dismissNotification options model = options diff --git a/src/Applications/UI/Common/Types.elm b/src/Applications/UI/Common/Types.elm new file mode 100644 index 00000000..4853e7a4 --- /dev/null +++ b/src/Applications/UI/Common/Types.elm @@ -0,0 +1,12 @@ +module UI.Common.Types exposing (..) + +import Debouncer.Basic as Debouncer +import UI.Types exposing (Manager, Model, Msg) + + + +-- 🌳 + + +type alias DebounceManager = + (Msg -> Model -> ( Model, Cmd Msg )) -> Debouncer.Msg Msg -> Manager diff --git a/src/Applications/UI/Interface/State.elm b/src/Applications/UI/Interface/State.elm index be836f6b..0494c4ad 100644 --- a/src/Applications/UI/Interface/State.elm +++ b/src/Applications/UI/Interface/State.elm @@ -7,6 +7,7 @@ import Return exposing (return) import Return.Ext as Return import Tracks import UI.Common.State as Common +import UI.Common.Types exposing (DebounceManager) import UI.DnD as DnD import UI.Page as Page import UI.Playlists.State as Playlists @@ -38,26 +39,12 @@ copyToClipboard string = |> Return.communicate -debounce : (Msg -> Model -> ( Model, Cmd Msg )) -> Debouncer.Msg Msg -> Manager -debounce update debouncerMsg model = - let - ( subModel, subCmd, emittedMsg ) = - Debouncer.update debouncerMsg model.debounce - - mappedCmd = - Cmd.map Debounce subCmd - - updatedModel = - { model | debounce = subModel } - in - case emittedMsg of - Just emitted -> - updatedModel - |> update emitted - |> Return.command mappedCmd - - Nothing -> - return updatedModel mappedCmd +resizeDebounce : DebounceManager +resizeDebounce = + Common.debounce + .resizeDebouncer + (\d m -> { m | resizeDebouncer = d }) + ResizeDebounce dnd : DnD.Msg Int -> Manager @@ -187,6 +174,14 @@ resizedWindow ( width, height ) model = } +searchDebounce : DebounceManager +searchDebounce = + Common.debounce + .searchDebouncer + (\d m -> { m | searchDebouncer = d }) + SearchDebounce + + setIsTouchDevice : Bool -> Manager setIsTouchDevice bool model = Return.singleton { model | isTouchDevice = bool } @@ -220,4 +215,4 @@ onResize w h = ( w, h ) |> ResizedWindow |> Debouncer.provideInput - |> Debounce + |> ResizeDebounce diff --git a/src/Applications/UI/Tracks/State.elm b/src/Applications/UI/Tracks/State.elm index ac4bcf74..8e13aad0 100644 --- a/src/Applications/UI/Tracks/State.elm +++ b/src/Applications/UI/Tracks/State.elm @@ -4,6 +4,7 @@ import Alien import Common exposing (..) import ContextMenu import Coordinates exposing (Coordinates) +import Debouncer.Basic as Debouncer import Dict import Html.Events.Extra.Mouse as Mouse import InfiniteList @@ -623,14 +624,21 @@ setSearchResults json model = setSearchTerm : String -> Manager setSearchTerm term model = - User.saveEnclosedUserData - (case String.trim term of - "" -> - { model | searchTerm = Nothing } + (case String.trim term of + "" -> + { model | searchTerm = Nothing } - _ -> - { model | searchTerm = Just term } - ) + _ -> + { model | searchTerm = Just term } + ) + |> Return.communicate + (Search + |> TracksMsg + |> Debouncer.provideInput + |> SearchDebounce + |> Task.do + ) + |> Return.andThen User.saveEnclosedUserData showCoverMenu : Cover -> Coordinates -> Manager diff --git a/src/Applications/UI/Tracks/View.elm b/src/Applications/UI/Tracks/View.elm index 26f97051..35e86191 100644 --- a/src/Applications/UI/Tracks/View.elm +++ b/src/Applications/UI/Tracks/View.elm @@ -6,9 +6,8 @@ import Common exposing (Switch(..)) import Conditional exposing (ifThenElse) import Html exposing (Html, text) import Html.Attributes as A exposing (attribute, placeholder, style, tabindex, title, value) -import Html.Events as E exposing (onBlur, onClick, onInput) +import Html.Events as E exposing (onClick, onInput) import Html.Events.Extra.Mouse as Mouse -import Html.Ext exposing (onEnterKey) import Html.Lazy exposing (..) import Keyboard exposing (Key(..)) import Material.Icons.Round as Icons @@ -184,8 +183,6 @@ navigation { bgColor, favouritesOnly, grouping, isOnIndexPage, pressedShift, sce Html.input [ attribute "autocorrect" "off" , attribute "autocapitalize" "none" - , onBlur (TracksMsg Search) - , onEnterKey (TracksMsg Search) , onInput (TracksMsg << SetSearchTerm) , placeholder "Search" , tabindex tabindex_ diff --git a/src/Applications/UI/Types.elm b/src/Applications/UI/Types.elm index 9d3af297..1c9f3b6b 100644 --- a/src/Applications/UI/Types.elm +++ b/src/Applications/UI/Types.elm @@ -102,7 +102,8 @@ type alias Model = ----------------------------------------- -- Debouncing ----------------------------------------- - , debounce : Debouncer Msg Msg + , resizeDebouncer : Debouncer Msg Msg + , searchDebouncer : Debouncer Msg Msg ----------------------------------------- -- Equalizer @@ -227,7 +228,6 @@ type Msg | Blur | ContextMenuConfirmation String Msg | CopyToClipboard String - | Debounce (Debouncer.Msg Msg) | DismissNotification { id : Int } | DnD (DnD.Msg Int) | FocusedOnInput @@ -238,7 +238,9 @@ type Msg | RemoveNotification { id : Int } | RemoveQueueSelection | RemoveTrackSelection + | ResizeDebounce (Debouncer.Msg Msg) | ResizedWindow ( Int, Int ) + | SearchDebounce (Debouncer.Msg Msg) | ShowNotification (Notification Msg) | SetIsTouchDevice Bool | StoppedDragging diff --git a/src/Javascript/index.js b/src/Javascript/index.js index 9a48fe0e..1240b5ef 100644 --- a/src/Javascript/index.js +++ b/src/Javascript/index.js @@ -5,7 +5,9 @@ // and connect the other bits to it. +import "subworkers" import "tocca" + import loadScript from "load-script2" import JSZip from "jszip" import { saveAs } from "file-saver"