From fd6a9f52a72a688ab2a735c9ff50b2046e726a1b Mon Sep 17 00:00:00 2001 From: Artur Tamborski Date: Sat, 28 Nov 2020 10:59:56 +0100 Subject: [PATCH] components: improve layout with css grid, rewrite line rendering --- src/components/App/App.scss | 4 ++-- src/components/App/App.tsx | 4 +++- src/components/Board/Board.scss | 12 ++---------- src/components/Board/Board.tsx | 21 +++++++++++++-------- src/components/Line/Line.tsx | 2 -- src/components/Logo/Logo.scss | 9 +++------ src/components/Logo/Logo.tsx | 2 +- 7 files changed, 24 insertions(+), 30 deletions(-) diff --git a/src/components/App/App.scss b/src/components/App/App.scss index 5e99f65..3bd71fa 100644 --- a/src/components/App/App.scss +++ b/src/components/App/App.scss @@ -1,9 +1,9 @@ .App { + max-width: 100vw; max-height: 100vh; - display: grid; grid-template-columns: repeat(3, 1fr); - grid-template-rows: 1fr; + grid-template-rows: 1fr 1fr 1/2fr; grid-column-gap: 0; grid-row-gap: 0; } diff --git a/src/components/App/App.tsx b/src/components/App/App.tsx index 3791fc4..4904e7c 100644 --- a/src/components/App/App.tsx +++ b/src/components/App/App.tsx @@ -8,9 +8,11 @@ import './App.scss'; export default function App(): JSX.Element { return (
+
+ +
- { handleMouseDown(startPos: Point) { const endPos = startPos; - this.setState({...this.state, startPos, endPos, isSelecting: true}); + let lines = [...this.state.lines]; + lines[0] = true; + this.setState({...this.state, startPos, endPos, lines, isSelecting: true}); } handleMouseUp(endPos: Point) { - if (this.moveIsValid(endPos)) - this.setState({...this.state, endPos, isSelecting: false}); + if (!this.moveIsValid(endPos)) + return; + + this.setState({...this.state, endPos, isSelecting: false}); } handleMouseOver(endPos: Point) { - if (this.moveIsValid(endPos)) - this.setState({...this.state, endPos}); + if (!this.moveIsValid(endPos)) + return; + + this.setState({...this.state, endPos}); } renderCell(s: string, pos: Point): JSX.Element { @@ -80,7 +86,6 @@ export default class Board extends React.Component { startPos={{...this.state.startPos}} endPos={{...this.state.endPos}} cellSize={60} - isVisible={this.state.lines[0]} /> ); } @@ -91,8 +96,8 @@ export default class Board extends React.Component { oy.map((s, x) => this.renderCell(s, {x, y}))); - let lines = this.state.lines.map((ox, x) => - this.renderLine(x)); + let lines = this.state.lines.filter(x => x).map((ox, x) => + this.renderLine(x)); return (
diff --git a/src/components/Line/Line.tsx b/src/components/Line/Line.tsx index ac40d38..a190e1b 100644 --- a/src/components/Line/Line.tsx +++ b/src/components/Line/Line.tsx @@ -8,7 +8,6 @@ interface ILineProps { startPos: Point; endPos: Point; cellSize: number; - isVisible: boolean; } export default function Line(props: ILineProps): JSX.Element { @@ -17,7 +16,6 @@ export default function Line(props: ILineProps): JSX.Element { return ( - Logo + Logo
); }