Skip to content

Commit

Permalink
when wrong channel is selected (via url) show error
Browse files Browse the repository at this point in the history
  • Loading branch information
garbas committed Sep 3, 2020
1 parent c12f4df commit 6940260
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 25 deletions.
6 changes: 5 additions & 1 deletion src/Main.elm
Expand Up @@ -117,7 +117,11 @@ submitQuery :
submitQuery old ( new, cmd ) =
let
triggerSearch _ newModel msg makeRequest =
if newModel.query /= Nothing && newModel.query /= Just "" then
if
(newModel.query /= Nothing)
&& (newModel.query /= Just "")
&& List.member newModel.channel Search.channels
then
( new
, Cmd.batch
[ cmd
Expand Down
65 changes: 41 additions & 24 deletions src/Search.elm
Expand Up @@ -6,6 +6,7 @@ module Search exposing
, SearchResult
, Sort(..)
, channelDetailsFromId
, channels
, decodeResult
, fromSortId
, init
Expand Down Expand Up @@ -463,31 +464,47 @@ view path title model viewSuccess outMsg =
[ form [ onSubmit (outMsg QueryInputSubmit) ]
[ p
[]
[ strong []
[ text "Channel: " ]
, div
[ class "btn-group"
, attribute "data-toggle" "buttons-radio"
]
(List.filterMap
(\channel_id ->
channelDetailsFromId channel_id
|> Maybe.map
(\channel ->
button
[ type_ "button"
, classList
[ ( "btn", True )
, ( "active", channel.id == model.channel )
]
, onClick <| outMsg (ChannelChange channel.id)
]
[ text channel.title ]
)
([]
|> List.append
(if List.member model.channel channels then
[]

else
[ p [ class "alert alert-error" ]
[ h4 [] [ text "Wrong channel selected!" ]
, text <| "Please select one of the channels above!"
]
]
)
channels
)
]
|> List.append
[ p []
[ strong []
[ text "Channel: " ]
, div
[ class "btn-group"
, attribute "data-toggle" "buttons-radio"
]
(List.filterMap
(\channel_id ->
channelDetailsFromId channel_id
|> Maybe.map
(\channel ->
button
[ type_ "button"
, classList
[ ( "btn", True )
, ( "active", channel.id == model.channel )
]
, onClick <| outMsg (ChannelChange channel.id)
]
[ text channel.title ]
)
)
channels
)
]
]
)
, p
[ class "input-append"
]
Expand Down

0 comments on commit 6940260

Please sign in to comment.