mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-01 01:29:31 +08:00
fix(core): open-in-app page crash (#8995)
fix AF-1839 should not render `Link` in open-in-app component
This commit is contained in:
@@ -1,10 +1,11 @@
|
|||||||
|
import { useNavigateHelper } from '@affine/core/components/hooks/use-navigate-helper';
|
||||||
import { GraphQLService } from '@affine/core/modules/cloud';
|
import { GraphQLService } from '@affine/core/modules/cloud';
|
||||||
import { OpenInAppPage } from '@affine/core/modules/open-in-app/views/open-in-app-page';
|
import { OpenInAppPage } from '@affine/core/modules/open-in-app/views/open-in-app-page';
|
||||||
import { appSchemes, channelToScheme } from '@affine/core/utils/channel';
|
import { appSchemes, channelToScheme } from '@affine/core/utils/channel';
|
||||||
import type { GetCurrentUserQuery } from '@affine/graphql';
|
import type { GetCurrentUserQuery } from '@affine/graphql';
|
||||||
import { getCurrentUserQuery } from '@affine/graphql';
|
import { getCurrentUserQuery } from '@affine/graphql';
|
||||||
import { useService } from '@toeverything/infra';
|
import { useService } from '@toeverything/infra';
|
||||||
import { useEffect, useState } from 'react';
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
import { useParams, useSearchParams } from 'react-router-dom';
|
import { useParams, useSearchParams } from 'react-router-dom';
|
||||||
|
|
||||||
import { AppContainer } from '../../components/app-container';
|
import { AppContainer } from '../../components/app-container';
|
||||||
@@ -12,6 +13,15 @@ import { AppContainer } from '../../components/app-container';
|
|||||||
const OpenUrl = () => {
|
const OpenUrl = () => {
|
||||||
const [params] = useSearchParams();
|
const [params] = useSearchParams();
|
||||||
const urlToOpen = params.get('url');
|
const urlToOpen = params.get('url');
|
||||||
|
const navigateHelper = useNavigateHelper();
|
||||||
|
|
||||||
|
const onOpenHere = useCallback(
|
||||||
|
(e: React.MouseEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
navigateHelper.jumpToIndex();
|
||||||
|
},
|
||||||
|
[navigateHelper]
|
||||||
|
);
|
||||||
|
|
||||||
if (!urlToOpen) {
|
if (!urlToOpen) {
|
||||||
return null;
|
return null;
|
||||||
@@ -25,7 +35,9 @@ const OpenUrl = () => {
|
|||||||
urlObj.searchParams.set(k, v);
|
urlObj.searchParams.set(k, v);
|
||||||
});
|
});
|
||||||
|
|
||||||
return <OpenInAppPage urlToOpen={urlObj.toString()} />;
|
return (
|
||||||
|
<OpenInAppPage urlToOpen={urlObj.toString()} openHereClicked={onOpenHere} />
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ const WebOpenInAppGuard = ({ children }: { children: React.ReactNode }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return shouldOpenInApp && !environment.isMobile ? (
|
return shouldOpenInApp && !environment.isMobile ? (
|
||||||
<OpenInAppPage openHereClicked={onOpenHere} />
|
<OpenInAppPage openHereClicked={onOpenHere} mode="open-doc" />
|
||||||
) : (
|
) : (
|
||||||
children
|
children
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
import { Button } from '@affine/component/ui/button';
|
import { Button } from '@affine/component/ui/button';
|
||||||
import { resolveLinkToDoc } from '@affine/core/modules/navigation';
|
|
||||||
import { appIconMap, appNames } from '@affine/core/utils/channel';
|
import { appIconMap, appNames } from '@affine/core/utils/channel';
|
||||||
import { Trans, useI18n } from '@affine/i18n';
|
import { Trans, useI18n } from '@affine/i18n';
|
||||||
import { LocalWorkspaceIcon, Logo1Icon } from '@blocksuite/icons/rc';
|
import { LocalWorkspaceIcon, Logo1Icon } from '@blocksuite/icons/rc';
|
||||||
import { useService } from '@toeverything/infra';
|
import { useService } from '@toeverything/infra';
|
||||||
import type { MouseEvent } from 'react';
|
import type { MouseEvent } from 'react';
|
||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
import { Link } from 'react-router-dom';
|
|
||||||
|
|
||||||
import { GlobalDialogService } from '../../dialogs';
|
import { GlobalDialogService } from '../../dialogs';
|
||||||
import { getOpenUrlInDesktopAppLink } from '../utils';
|
import { getOpenUrlInDesktopAppLink } from '../utils';
|
||||||
@@ -17,12 +15,17 @@ let lastOpened = '';
|
|||||||
interface OpenAppProps {
|
interface OpenAppProps {
|
||||||
urlToOpen?: string | null;
|
urlToOpen?: string | null;
|
||||||
openHereClicked?: (e: MouseEvent) => void;
|
openHereClicked?: (e: MouseEvent) => void;
|
||||||
|
mode?: 'auth' | 'open-doc'; // default to 'auth'
|
||||||
}
|
}
|
||||||
const channel = BUILD_CONFIG.appBuildType;
|
const channel = BUILD_CONFIG.appBuildType;
|
||||||
const url =
|
const url =
|
||||||
'https://affine.pro/download' + (channel !== 'stable' ? '/beta-canary' : '');
|
'https://affine.pro/download' + (channel !== 'stable' ? '/beta-canary' : '');
|
||||||
|
|
||||||
export const OpenInAppPage = ({ urlToOpen, openHereClicked }: OpenAppProps) => {
|
export const OpenInAppPage = ({
|
||||||
|
urlToOpen,
|
||||||
|
openHereClicked,
|
||||||
|
mode = 'auth',
|
||||||
|
}: OpenAppProps) => {
|
||||||
// default to open the current page in desktop app
|
// default to open the current page in desktop app
|
||||||
urlToOpen ??= getOpenUrlInDesktopAppLink(window.location.href, true);
|
urlToOpen ??= getOpenUrlInDesktopAppLink(window.location.href, true);
|
||||||
const globalDialogService = useService(GlobalDialogService);
|
const globalDialogService = useService(GlobalDialogService);
|
||||||
@@ -35,18 +38,6 @@ export const OpenInAppPage = ({ urlToOpen, openHereClicked }: OpenAppProps) => {
|
|||||||
const appIcon = appIconMap[channel];
|
const appIcon = appIconMap[channel];
|
||||||
const appName = appNames[channel];
|
const appName = appNames[channel];
|
||||||
|
|
||||||
const maybeDocLink = urlToOpen ? resolveLinkToDoc(urlToOpen) : null;
|
|
||||||
|
|
||||||
const goToDocPage = useCallback(
|
|
||||||
(e: MouseEvent) => {
|
|
||||||
if (!maybeDocLink) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
openHereClicked?.(e);
|
|
||||||
},
|
|
||||||
[maybeDocLink, openHereClicked]
|
|
||||||
);
|
|
||||||
|
|
||||||
const goToAppearanceSetting = useCallback(
|
const goToAppearanceSetting = useCallback(
|
||||||
(e: MouseEvent) => {
|
(e: MouseEvent) => {
|
||||||
openHereClicked?.(e);
|
openHereClicked?.(e);
|
||||||
@@ -109,7 +100,7 @@ export const OpenInAppPage = ({ urlToOpen, openHereClicked }: OpenAppProps) => {
|
|||||||
<img src={appIcon} alt={appName} width={120} height={120} />
|
<img src={appIcon} alt={appName} width={120} height={120} />
|
||||||
|
|
||||||
<div className={styles.prompt}>
|
<div className={styles.prompt}>
|
||||||
{openHereClicked ? (
|
{mode === 'open-doc' ? (
|
||||||
<Trans i18nKey="com.affine.auth.open.affine.open-doc-prompt">
|
<Trans i18nKey="com.affine.auth.open.affine.open-doc-prompt">
|
||||||
This doc is now opened in {appName}
|
This doc is now opened in {appName}
|
||||||
</Trans>
|
</Trans>
|
||||||
@@ -124,7 +115,7 @@ export const OpenInAppPage = ({ urlToOpen, openHereClicked }: OpenAppProps) => {
|
|||||||
{openHereClicked && (
|
{openHereClicked && (
|
||||||
<a
|
<a
|
||||||
className={styles.promptLink}
|
className={styles.promptLink}
|
||||||
onClick={goToDocPage}
|
onClick={openHereClicked}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noreferrer"
|
rel="noreferrer"
|
||||||
>
|
>
|
||||||
@@ -140,25 +131,9 @@ export const OpenInAppPage = ({ urlToOpen, openHereClicked }: OpenAppProps) => {
|
|||||||
{t['com.affine.auth.open.affine.try-again']()}
|
{t['com.affine.auth.open.affine.try-again']()}
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div className={styles.accidentHandling}>
|
|
||||||
<div className={styles.prompt}>
|
|
||||||
{t['com.affine.auth.open.affine.still-have-problems']()}
|
|
||||||
</div>
|
|
||||||
<Link to="/" replace className={styles.promptLink}>
|
|
||||||
{t['com.affine.auth.open.affine.continue-with-browser']()}
|
|
||||||
</Link>
|
|
||||||
<a
|
|
||||||
className={styles.promptLink}
|
|
||||||
href={url}
|
|
||||||
target="_blank"
|
|
||||||
rel="noreferrer"
|
|
||||||
>
|
|
||||||
{t['com.affine.auth.open.affine.download-latest-client']()}
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{maybeDocLink ? (
|
{mode === 'open-doc' ? (
|
||||||
<div className={styles.docFooter}>
|
<div className={styles.docFooter}>
|
||||||
<button
|
<button
|
||||||
className={styles.editSettingsLink}
|
className={styles.editSettingsLink}
|
||||||
|
|||||||
Reference in New Issue
Block a user