Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
feat: reenable page switch in chrome
Browse files Browse the repository at this point in the history
  • Loading branch information
marionebl committed May 24, 2018
1 parent a80ef4c commit a938223
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 53 deletions.
1 change: 1 addition & 0 deletions src/alva-util/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './guess-name';
export * from './noop';
2 changes: 2 additions & 0 deletions src/alva-util/noop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// tslint:disable-next-line:no-empty
export const noop = () => {};
105 changes: 52 additions & 53 deletions src/container/chrome/chrome-container.tsx
Original file line number Diff line number Diff line change
@@ -1,62 +1,61 @@
import * as AlvaUtil from '../../alva-util';
import { Chrome, CopySize, ViewSwitch, ViewTitle } from '../../components';
import { observer } from 'mobx-react';
import * as MobxReact from 'mobx-react';
import { OverviewSwitchContainer } from './overview-switch-container';
import * as React from 'react';
import { Page, ViewStore } from '../../store';
import { ViewStore } from '../../store';
import * as Types from '../../store/types';

@observer
export class ChromeContainer extends React.Component {
protected store = ViewStore.getInstance();
export const ChromeContainer = MobxReact.observer((props): JSX.Element | null => {
const store = ViewStore.getInstance();
const project = store.getCurrentProject();

protected getCurrentPage(): Page | undefined {
return this.store.getCurrentPage();
if (!project) {
return null;
}

public render(): JSX.Element {
let nextPage: Page | undefined;
let previousPage: Page | undefined;

const currentPage = this.getCurrentPage();
const project = this.store.getCurrentProject();
const pages = project ? project.getPages() : [];
const currentIndex = currentPage ? pages.indexOf(currentPage) : 0;

if (currentIndex > 0) {
previousPage = pages[currentIndex - 1];
}

if (currentIndex < pages.length - 1) {
nextPage = pages[currentIndex + 1];
}

return (
<Chrome>
{this.store.getActiveView() === Types.AlvaView.PageDetail ? (
<OverviewSwitchContainer />
) : (
<div />
)}
{this.store.getActiveView() === Types.AlvaView.PageDetail && (
<ViewSwitch
fontSize={CopySize.M}
justify="center"
leftVisible={Boolean(previousPage)}
rightVisible={Boolean(nextPage)}
// onLeftClick={() => /* this.openPage(previousPage) */}
// onRightClick={() => /* this.openPage(nextPage) */}
title={currentPage ? currentPage.getName() : ''}
/>
)}
{this.store.getActiveView() === Types.AlvaView.Pages && (
<ViewTitle
fontSize={CopySize.M}
justify="center"
title={project ? project.getName() : 'Alva'}
/>
)}
{this.props.children}
</Chrome>
);
const page = store.getCurrentPage();

if (!page) {
return null;
}

const index = project.getPageIndex(page);
const pages = project.getPages();

if (typeof index !== 'number') {
return null;
}
}

const previous = index > 0 ? () => store.setActivePageByIndex(index - 1) : AlvaUtil.noop;
const next = index < pages.length ? () => store.setActivePageByIndex(index + 1) : AlvaUtil.noop;

return (
<Chrome>
{store.getActiveView() === Types.AlvaView.PageDetail ? (
<OverviewSwitchContainer />
) : (
<div />
)}
{store.getActiveView() === Types.AlvaView.PageDetail && (
<ViewSwitch
fontSize={CopySize.M}
justify="center"
leftVisible={index > 0}
rightVisible={index < pages.length - 1}
onLeftClick={previous}
onRightClick={next}
title={page ? page.getName() : ''}
/>
)}
{store.getActiveView() === Types.AlvaView.Pages && (
<ViewTitle
fontSize={CopySize.M}
justify="center"
title={project ? project.getName() : 'Alva'}
/>
)}
{props.children}
</Chrome>
);
});

0 comments on commit a938223

Please sign in to comment.