|
|
@ -1,16 +1,26 @@
|
|
|
|
import type { PropsWithChildren } from 'react';
|
|
|
|
import type { PropsWithChildren } from 'react';
|
|
|
|
import React from 'react';
|
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
|
|
|
|
import type { History } from 'history';
|
|
|
|
|
|
|
|
import { createBrowserHistory } from 'history';
|
|
|
|
import { createBrowserHistory } from 'history';
|
|
|
|
import { Router as OriginalRouter } from 'react-router';
|
|
|
|
import { Router as OriginalRouter } from 'react-router';
|
|
|
|
|
|
|
|
|
|
|
|
import { layoutFromWindow } from 'mastodon/is_mobile';
|
|
|
|
import { layoutFromWindow } from 'mastodon/is_mobile';
|
|
|
|
|
|
|
|
|
|
|
|
const browserHistory = createBrowserHistory();
|
|
|
|
interface MastodonLocationState {
|
|
|
|
|
|
|
|
fromMastodon?: boolean;
|
|
|
|
|
|
|
|
mastodonModalKey?: string;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const browserHistory = createBrowserHistory<
|
|
|
|
|
|
|
|
MastodonLocationState | undefined
|
|
|
|
|
|
|
|
>();
|
|
|
|
const originalPush = browserHistory.push.bind(browserHistory);
|
|
|
|
const originalPush = browserHistory.push.bind(browserHistory);
|
|
|
|
|
|
|
|
const originalReplace = browserHistory.replace.bind(browserHistory);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
browserHistory.push = (path: string, state?: MastodonLocationState) => {
|
|
|
|
|
|
|
|
state = state ?? {};
|
|
|
|
|
|
|
|
state.fromMastodon = true;
|
|
|
|
|
|
|
|
|
|
|
|
browserHistory.push = (path: string, state: History.LocationState) => {
|
|
|
|
|
|
|
|
if (layoutFromWindow() === 'multi-column' && !path.startsWith('/deck')) {
|
|
|
|
if (layoutFromWindow() === 'multi-column' && !path.startsWith('/deck')) {
|
|
|
|
originalPush(`/deck${path}`, state);
|
|
|
|
originalPush(`/deck${path}`, state);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -18,6 +28,19 @@ browserHistory.push = (path: string, state: History.LocationState) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
browserHistory.replace = (path: string, state?: MastodonLocationState) => {
|
|
|
|
|
|
|
|
if (browserHistory.location.state?.fromMastodon) {
|
|
|
|
|
|
|
|
state = state ?? {};
|
|
|
|
|
|
|
|
state.fromMastodon = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (layoutFromWindow() === 'multi-column' && !path.startsWith('/deck')) {
|
|
|
|
|
|
|
|
originalReplace(`/deck${path}`, state);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
originalReplace(path, state);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export const Router: React.FC<PropsWithChildren> = ({ children }) => {
|
|
|
|
export const Router: React.FC<PropsWithChildren> = ({ children }) => {
|
|
|
|
return <OriginalRouter history={browserHistory}>{children}</OriginalRouter>;
|
|
|
|
return <OriginalRouter history={browserHistory}>{children}</OriginalRouter>;
|
|
|
|
};
|
|
|
|
};
|
|
|
|