Skip to content

Commit

Permalink
Move navigation out of Stream
Browse files Browse the repository at this point in the history
Co-authored-by: Szymon Fiedler <[email protected]>
  • Loading branch information
mostlyobvious and fidel committed Mar 21, 2024
1 parent 9cc6e71 commit ed475f6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
17 changes: 11 additions & 6 deletions ruby_event_store-browser/elm/src/Layout.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
30 changes: 16 additions & 14 deletions ruby_event_store-browser/elm/src/Search.elm
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,18 @@ type Msg
| OnQueryChanged Stream


globalStreamName =
"all"


emptyStreamName =
""


init : Model
init =
{ streams = [ "all" ]
, value = ""
{ streams = [ globalStreamName ]
, value = emptyStreamName
}


Expand All @@ -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
Expand All @@ -67,11 +72,8 @@ update msg model onSubmit =
)

GoToStream stream ->
( { model | value = "" }
, Cmd.batch
[ onSubmit stream
, hackWithInternalOnSelectMsg stream
]
( { model | value = emptyStreamName }
, hackWithInternalOnSelectMsg stream
)

OnSelect _ ->
Expand Down

0 comments on commit ed475f6

Please sign in to comment.