Create logged-out view for group chat invites (#10598)
Co-authored-by: Samuel Newman <mozzius@protonmail.com>
This commit is contained in:
@@ -9,6 +9,7 @@ import {PressableScale} from '#/lib/custom-animations/PressableScale'
|
||||
import {STALE} from '#/state/queries'
|
||||
import {profilesQueryKey} from '#/state/queries/profile'
|
||||
import {useAgent, useSession} from '#/state/session'
|
||||
import {useSetActiveLanding} from '#/state/shell/landing'
|
||||
import {
|
||||
useLoggedOutView,
|
||||
useLoggedOutViewControls,
|
||||
@@ -16,6 +17,7 @@ import {
|
||||
import {useEnableMinimalShellMode} from '#/state/shell/minimal-mode'
|
||||
import {ErrorBoundary} from '#/view/com/util/ErrorBoundary'
|
||||
import {Login} from '#/screens/Login'
|
||||
import {JoinRequest} from '#/screens/Messages/JoinRequest'
|
||||
import {Signup} from '#/screens/Signup'
|
||||
import {LandingScreen} from '#/screens/StarterPack/StarterPackLandingScreen'
|
||||
import {atoms as a, native, tokens, useTheme} from '#/alf'
|
||||
@@ -29,9 +31,26 @@ enum ScreenState {
|
||||
S_Login,
|
||||
S_CreateAccount,
|
||||
S_StarterPack,
|
||||
S_GroupChatJoinRequest,
|
||||
}
|
||||
export {ScreenState as LoggedOutScreenState}
|
||||
|
||||
function getInitialScreenState(requestedAccountSwitchTo?: string): ScreenState {
|
||||
switch (requestedAccountSwitchTo) {
|
||||
case 'new':
|
||||
return ScreenState.S_CreateAccount
|
||||
case 'starterpack':
|
||||
return ScreenState.S_StarterPack
|
||||
case 'groupchat':
|
||||
return ScreenState.S_GroupChatJoinRequest
|
||||
case undefined:
|
||||
return ScreenState.S_LoginOrCreateAccount
|
||||
default:
|
||||
// DID or other string = login with that account
|
||||
return ScreenState.S_Login
|
||||
}
|
||||
}
|
||||
|
||||
export function LoggedOut({onDismiss}: {onDismiss?: () => void}) {
|
||||
const {_} = useLingui()
|
||||
const ax = useAnalytics()
|
||||
@@ -39,18 +58,11 @@ export function LoggedOut({onDismiss}: {onDismiss?: () => void}) {
|
||||
const insets = useSafeAreaInsets()
|
||||
useEnableMinimalShellMode()
|
||||
const {requestedAccountSwitchTo} = useLoggedOutView()
|
||||
const [screenState, setScreenState] = useState<ScreenState>(() => {
|
||||
if (requestedAccountSwitchTo === 'new') {
|
||||
return ScreenState.S_CreateAccount
|
||||
} else if (requestedAccountSwitchTo === 'starterpack') {
|
||||
return ScreenState.S_StarterPack
|
||||
} else if (requestedAccountSwitchTo != null) {
|
||||
return ScreenState.S_Login
|
||||
} else {
|
||||
return ScreenState.S_LoginOrCreateAccount
|
||||
}
|
||||
})
|
||||
const initialScreenState = getInitialScreenState(requestedAccountSwitchTo)
|
||||
const [screenState, setScreenState] =
|
||||
useState<ScreenState>(initialScreenState)
|
||||
const {clearRequestedAccount} = useLoggedOutViewControls()
|
||||
const setActiveLanding = useSetActiveLanding()
|
||||
|
||||
const queryClient = useQueryClient()
|
||||
const {accounts} = useSession()
|
||||
@@ -73,7 +85,9 @@ export function LoggedOut({onDismiss}: {onDismiss?: () => void}) {
|
||||
onDismiss()
|
||||
}
|
||||
clearRequestedAccount()
|
||||
}, [clearRequestedAccount, onDismiss])
|
||||
// Clear landing context when user dismisses the modal
|
||||
setActiveLanding(undefined)
|
||||
}, [clearRequestedAccount, onDismiss, setActiveLanding])
|
||||
|
||||
return (
|
||||
<View
|
||||
@@ -107,6 +121,8 @@ export function LoggedOut({onDismiss}: {onDismiss?: () => void}) {
|
||||
|
||||
{screenState === ScreenState.S_StarterPack ? (
|
||||
<LandingScreen setScreenState={setScreenState} />
|
||||
) : screenState === ScreenState.S_GroupChatJoinRequest ? (
|
||||
<JoinRequest setScreenState={setScreenState} />
|
||||
) : screenState === ScreenState.S_LoginOrCreateAccount ? (
|
||||
<SplashScreen
|
||||
onPressSignin={() => {
|
||||
@@ -122,17 +138,12 @@ export function LoggedOut({onDismiss}: {onDismiss?: () => void}) {
|
||||
{screenState === ScreenState.S_Login ? (
|
||||
<Login
|
||||
onPressBack={() => {
|
||||
setScreenState(ScreenState.S_LoginOrCreateAccount)
|
||||
clearRequestedAccount()
|
||||
setScreenState(initialScreenState)
|
||||
}}
|
||||
/>
|
||||
) : undefined}
|
||||
{screenState === ScreenState.S_CreateAccount ? (
|
||||
<Signup
|
||||
onPressBack={() =>
|
||||
setScreenState(ScreenState.S_LoginOrCreateAccount)
|
||||
}
|
||||
/>
|
||||
<Signup onPressBack={() => setScreenState(initialScreenState)} />
|
||||
) : undefined}
|
||||
</ErrorBoundary>
|
||||
</View>
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
import {sanitizeUrl} from '@braintree/sanitize-url'
|
||||
import {StackActions} from '@react-navigation/native'
|
||||
|
||||
import {useGroupChatJoinIntent} from '#/lib/hooks/useIntentHandler'
|
||||
import {
|
||||
type DebouncedNavigationProp,
|
||||
useNavigationDeduped,
|
||||
@@ -21,6 +22,7 @@ import {useOpenLink} from '#/lib/hooks/useOpenLink'
|
||||
import {getTabState, TabState} from '#/lib/routes/helpers'
|
||||
import {
|
||||
convertBskyAppUrlIfNeeded,
|
||||
getChatInviteCodeFromUrl,
|
||||
isExternalUrl,
|
||||
linkRequiresWarning,
|
||||
} from '#/lib/strings/url-helpers'
|
||||
@@ -81,6 +83,7 @@ export const Link = memo(function Link({
|
||||
const navigation = useNavigationDeduped()
|
||||
const anchorHref = asAnchor ? sanitizeUrl(href) : undefined
|
||||
const openLink = useOpenLink()
|
||||
const groupChatJoinIntent = useGroupChatJoinIntent()
|
||||
|
||||
const onPress = useCallback(
|
||||
(e?: Event) => {
|
||||
@@ -92,11 +95,20 @@ export const Link = memo(function Link({
|
||||
sanitizeUrl(href),
|
||||
navigationAction,
|
||||
openLink,
|
||||
groupChatJoinIntent,
|
||||
e,
|
||||
)
|
||||
}
|
||||
},
|
||||
[closeModal, navigation, navigationAction, href, openLink, onBeforePress],
|
||||
[
|
||||
closeModal,
|
||||
navigation,
|
||||
navigationAction,
|
||||
href,
|
||||
openLink,
|
||||
onBeforePress,
|
||||
groupChatJoinIntent,
|
||||
],
|
||||
)
|
||||
|
||||
const accessibilityActionsWithActivate = [
|
||||
@@ -196,6 +208,7 @@ export const TextLink = memo(function TextLink({
|
||||
const {closeModal} = useModalControls()
|
||||
const {linkWarningDialogControl} = useGlobalDialogsControlContext()
|
||||
const openLink = useOpenLink()
|
||||
const groupChatJoinIntent = useGroupChatJoinIntent()
|
||||
|
||||
if (!disableMismatchWarning && typeof text !== 'string') {
|
||||
console.error('Unable to detect mismatching label')
|
||||
@@ -238,6 +251,7 @@ export const TextLink = memo(function TextLink({
|
||||
sanitizeUrl(href),
|
||||
navigationAction,
|
||||
openLink,
|
||||
groupChatJoinIntent,
|
||||
e,
|
||||
)
|
||||
},
|
||||
@@ -252,6 +266,7 @@ export const TextLink = memo(function TextLink({
|
||||
navigationAction,
|
||||
openLink,
|
||||
linkWarningDialogControl,
|
||||
groupChatJoinIntent,
|
||||
],
|
||||
)
|
||||
const hrefAttrs = useMemo(() => {
|
||||
@@ -373,6 +388,7 @@ function onPressInner(
|
||||
href: string,
|
||||
navigationAction: 'push' | 'replace' | 'navigate' = 'push',
|
||||
openLink: (href: string) => void,
|
||||
groupChatJoinIntent: (code: string, uri?: string) => void,
|
||||
e?: Event,
|
||||
) {
|
||||
let shouldHandle = false
|
||||
@@ -400,6 +416,11 @@ function onPressInner(
|
||||
|
||||
if (shouldHandle) {
|
||||
href = convertBskyAppUrlIfNeeded(href)
|
||||
const chatInviteCode = getChatInviteCodeFromUrl(href)
|
||||
if (chatInviteCode) {
|
||||
groupChatJoinIntent(chatInviteCode, href)
|
||||
return
|
||||
}
|
||||
if (
|
||||
newTab ||
|
||||
href.startsWith('http') ||
|
||||
|
||||
Reference in New Issue
Block a user