Added non-standalone mode that hides 'open file' menus.

This commit is contained in:
Przemek Wiech 2019-04-18 23:40:09 +02:00
parent 56f8cfbf9a
commit 22262c53c0
2 changed files with 30 additions and 21 deletions

View File

@ -61,10 +61,12 @@ interface State {
showSidePanel?: boolean;
/** Whether the app is in embedded mode, i.e. embedded in an iframe. */
embedded: boolean;
/** Whether the app is in standalone mode, i.e. showing 'open file' menus */
standalone: boolean;
}
export class App extends React.Component<RouteComponentProps, {}> {
state: State = {loading: false, embedded: false};
state: State = {loading: false, embedded: false, standalone: true};
chartRef: Chart | null = null;
private isNewData(
@ -155,7 +157,11 @@ export class App extends React.Component<RouteComponentProps, {}> {
if (embedded && !this.state.embedded) {
this.setState(
Object.assign({}, this.state, {embedded: true, showSidePanel}),
Object.assign({}, this.state, {
embedded: true,
standalone: false,
showSidePanel,
}),
);
// Notify the parent window that we are ready.
window.parent.postMessage('ready', '*');
@ -172,6 +178,7 @@ export class App extends React.Component<RouteComponentProps, {}> {
const generation = !isNaN(parsedGen) ? parsedGen : undefined;
const hash = getParam('file');
const handleCors = getParam('handleCors') !== 'false'; // True by default.
const standalone = getParam('standalone') !== 'false'; // True by default.
const gedcom = this.props.location.state && this.props.location.state.data;
const images =
@ -190,6 +197,7 @@ export class App extends React.Component<RouteComponentProps, {}> {
error: undefined,
loading: true,
url,
standalone,
}),
);
const data = hash
@ -212,6 +220,7 @@ export class App extends React.Component<RouteComponentProps, {}> {
loading: false,
url,
showSidePanel,
standalone,
}),
);
} catch (error) {
@ -290,7 +299,7 @@ export class App extends React.Component<RouteComponentProps, {}> {
this.state.selection
)
}
embedded={this.state.embedded}
standalone={this.state.standalone}
onSelection={this.onSelection}
onPrint={() => {
analyticsEvent('print');

View File

@ -33,7 +33,7 @@ interface State {
interface Props {
showingChart: boolean;
gedcom?: GedcomData;
embedded: boolean;
standalone: boolean;
onSelection: (indiInfo: IndiInfo) => void;
onPrint: () => void;
onDownloadPdf: () => void;
@ -306,7 +306,7 @@ export class TopBar extends React.Component<
</>
) : null;
const fileMenus = this.props.embedded ? null : (
const fileMenus = this.props.standalone ? (
<>
<Link to="/">
<Menu.Item>
@ -338,23 +338,9 @@ export class TopBar extends React.Component<
</Menu.Item>
</label>
</>
);
) : null;
const sourceLink = this.props.embedded ? (
<>
<Menu.Item
as="a"
href="https://pewu.github.com/topola-viewer"
position="right"
target="_blank"
>
<FormattedMessage
id="menu.powered_by"
defaultMessage="Powered by Topola"
/>
</Menu.Item>
</>
) : (
const sourceLink = this.props.standalone ? (
<>
<Menu.Item
as="a"
@ -368,6 +354,20 @@ export class TopBar extends React.Component<
/>
</Menu.Item>
</>
) : (
<>
<Menu.Item
as="a"
href="https://pewu.github.com/topola-viewer"
position="right"
target="_blank"
>
<FormattedMessage
id="menu.powered_by"
defaultMessage="Powered by Topola"
/>
</Menu.Item>
</>
);
return (