- realtime.ts: the page's one Centrifuge client, setRealtimeAuth, onUserEvent for user:{me} events the chat does not handle
- chatEvents, chatFormat, chatText, chatUnread, format, media, tabs ported; copy passed in localized
- useChat over useState: channels with join and leave, DMs, member list, unread and mention counts, read marks, typing, presence, polling fallback
- ChatPanel, ChatHeader, ChatMessage, ChatDmList, ChatMemberPicker, ChatMentionPopup, ChatAvatar, ChatIcon, ChatNotices
- EN and PL strings
21 lines
819 B
TypeScript
21 lines
819 B
TypeScript
import { getCurrentScope, onScopeDispose, ref, type Ref } from 'vue'
|
|
|
|
/** A reactive matchMedia; false where matchMedia does not exist (tests, SSR). */
|
|
export function useMediaQuery(query: string): Ref<boolean> {
|
|
const matches = ref(false)
|
|
if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') return matches
|
|
const mql = window.matchMedia(query)
|
|
matches.value = mql.matches
|
|
const update = (e: MediaQueryListEvent) => {
|
|
matches.value = e.matches
|
|
}
|
|
mql.addEventListener('change', update)
|
|
if (getCurrentScope()) onScopeDispose(() => mql.removeEventListener('change', update))
|
|
return matches
|
|
}
|
|
|
|
/** True at and above a viewport width (the CSS `min-width` breakpoints). */
|
|
export function useMinWidth(px: number): Ref<boolean> {
|
|
return useMediaQuery(`(min-width: ${px}px)`)
|
|
}
|