Backend of public sharing at root (#6103)
This commit is contained in:
@@ -4,6 +4,7 @@ import DesktopRedirect from "~/scenes/DesktopRedirect";
|
||||
import DelayedMount from "~/components/DelayedMount";
|
||||
import FullscreenLoading from "~/components/FullscreenLoading";
|
||||
import Route from "~/components/ProfiledRoute";
|
||||
import env from "~/env";
|
||||
import useQueryNotices from "~/hooks/useQueryNotices";
|
||||
import lazyWithRetry from "~/utils/lazyWithRetry";
|
||||
import { matchDocumentSlug as slug } from "~/utils/routeHelpers";
|
||||
@@ -25,30 +26,37 @@ export default function Routes() {
|
||||
</DelayedMount>
|
||||
}
|
||||
>
|
||||
<Switch>
|
||||
<Route exact path="/" component={Login} />
|
||||
<Route exact path="/create" component={Login} />
|
||||
<Route exact path="/logout" component={Logout} />
|
||||
<Route exact path="/desktop-redirect" component={DesktopRedirect} />
|
||||
{env.ROOT_SHARE_ID ? (
|
||||
<Switch>
|
||||
<Route exact path="/" component={SharedDocument} />
|
||||
<Route exact path={`/doc/${slug}`} component={SharedDocument} />
|
||||
</Switch>
|
||||
) : (
|
||||
<Switch>
|
||||
<Route exact path="/" component={Login} />
|
||||
<Route exact path="/create" component={Login} />
|
||||
<Route exact path="/logout" component={Logout} />
|
||||
<Route exact path="/desktop-redirect" component={DesktopRedirect} />
|
||||
|
||||
<Redirect exact from="/share/:shareId" to="/s/:shareId" />
|
||||
<Route exact path="/s/:shareId" component={SharedDocument} />
|
||||
<Redirect exact from="/share/:shareId" to="/s/:shareId" />
|
||||
<Route exact path="/s/:shareId" component={SharedDocument} />
|
||||
|
||||
<Redirect
|
||||
exact
|
||||
from={`/share/:shareId/doc/${slug}`}
|
||||
to={`/s/:shareId/doc/${slug}`}
|
||||
/>
|
||||
<Route
|
||||
exact
|
||||
path={`/s/:shareId/doc/${slug}`}
|
||||
component={SharedDocument}
|
||||
/>
|
||||
<Redirect
|
||||
exact
|
||||
from={`/share/:shareId/doc/${slug}`}
|
||||
to={`/s/:shareId/doc/${slug}`}
|
||||
/>
|
||||
<Route
|
||||
exact
|
||||
path={`/s/:shareId/doc/${slug}`}
|
||||
component={SharedDocument}
|
||||
/>
|
||||
|
||||
<Authenticated>
|
||||
<AuthenticatedRoutes />
|
||||
</Authenticated>
|
||||
</Switch>
|
||||
<Authenticated>
|
||||
<AuthenticatedRoutes />
|
||||
</Authenticated>
|
||||
</Switch>
|
||||
)}
|
||||
</React.Suspense>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ function SharedDocumentScene(props: Props) {
|
||||
const [response, setResponse] = React.useState<Response>();
|
||||
const [error, setError] = React.useState<Error | null | undefined>();
|
||||
const { documents } = useStores();
|
||||
const { shareId, documentSlug } = props.match.params;
|
||||
const { shareId = env.ROOT_SHARE_ID, documentSlug } = props.match.params;
|
||||
const documentId = useDocumentId(documentSlug, response);
|
||||
const themeOverride = ["dark", "light"].includes(
|
||||
searchParams.get("theme") || ""
|
||||
@@ -185,7 +185,7 @@ function SharedDocumentScene(props: Props) {
|
||||
title={response.document.title}
|
||||
sidebar={
|
||||
response.sharedTree?.children.length ? (
|
||||
<Sidebar rootNode={response.sharedTree} shareId={shareId} />
|
||||
<Sidebar rootNode={response.sharedTree} shareId={shareId!} />
|
||||
) : undefined
|
||||
}
|
||||
>
|
||||
|
||||
@@ -2,6 +2,7 @@ import queryString from "query-string";
|
||||
import Collection from "~/models/Collection";
|
||||
import Comment from "~/models/Comment";
|
||||
import Document from "~/models/Document";
|
||||
import env from "~/env";
|
||||
|
||||
export function homePath(): string {
|
||||
return "/home";
|
||||
@@ -115,6 +116,10 @@ export function searchPath(
|
||||
}
|
||||
|
||||
export function sharedDocumentPath(shareId: string, docPath?: string) {
|
||||
if (shareId === env.ROOT_SHARE_ID) {
|
||||
return docPath ? docPath : "/";
|
||||
}
|
||||
|
||||
return docPath ? `/s/${shareId}${docPath}` : `/s/${shareId}`;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user