From ed475f6849cb8657f6f75b34ad3125012caaec9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Pacana?= Date: Thu, 21 Mar 2024 17:32:10 +0100 Subject: [PATCH] Move navigation out of Stream Co-authored-by: Szymon Fiedler --- ruby_event_store-browser/elm/src/Layout.elm | 17 +++++++----- ruby_event_store-browser/elm/src/Search.elm | 30 +++++++++++---------- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Layout.elm b/ruby_event_store-browser/elm/src/Layout.elm index 5aeeae4b68..a428f3a47e 100644 --- a/ruby_event_store-browser/elm/src/Layout.elm +++ b/ruby_event_store-browser/elm/src/Layout.elm @@ -72,18 +72,23 @@ update : Msg -> WrappedModel Model -> ( WrappedModel Model, Cmd Msg ) update msg model = case msg of SearchMsg searchMsg -> - let - ( newSearch, cmd ) = - Search.update searchMsg model.internal.search (goToStream model) - in case searchMsg of - OnSelect _ -> - ( { model | internal = Model newSearch }, toggleDialog searchModalId ) + OnSelect streamName -> + ( model + , Cmd.batch + [ toggleDialog searchModalId + , goToStream model streamName + ] + ) OnQueryChanged streamName -> ( model, searchStreams model.flags streamName ) _ -> + let + ( newSearch, cmd ) = + Search.update searchMsg model.internal.search + in ( { model | internal = Model newSearch }, Cmd.map SearchMsg cmd ) TimeZoneSelected zoneName -> diff --git a/ruby_event_store-browser/elm/src/Search.elm b/ruby_event_store-browser/elm/src/Search.elm index 75a4fab198..0569f651f4 100644 --- a/ruby_event_store-browser/elm/src/Search.elm +++ b/ruby_event_store-browser/elm/src/Search.elm @@ -27,10 +27,18 @@ type Msg | OnQueryChanged Stream +globalStreamName = + "all" + + +emptyStreamName = + "" + + init : Model init = - { streams = [ "all" ] - , value = "" + { streams = [ globalStreamName ] + , value = emptyStreamName } @@ -49,16 +57,13 @@ isExactStream stream streams = List.any (\s -> s == stream) streams -update : Msg -> Model -> (String -> Cmd Msg) -> ( Model, Cmd Msg ) -update msg model onSubmit = +update : Msg -> Model -> ( Model, Cmd Msg ) +update msg model = case msg of StreamChanged stream -> if isExactStream stream model.streams then - ( { model | value = "" } - , Cmd.batch - [ onSubmit stream - , hackWithInternalOnSelectMsg stream - ] + ( { model | value = emptyStreamName } + , hackWithInternalOnSelectMsg stream ) else @@ -67,11 +72,8 @@ update msg model onSubmit = ) GoToStream stream -> - ( { model | value = "" } - , Cmd.batch - [ onSubmit stream - , hackWithInternalOnSelectMsg stream - ] + ( { model | value = emptyStreamName } + , hackWithInternalOnSelectMsg stream ) OnSelect _ ->