diff options
author | Samuel Newman <mozzius@protonmail.com> | 2025-04-25 00:41:11 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-24 16:41:11 -0500 |
commit | 8ec8a644727cd59ba475bb221fedbd51e7d93e7e (patch) | |
tree | cebbdde92bfc056577653053636fd53e0f21fc39 /src/lib/hooks/useOpenLink.ts | |
parent | 69f656f28300a6a33526020725c61cac78501cb0 (diff) | |
download | voidsky-8ec8a644727cd59ba475bb221fedbd51e7d93e7e.tar.zst |
Modernize in-app browser consent dialog (#8191)
* add stateful dialog control hook * add new alf'd consent * make secondary_inverted buttons clearer * contingency for opening a link from another dialog * rm old modal * Differentiate buttons more --------- Co-authored-by: Eric Bailey <git@esb.lol>
Diffstat (limited to 'src/lib/hooks/useOpenLink.ts')
-rw-r--r-- | src/lib/hooks/useOpenLink.ts | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/lib/hooks/useOpenLink.ts b/src/lib/hooks/useOpenLink.ts index a949dacc6..28c1bca3d 100644 --- a/src/lib/hooks/useOpenLink.ts +++ b/src/lib/hooks/useOpenLink.ts @@ -12,16 +12,18 @@ import { toNiceDomain, } from '#/lib/strings/url-helpers' import {isNative} from '#/platform/detection' -import {useModalControls} from '#/state/modals' import {useInAppBrowser} from '#/state/preferences/in-app-browser' import {useTheme} from '#/alf' +import {useDialogContext} from '#/components/Dialog' import {useSheetWrapper} from '#/components/Dialog/sheet-wrapper' +import {useGlobalDialogsControlContext} from '#/components/dialogs/Context' export function useOpenLink() { - const {openModal} = useModalControls() const enabled = useInAppBrowser() const t = useTheme() const sheetWrapper = useSheetWrapper() + const dialogContext = useDialogContext() + const {inAppBrowserConsentControl} = useGlobalDialogsControlContext() const openLink = useCallback( async (url: string, override?: boolean, shouldProxy?: boolean) => { @@ -42,10 +44,17 @@ export function useOpenLink() { if (isNative && !url.startsWith('mailto:')) { if (override === undefined && enabled === undefined) { - openModal({ - name: 'in-app-browser-consent', - href: url, - }) + // consent dialog is a global dialog, and while it's possible to nest dialogs, + // the actual components need to be nested. sibling dialogs on iOS are not supported. + // thus, check if we're in a dialog, and if so, close the existing dialog before opening the + // consent dialog -sfn + if (dialogContext.isWithinDialog) { + dialogContext.close(() => { + inAppBrowserConsentControl.open(url) + }) + } else { + inAppBrowserConsentControl.open(url) + } return } else if (override ?? enabled) { await sheetWrapper( @@ -62,7 +71,7 @@ export function useOpenLink() { } Linking.openURL(url) }, - [enabled, openModal, t, sheetWrapper], + [enabled, inAppBrowserConsentControl, t, sheetWrapper, dialogContext], ) return openLink |