Skip to content

Instantly share code, notes, and snippets.

@cschneid
Created January 23, 2017 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save cschneid/da2a04415b85b9ca5b1773e08a82eed8 to your computer and use it in GitHub Desktop.
Save cschneid/da2a04415b85b9ca5b1773e08a82eed8 to your computer and use it in GitHub Desktop.
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
Noop ->
( model, Cmd.none )
UpdateTitleFilter titleSearch ->
let
newFilters =
createFilters titleSearch model.currentDescriptionSearchField model.currentFilteredTags
newModel =
{ model | filters = newFilters, currentTitleSearchField = titleSearch }
in
( newModel, Cmd.none )
UpdateDescriptionFilter descSearch ->
let
newFilters =
createFilters model.currentTitleSearchField descSearch model.currentFilteredTags
newModel =
{ model | filters = newFilters, currentDescriptionSearchField = descSearch }
in
( newModel, Cmd.none )
UpdateTagFilter tagSearch ->
let
newModel =
{ model | currentTagSearchField = tagSearch }
in
( newModel, Cmd.none )
SubmitTagFilter ->
let
newTags =
model.currentTagSearchField :: model.currentFilteredTags
newFilters =
createFilters model.currentTitleSearchField model.currentDescriptionSearchField newTags
newModel =
{ model | currentFilteredTags = newTags, filters = newFilters }
in
( newModel, Cmd.none )
AddTagFilter tag ->
let
newTags =
tag :: model.currentFilteredTags
newFilters =
createFilters model.currentTitleSearchField model.currentDescriptionSearchField newTags
newModel =
{ model | currentFilteredTags = newTags, filters = newFilters }
in
( newModel, Cmd.none )
RemoveTagFilter tag ->
let
newTags =
List.filter (\t -> t /= tag) model.currentFilteredTags
newFilters =
createFilters model.currentTitleSearchField model.currentDescriptionSearchField newTags
newModel =
{ model | currentFilteredTags = newTags, filters = newFilters }
in
( newModel, Cmd.none )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment