fix: suppress site chat on mobile
This commit is contained in:
parent
8184149c3f
commit
726c4877c6
1 changed files with 19 additions and 1 deletions
|
|
@ -64,6 +64,7 @@ const CHAT_UNAVAILABLE_MESSAGE = "Jessica is temporarily unavailable right now.
|
|||
const SESSION_STORAGE_KEY = "rmv-site-chat-session"
|
||||
const PROFILE_STORAGE_KEY = "rmv-site-chat-profile"
|
||||
const PANEL_MAX_HEIGHT = "min(40rem, calc(100vh - 7rem))"
|
||||
const MOBILE_CHAT_MEDIA_QUERY = "(max-width: 767px)"
|
||||
|
||||
function createMessage(role: ChatRole, content: string): ChatMessage {
|
||||
return {
|
||||
|
|
@ -197,7 +198,7 @@ export function SiteChatWidget() {
|
|||
() => CHAT_INTENT_OPTIONS.map((option) => ({ label: option, value: option })),
|
||||
[],
|
||||
)
|
||||
const isSuppressed = isSiteChatSuppressedRoute(pathname)
|
||||
const [isMobileViewport, setIsMobileViewport] = useState(false)
|
||||
const [isOpen, setIsOpen] = useState(false)
|
||||
const [messages, setMessages] = useState<ChatMessage[]>([])
|
||||
const [draft, setDraft] = useState("")
|
||||
|
|
@ -210,6 +211,23 @@ export function SiteChatWidget() {
|
|||
const [, setLimits] = useState<ChatLimitStatus | null>(null)
|
||||
const messagesEndRef = useRef<HTMLDivElement | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
const mediaQuery = window.matchMedia(MOBILE_CHAT_MEDIA_QUERY)
|
||||
const handleViewportChange = () => setIsMobileViewport(mediaQuery.matches)
|
||||
|
||||
handleViewportChange()
|
||||
|
||||
if (typeof mediaQuery.addEventListener === "function") {
|
||||
mediaQuery.addEventListener("change", handleViewportChange)
|
||||
return () => mediaQuery.removeEventListener("change", handleViewportChange)
|
||||
}
|
||||
|
||||
mediaQuery.addListener(handleViewportChange)
|
||||
return () => mediaQuery.removeListener(handleViewportChange)
|
||||
}, [])
|
||||
|
||||
const isSuppressed = isSiteChatSuppressedRoute(pathname) || isMobileViewport
|
||||
|
||||
useEffect(() => {
|
||||
const storedSessionId = window.localStorage.getItem(SESSION_STORAGE_KEY)
|
||||
if (storedSessionId) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue