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.
feat: replace project dropdown with page tile overview (fixes #176)
- Loading branch information
Showing
13 changed files
with
382 additions
and
153 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import Layout from '../../lsg/patterns/layout'; | ||
import { observer } from 'mobx-react'; | ||
import { PageRef } from '../../store/page/page-ref'; | ||
import { PageTileContainer } from './page-tile-container'; | ||
import * as React from 'react'; | ||
|
||
export interface PageListProps { | ||
focusStates: boolean[]; | ||
pages: PageRef[]; | ||
onClick(event: React.MouseEvent<HTMLElement>, index: number): void; | ||
} | ||
|
||
export const PageListComposite: React.StatelessComponent<PageListProps> = observer( | ||
(props): JSX.Element => ( | ||
<Layout> | ||
{props.pages.map((page: PageRef, i: number) => ( | ||
<PageTileContainer | ||
focused={props.focusStates[i]} | ||
key={page.getId()} | ||
onClick={e => props.onClick(e, i)} | ||
page={page} | ||
/> | ||
))} | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import * as MobX from 'mobx'; | ||
import { observer } from 'mobx-react'; | ||
import { PageListComposite } from './page-list-composite'; | ||
import { PageRef } from '../../store/page/page-ref'; | ||
import { Project } from '../../store/project'; | ||
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); | ||
|
||
@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]; | ||
} | ||
|
||
public render(): JSX.Element { | ||
return ( | ||
<PageListComposite | ||
focusStates={this.focusStates} | ||
pages={this.getPages()} | ||
onClick={this.handleClick} | ||
/> | ||
); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import * as React from 'react'; | ||
|
||
import { colors } from '../../lsg/patterns/colors'; | ||
import Copy from '../../lsg/patterns/copy'; | ||
import { Headline } from '../../lsg/patterns/headline'; | ||
import Space, { Size } from '../../lsg/patterns/space'; | ||
import { Store } from '../../store/store'; | ||
|
||
export const PageListPreview: React.StatelessComponent = props => { | ||
const project = Store.getInstance().getCurrentProject(); | ||
if (!project) { | ||
return <>props.children</>; | ||
} | ||
const dateString = new Intl.DateTimeFormat().format(project.getLastChangedDate()); | ||
return ( | ||
<Space size={[Size.XXXL, Size.XL, Size.XS, Size.XL]}> | ||
<Space size={[Size.S, Size.S, Size.XXXL]}> | ||
<Headline order={3} tagName="h1"> | ||
{project.getName()} | ||
</Headline> | ||
<Copy textColor={colors.grey60}> | ||
Last change: {dateString} by {project.getLastChangedAuthor()} | ||
</Copy> | ||
</Space> | ||
{props.children} | ||
</Space> | ||
); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { PreviewTile } from '../../lsg/patterns/preview-tile/index'; | ||
import Space, { Size } from '../../lsg/patterns/space/index'; | ||
import * as MobX from 'mobx'; | ||
import { observer } from 'mobx-react'; | ||
import { PageRef } from '../../store/page/page-ref'; | ||
import * as React from 'react'; | ||
import { Store } from '../../store/store'; | ||
|
||
export interface PageTileContainerProps { | ||
focused: boolean; | ||
onClick: React.MouseEventHandler<HTMLElement>; | ||
page: PageRef; | ||
} | ||
|
||
@observer | ||
export class PageTileContainer extends React.Component<PageTileContainerProps> { | ||
@MobX.observable public editable: boolean = false; | ||
@MobX.observable public inputValue: string = ''; | ||
|
||
public constructor(props: PageTileContainerProps) { | ||
super(props); | ||
this.inputValue = this.inputValue || this.props.page.getName(); | ||
|
||
this.handleBlur = this.handleBlur.bind(this); | ||
this.handleChange = this.handleChange.bind(this); | ||
this.handleClick = this.handleClick.bind(this); | ||
this.handleDoubleClick = this.handleDoubleClick.bind(this); | ||
this.handleKeyDown = this.handleKeyDown.bind(this); | ||
this.renamePage = this.renamePage.bind(this); | ||
} | ||
|
||
@MobX.action | ||
protected handleBlur(): void { | ||
this.renamePage(); | ||
} | ||
|
||
@MobX.action | ||
protected handleChange(e: React.ChangeEvent<HTMLInputElement>): void { | ||
this.inputValue = e.target.value; | ||
} | ||
|
||
@MobX.action | ||
protected handleClick(e: React.MouseEvent<HTMLElement>): void { | ||
this.props.onClick(e); | ||
if (this.props.focused) { | ||
this.editable = true; | ||
} | ||
} | ||
|
||
protected handleDoubleClick(e: React.MouseEvent<HTMLElement>): void { | ||
Store.getInstance().openPage(this.props.page.getId()); | ||
} | ||
|
||
@MobX.action | ||
protected handleKeyDown(e: React.KeyboardEvent<HTMLInputElement>): void { | ||
switch (e.key) { | ||
case 'Escape': | ||
this.inputValue = this.props.page.getName(); | ||
this.editable = false; | ||
break; | ||
|
||
case 'Enter': | ||
this.renamePage(); | ||
break; | ||
|
||
default: | ||
return; | ||
} | ||
} | ||
@MobX.action | ||
protected renamePage(): void { | ||
if (!this.inputValue) { | ||
this.inputValue = this.props.page.getName(); | ||
this.editable = false; | ||
return; | ||
} | ||
|
||
this.props.page.setName(this.inputValue); | ||
Store.getInstance().save(); | ||
this.editable = false; | ||
} | ||
|
||
public render(): JSX.Element { | ||
return ( | ||
<Space size={Size.S}> | ||
<PreviewTile | ||
editable={this.editable} | ||
focused={this.props.focused} | ||
id={this.props.page.getId()} | ||
name={this.inputValue} | ||
onBlur={this.handleBlur} | ||
onChange={this.handleChange} | ||
onClick={this.handleClick} | ||
onDoubleClick={this.handleDoubleClick} | ||
onKeyDown={this.handleKeyDown} | ||
value={this.inputValue} | ||
/> | ||
</Space> | ||
); | ||
} | ||
} |
Oops, something went wrong.