This repository has been archived by the owner on Oct 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: bind active page and selected overview item together
- Loading branch information
Showing
3 changed files
with
26 additions
and
67 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,31 @@ | ||
import * as MobX from 'mobx'; | ||
import Layout from '../../lsg/patterns/layout'; | ||
import { observer } from 'mobx-react'; | ||
import { PageListComposite } from './page-list-composite'; | ||
import { PageRef } from '../../store/page/page-ref'; | ||
import { Project } from '../../store/project'; | ||
import { PageTileContainer } from './page-tile-container'; | ||
import * as React from 'react'; | ||
import { Store } from '../../store/store'; | ||
|
||
@observer | ||
export class PageListContainer extends React.Component { | ||
@MobX.observable public focusStates: boolean[] = this.generateInitialFocusList(false); | ||
export const PageListContainer: React.StatelessComponent = observer((): JSX.Element | null => { | ||
const store = Store.getInstance(); | ||
const project = store.getCurrentProject(); | ||
const currentPage = store.getCurrentPageRef(); | ||
const currentPageId = currentPage ? currentPage.getId() : undefined; | ||
|
||
@MobX.action | ||
protected generateInitialFocusList(bool: boolean): boolean[] { | ||
const pages = this.getPages(); | ||
const states: boolean[] = []; | ||
pages.forEach((page: PageRef) => { | ||
states.push(bool); | ||
}); | ||
return states; | ||
} | ||
protected getPages(): PageRef[] { | ||
const project: Project | undefined = Store.getInstance().getCurrentProject(); | ||
return project ? project.getPages() : []; | ||
} | ||
|
||
@MobX.action | ||
protected handleClick(e: React.MouseEvent<HTMLElement>, i: number): void { | ||
if (this.focusStates[i]) { | ||
return; | ||
} | ||
this.focusStates.forEach((state, index) => { | ||
this.focusStates[index] = false; | ||
}); | ||
this.focusStates[i] = !this.focusStates[i]; | ||
if (!project) { | ||
return null; | ||
} | ||
|
||
public render(): JSX.Element { | ||
return ( | ||
<PageListComposite | ||
focusStates={this.focusStates} | ||
pages={this.getPages()} | ||
onClick={this.handleClick} | ||
/> | ||
); | ||
} | ||
} | ||
return ( | ||
<Layout> | ||
{project | ||
.getPages() | ||
.map((pageRef: PageRef, i: number) => ( | ||
<PageTileContainer | ||
focused={pageRef.getId() === currentPageId} | ||
key={pageRef.getId()} | ||
page={pageRef} | ||
/> | ||
))} | ||
</Layout> | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters