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 {useCurrentConvoId} from '#/state/messages/current-convo-id'
|
||||||
import {BACK_HITSLOP} from 'lib/constants'
|
import {BACK_HITSLOP} from 'lib/constants'
|
||||||
import {isIOS, isWeb} from 'platform/detection'
|
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 {ConvoStatus} from 'state/messages/convo/types'
|
||||||
import {PreviewableUserAvatar} from 'view/com/util/UserAvatar'
|
import {PreviewableUserAvatar} from 'view/com/util/UserAvatar'
|
||||||
import {CenteredView} from 'view/com/util/Views'
|
import {CenteredView} from 'view/com/util/Views'
|
||||||
@@ -72,7 +72,7 @@ function Inner() {
|
|||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (
|
if (
|
||||||
!hasInitiallyRendered &&
|
!hasInitiallyRendered &&
|
||||||
isConvoReady(convoState) &&
|
isConvoActive(convoState) &&
|
||||||
!convoState.isFetchingHistory
|
!convoState.isFetchingHistory
|
||||||
) {
|
) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@@ -108,7 +108,7 @@ function Inner() {
|
|||||||
<CenteredView style={a.flex_1} sideBorders>
|
<CenteredView style={a.flex_1} sideBorders>
|
||||||
<Header profile={convoState.recipients?.[0]} />
|
<Header profile={convoState.recipients?.[0]} />
|
||||||
<View style={[a.flex_1]}>
|
<View style={[a.flex_1]}>
|
||||||
{isConvoReady(convoState) ? (
|
{isConvoActive(convoState) ? (
|
||||||
<MessagesList />
|
<MessagesList />
|
||||||
) : (
|
) : (
|
||||||
<ListMaybePlaceholder isLoading />
|
<ListMaybePlaceholder isLoading />
|
||||||
@@ -230,7 +230,7 @@ let Header = ({
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</View>
|
</View>
|
||||||
{isConvoReady(convoState) && profile ? (
|
{isConvoActive(convoState) && profile ? (
|
||||||
<ConvoMenu
|
<ConvoMenu
|
||||||
convo={convoState.convo}
|
convo={convoState.convo}
|
||||||
profile={profile}
|
profile={profile}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
ConvoState,
|
ConvoState,
|
||||||
ConvoStatus,
|
ConvoStatus,
|
||||||
} from '#/state/messages/convo/types'
|
} 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 {useMessagesEventBus} from '#/state/messages/events'
|
||||||
import {useMarkAsReadMutation} from '#/state/queries/messages/conversation'
|
import {useMarkAsReadMutation} from '#/state/queries/messages/conversation'
|
||||||
import {useAgent} from '#/state/session'
|
import {useAgent} from '#/state/session'
|
||||||
@@ -25,6 +25,11 @@ export function useConvo() {
|
|||||||
return ctx
|
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() {
|
export function useConvoActive() {
|
||||||
const ctx = useContext(ChatContext) as ConvoState & {
|
const ctx = useContext(ChatContext) as ConvoState & {
|
||||||
status: ConvoStatus.Ready | ConvoStatus.Backgrounded | ConvoStatus.Suspended
|
status: ConvoStatus.Ready | ConvoStatus.Backgrounded | ConvoStatus.Suspended
|
||||||
@@ -32,7 +37,7 @@ export function useConvoActive() {
|
|||||||
if (!ctx) {
|
if (!ctx) {
|
||||||
throw new Error('useConvo must be used within a ConvoProvider')
|
throw new Error('useConvo must be used within a ConvoProvider')
|
||||||
}
|
}
|
||||||
if (!isConvoReady(ctx)) {
|
if (!isConvoActive(ctx)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`useConvoActive must only be rendered when the Convo is ready. Current status: ${ctx.status}`,
|
`useConvoActive must only be rendered when the Convo is ready. Current status: ${ctx.status}`,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
import {ConvoState, ConvoStatus} from './types'
|
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 (
|
return (
|
||||||
convo.status === ConvoStatus.Ready ||
|
convo.status === ConvoStatus.Ready ||
|
||||||
convo.status === ConvoStatus.Backgrounded ||
|
convo.status === ConvoStatus.Backgrounded ||
|
||||||
|
|||||||
Reference in New Issue
Block a user