Make naming more clear
This commit is contained in:
@@ -15,7 +15,7 @@ import {useGate} from '#/lib/statsig/statsig'
|
||||
import {useCurrentConvoId} from '#/state/messages/current-convo-id'
|
||||
import {BACK_HITSLOP} from 'lib/constants'
|
||||
import {isIOS, isWeb} from 'platform/detection'
|
||||
import {ConvoProvider, isConvoReady, useConvo} from 'state/messages/convo'
|
||||
import {ConvoProvider, isConvoActive, useConvo} from 'state/messages/convo'
|
||||
import {ConvoStatus} from 'state/messages/convo/types'
|
||||
import {PreviewableUserAvatar} from 'view/com/util/UserAvatar'
|
||||
import {CenteredView} from 'view/com/util/Views'
|
||||
@@ -72,7 +72,7 @@ function Inner() {
|
||||
React.useEffect(() => {
|
||||
if (
|
||||
!hasInitiallyRendered &&
|
||||
isConvoReady(convoState) &&
|
||||
isConvoActive(convoState) &&
|
||||
!convoState.isFetchingHistory
|
||||
) {
|
||||
setTimeout(() => {
|
||||
@@ -108,7 +108,7 @@ function Inner() {
|
||||
<CenteredView style={a.flex_1} sideBorders>
|
||||
<Header profile={convoState.recipients?.[0]} />
|
||||
<View style={[a.flex_1]}>
|
||||
{isConvoReady(convoState) ? (
|
||||
{isConvoActive(convoState) ? (
|
||||
<MessagesList />
|
||||
) : (
|
||||
<ListMaybePlaceholder isLoading />
|
||||
@@ -230,7 +230,7 @@ let Header = ({
|
||||
</>
|
||||
)}
|
||||
</View>
|
||||
{isConvoReady(convoState) && profile ? (
|
||||
{isConvoActive(convoState) && profile ? (
|
||||
<ConvoMenu
|
||||
convo={convoState.convo}
|
||||
profile={profile}
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
ConvoState,
|
||||
ConvoStatus,
|
||||
} from '#/state/messages/convo/types'
|
||||
import {isConvoReady} from '#/state/messages/convo/util'
|
||||
import {isConvoActive} from '#/state/messages/convo/util'
|
||||
import {useMessagesEventBus} from '#/state/messages/events'
|
||||
import {useMarkAsReadMutation} from '#/state/queries/messages/conversation'
|
||||
import {useAgent} from '#/state/session'
|
||||
@@ -25,6 +25,11 @@ export function useConvo() {
|
||||
return ctx
|
||||
}
|
||||
|
||||
/**
|
||||
* This hook should only be used when the Convo is "active", meaning the chat
|
||||
* is loaded and ready to be used, or its in a suspended or background state,
|
||||
* and ready for resumption.
|
||||
*/
|
||||
export function useConvoActive() {
|
||||
const ctx = useContext(ChatContext) as ConvoState & {
|
||||
status: ConvoStatus.Ready | ConvoStatus.Backgrounded | ConvoStatus.Suspended
|
||||
@@ -32,7 +37,7 @@ export function useConvoActive() {
|
||||
if (!ctx) {
|
||||
throw new Error('useConvo must be used within a ConvoProvider')
|
||||
}
|
||||
if (!isConvoReady(ctx)) {
|
||||
if (!isConvoActive(ctx)) {
|
||||
throw new Error(
|
||||
`useConvoActive must only be rendered when the Convo is ready. Current status: ${ctx.status}`,
|
||||
)
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import {ConvoState, ConvoStatus} from './types'
|
||||
|
||||
export function isConvoReady(convo: ConvoState) {
|
||||
/**
|
||||
* Checks if a `Convo` has a `status` that is "active", meaning the chat is
|
||||
* loaded and ready to be used, or its in a suspended or background state, and
|
||||
* ready for resumption.
|
||||
*/
|
||||
export function isConvoActive(convo: ConvoState) {
|
||||
return (
|
||||
convo.status === ConvoStatus.Ready ||
|
||||
convo.status === ConvoStatus.Backgrounded ||
|
||||
|
||||
Reference in New Issue
Block a user