@@ -2,9 +2,10 @@ module Main where
22
33import Prelude
44
5−import Data.Array (snoc, mapWithIndex, length)
5+import Data.Array (snoc, mapWithIndex, length, filter, null)
66import Data.Nullable (toNullable)
77import Data.Maybe (Maybe(..))
8+import Data.String (contains, Pattern(..))
89import Effect (Effect)
910import React.Basic (JSX)
1011import React.Basic.Events (EventHandler, handler, handler_, unsafeEventFn)
@@ -630,6 +631,10 @@ chatTab = component "ChatTab" \p -> React.do
630631 setInputText ""
631632 sendSticker stickerName = do
632633 setMessages (snoc messages { sender: "You", body: stickerName, isSticker: true })
634+ setInputText ""
635+ allStickers = [ "cat_following_mouse", "rating_animation", "switch_event_example", "windy_tree" ]
636+ query = colonQuery inputText
637+ matchingStickers = if query == "" then [] else filter (contains (Pattern query)) allStickers
633638 sentBubbleBg = if p.isDark then "#0A84FF" else "#007AFF"
634639 receivedBubbleBg = p.cardBg
635640 sidebar = view { style: tw "pt-2" }
@@ -727,6 +732,31 @@ chatTab = component "ChatTab" \p -> React.do
727732 , style: Style.style { position: "absolute", top: 0.0, left: 0.0, right: 0.0, bottom: 0.0, opacity: 0.0 }
728733 }
729734 ]
735+ stickerPicker stickers = view
736+ { style: tw "flex-row px-3 py-2"
737+ <> Style.style { backgroundColor: p.cardBg, borderTopWidth: 0.5, borderColor: p.dimFg }
738+ }
739+ ( stickers <#> \name ->
740+ view
741+ { style: tw "mr-2 rounded-lg overflow-hidden items-center"
742+ <> Style.style { backgroundColor: if p.isDark then "#3A3A3A" else "#E0E0E0" }
743+ }
744+ [ nativeRiveView_
745+ { resourceName: name
746+ , fit: "contain"
747+ , autoplay: true
748+ , style: Style.style { width: 56.0, height: 56.0 }
749+ }
750+ , text { style: tw "text-xs pb-1" <> Style.style { color: p.dimFg } } (":" <> name)
751+ , nativeButton
752+ { title: ""
753+ , bezelStyle: "toolbar"
754+ , sfSymbol: ""
755+ , onPress: handler_ (sendSticker name)
756+ , style: Style.style { position: "absolute", top: 0.0, left: 0.0, right: 0.0, bottom: 0.0, opacity: 0.0 }
757+ }
758+ ]
759+ )
730760 pure do
731761 sidebarLayout
732762 { sidebar
@@ -741,7 +771,8 @@ chatTab = component "ChatTab" \p -> React.do
741771 ( view { style: tw "py-2" }
742772 (mapWithIndex messageBubble messages)
743773 )
744− , stickerBar
774+ , if null matchingStickers then stickerBar
775+ else stickerPicker matchingStickers
745776 , view
746777 { style: tw "flex-row items-center px-3 py-2"
747778 <> Style.style { borderTopWidth: 0.5, borderColor: p.dimFg, backgroundColor: "transparent" }
@@ -786,3 +817,4 @@ round n = unsafeRound n
786817foreign import unsafeRound :: Number -> Int
787818foreign import getFieldJSON :: String -> forall r. r -> String
788819foreign import isSingleEmoji :: String -> Boolean
820+foreign import colonQuery :: String -> String