Wire up the search bar.

This commit is contained in:
Danila Fedorin 2019-05-19 13:42:22 -07:00
parent a4c40dca28
commit 3a31f98f3b
4 changed files with 18 additions and 2 deletions

View File

@ -53,6 +53,7 @@ init _ url key =
, transactionId = 0 , transactionId = 0
, userData = Dict.empty , userData = Dict.empty
, connected = True , connected = True
, searchText = ""
} }
cmd = getStoreValuePort "scylla.loginInfo" cmd = getStoreValuePort "scylla.loginInfo"
in in
@ -105,6 +106,7 @@ update msg model = case msg of
ReceiveMarkdown md -> updateMarkdown model md ReceiveMarkdown md -> updateMarkdown model md
DismissError i -> updateDismissError model i DismissError i -> updateDismissError model i
AttemptReconnect -> ({ model | connected = True }, firstSync model.apiUrl (Maybe.withDefault "" model.token)) AttemptReconnect -> ({ model | connected = True }, firstSync model.apiUrl (Maybe.withDefault "" model.token))
UpdateSearchText s -> ({ model | searchText = s }, Cmd.none)
requestScrollCmd : Cmd Msg requestScrollCmd : Cmd Msg
requestScrollCmd = Task.attempt ViewportAfterMessage (Browser.Dom.getViewportOf "messages-wrapper") requestScrollCmd = Task.attempt ViewportAfterMessage (Browser.Dom.getViewportOf "messages-wrapper")

View File

@ -32,6 +32,7 @@ type alias Model =
, transactionId : Int , transactionId : Int
, userData : Dict Username UserData , userData : Dict Username UserData
, connected : Bool , connected : Bool
, searchText : String
} }
type Msg = type Msg =
@ -68,6 +69,7 @@ type Msg =
| ReceiveMarkdown MarkdownResponse | ReceiveMarkdown MarkdownResponse
| DismissError Int | DismissError Int
| AttemptReconnect | AttemptReconnect
| UpdateSearchText String
displayName : Model -> Username -> String displayName : Model -> Username -> String
displayName m s = Maybe.withDefault (senderName s) <| Maybe.andThen .displayName <| Dict.get s m.userData displayName m s = Maybe.withDefault (senderName s) <| Maybe.andThen .displayName <| Dict.get s m.userData

View File

@ -91,7 +91,13 @@ roomListView m =
in in
div [ class "rooms-wrapper" ] div [ class "rooms-wrapper" ]
[ h2 [] [ text "Rooms" ] [ h2 [] [ text "Rooms" ]
, input [ class "room-search", type_ "text", placeholder "Search chats..." ] [] , input
[ class "room-search"
, type_ "text"
, placeholder "Search chats..."
, onInput UpdateSearchText
, value m.searchText
] []
, homeserverList , homeserverList
] ]
@ -111,6 +117,7 @@ roomListElementView : Model -> String -> JoinedRoom -> Html Msg
roomListElementView m s jr = roomListElementView m s jr =
let let
name = roomDisplayName m jr name = roomDisplayName m jr
isVisible = m.searchText == "" || (String.contains (String.toLower m.searchText) <| String.toLower name)
isCurrentRoom = case currentRoomId m of isCurrentRoom = case currentRoomId m of
Nothing -> False Nothing -> False
Just cr -> cr == s Just cr -> cr == s
@ -118,6 +125,7 @@ roomListElementView m s jr =
div [ classList div [ classList
[ ("room-link-wrapper", True) [ ("room-link-wrapper", True)
, ("active", isCurrentRoom) , ("active", isCurrentRoom)
, ("hidden", not isVisible)
] ]
] ]
[ a [ href <| roomUrl s ] [ text name ] [ a [ href <| roomUrl s ] [ text name ]

View File

@ -172,7 +172,7 @@ div.room-link-wrapper {
padding-left: 5px; padding-left: 5px;
margin: 3px; margin: 3px;
align-items: center; align-items: center;
span, a { span, a {
margin-right: 5px; margin-right: 5px;
color: lightgrey; color: lightgrey;
@ -186,6 +186,10 @@ div.room-link-wrapper {
&.active { &.active {
border-left: solid 2px $primary-color; border-left: solid 2px $primary-color;
} }
&.hidden {
display: none;
}
} }
div.reconnect-wrapper { div.reconnect-wrapper {