mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-22 19:53:48 +08:00
feat(mobile): share page support (#12351)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Improved server context awareness for workspaces on mobile web. - Enhanced handling for missing workspaces by displaying a share page when accessing a document detail route in mobile web environments. - **Bug Fixes** - Workspace list now refreshes automatically when switching workspace IDs. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -1,9 +1,11 @@
|
|||||||
import { AffineErrorBoundary } from '@affine/core/components/affine/affine-error-boundary';
|
import { AffineErrorBoundary } from '@affine/core/components/affine/affine-error-boundary';
|
||||||
import { AffineErrorComponent } from '@affine/core/components/affine/affine-error-boundary/affine-error-fallback';
|
import { AffineErrorComponent } from '@affine/core/components/affine/affine-error-boundary/affine-error-fallback';
|
||||||
import { PageNotFound } from '@affine/core/desktop/pages/404';
|
import { PageNotFound } from '@affine/core/desktop/pages/404';
|
||||||
|
import { SharePage } from '@affine/core/desktop/pages/workspace/share/share-page';
|
||||||
import { workbenchRoutes } from '@affine/core/mobile/workbench-router';
|
import { workbenchRoutes } from '@affine/core/mobile/workbench-router';
|
||||||
|
import { ServersService } from '@affine/core/modules/cloud';
|
||||||
import { WorkspacesService } from '@affine/core/modules/workspace';
|
import { WorkspacesService } from '@affine/core/modules/workspace';
|
||||||
import { useLiveData, useServices } from '@toeverything/infra';
|
import { FrameworkScope, useLiveData, useServices } from '@toeverything/infra';
|
||||||
import {
|
import {
|
||||||
lazy as reactLazy,
|
lazy as reactLazy,
|
||||||
Suspense,
|
Suspense,
|
||||||
@@ -17,6 +19,7 @@ import {
|
|||||||
type RouteObject,
|
type RouteObject,
|
||||||
useLocation,
|
useLocation,
|
||||||
useParams,
|
useParams,
|
||||||
|
useSearchParams,
|
||||||
} from 'react-router-dom';
|
} from 'react-router-dom';
|
||||||
|
|
||||||
import { WorkspaceLayout } from './layout';
|
import { WorkspaceLayout } from './layout';
|
||||||
@@ -62,12 +65,14 @@ const warpedRoutes = workbenchRoutes.map((originalRoute: RouteObject) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
export const Component = () => {
|
export const Component = () => {
|
||||||
const { workspacesService } = useServices({
|
const { workspacesService, serversService } = useServices({
|
||||||
WorkspacesService,
|
WorkspacesService,
|
||||||
|
ServersService,
|
||||||
});
|
});
|
||||||
|
|
||||||
const params = useParams();
|
const params = useParams();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
const [searchParams] = useSearchParams();
|
||||||
|
|
||||||
// todo(pengx17): dedupe the code with core
|
// todo(pengx17): dedupe the code with core
|
||||||
// check if we are in detail doc route, if so, maybe render share page
|
// check if we are in detail doc route, if so, maybe render share page
|
||||||
@@ -115,7 +120,8 @@ export const Component = () => {
|
|||||||
const retryTimesRef = useRef(3);
|
const retryTimesRef = useRef(3);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
retryTimesRef.current = 3; // reset retry times
|
retryTimesRef.current = 3; // reset retry times
|
||||||
}, [params.workspaceId]);
|
workspacesService.list.revalidate();
|
||||||
|
}, [params.workspaceId, workspacesService.list]);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (listLoading === false && meta === undefined) {
|
if (listLoading === false && meta === undefined) {
|
||||||
const timer = setInterval(() => {
|
const timer = setInterval(() => {
|
||||||
@@ -129,12 +135,33 @@ export const Component = () => {
|
|||||||
return;
|
return;
|
||||||
}, [listLoading, meta, workspaceNotFound, workspacesService]);
|
}, [listLoading, meta, workspaceNotFound, workspacesService]);
|
||||||
|
|
||||||
|
// server search params
|
||||||
|
const serverFromSearchParams = useLiveData(
|
||||||
|
searchParams.has('server')
|
||||||
|
? serversService.serverByBaseUrl$(searchParams.get('server') as string)
|
||||||
|
: undefined
|
||||||
|
);
|
||||||
|
// server from workspace
|
||||||
|
const serverFromWorkspace = useLiveData(
|
||||||
|
meta?.flavour && meta.flavour !== 'local'
|
||||||
|
? serversService.server$(meta?.flavour)
|
||||||
|
: undefined
|
||||||
|
);
|
||||||
|
const server = serverFromWorkspace ?? serverFromSearchParams;
|
||||||
|
|
||||||
if (workspaceNotFound) {
|
if (workspaceNotFound) {
|
||||||
if (
|
if (
|
||||||
BUILD_CONFIG.isDesktopEdition /* only browser has share page */ &&
|
BUILD_CONFIG.isMobileWeb /* only browser has share page */ &&
|
||||||
detailDocRoute
|
detailDocRoute
|
||||||
) {
|
) {
|
||||||
return <div>TODO: share page</div>;
|
return (
|
||||||
|
<FrameworkScope scope={server?.scope}>
|
||||||
|
<SharePage
|
||||||
|
docId={detailDocRoute.docId}
|
||||||
|
workspaceId={detailDocRoute.workspaceId}
|
||||||
|
/>
|
||||||
|
</FrameworkScope>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return <PageNotFound noPermission />;
|
return <PageNotFound noPermission />;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user