diff --git a/site.css b/site.css index 665eba0..6f3c2be 100644 --- a/site.css +++ b/site.css @@ -30,3 +30,42 @@ h1 { .Grid img { cursor: pointer; } + +.BigPicture { + background-color: rgba(0, 0, 0, 0.6); + bottom: 0; + display: flex; + flex-direction: column; + left: 0; + padding: 30px; + position: fixed; + right: 0; + top: 0; +} + +.BigPicture-image { + background-position: center; + background-repeat: no-repeat; + background-size: contain; + flex: 1 1 auto; +} + +.BigPicture-footer { + align-self: center; + display: flex; + flex: 0 0 auto; + justify-content: space-between; + margin-top: 30px; + max-width: 200px; + width: 100%; +} + +.BigPicture-footerLink { + color: #69c; + cursor: pointer; + text-decoration: none; +} + +.BigPicture-footerLink:hover { + text-decoration: underline; +} diff --git a/src/components/big_picture.tsx b/src/components/big_picture.tsx new file mode 100644 index 0000000..d41236a --- /dev/null +++ b/src/components/big_picture.tsx @@ -0,0 +1,38 @@ +import * as Model from "../model"; + +import * as React from "react"; + +export interface Props { + src: string; + image: Model.Image; + onClose: () => void; + width: number; +} + +export class BigPicture extends React.PureComponent { + static displayName = "BigPicture"; + + render() { + const src = `img/1600/${this.props.src}`; + return
+
+
+
+ + Download + + + Close + +
+
; + } +} diff --git a/src/components/grid.tsx b/src/components/grid.tsx index 6916f87..ff04223 100644 --- a/src/components/grid.tsx +++ b/src/components/grid.tsx @@ -6,7 +6,6 @@ import * as React from "react"; export interface Props { images: Model.Images; onImageSelected: (key: string) => void; - selectedImage: string | null; width: number; } @@ -52,7 +51,6 @@ export class Grid extends React.PureComponent { return this.props.onImageSelected(key)} - selected={this.props.selectedImage === key} src={key} key={key} width={image.width/image.height * scale} diff --git a/src/components/picture.tsx b/src/components/picture.tsx index d0b59d3..03c965e 100644 --- a/src/components/picture.tsx +++ b/src/components/picture.tsx @@ -6,7 +6,6 @@ export interface Props { src: string; image: Model.Image; onClick: () => void; - selected?: boolean; width: number; } @@ -16,11 +15,10 @@ export class Picture extends React.PureComponent { render() { const src = `img/600/${this.props.src}`; return ; } diff --git a/src/components/root.tsx b/src/components/root.tsx index 1b3f712..57fda16 100644 --- a/src/components/root.tsx +++ b/src/components/root.tsx @@ -1,3 +1,4 @@ +import { BigPicture } from "./big_picture"; import { Grid } from "./grid"; import * as Model from "../model"; @@ -7,16 +8,15 @@ export interface Props {} export interface State { images: Model.Images; - selectedIamge?: string | null; + selectedImage?: string | null; width: number; } export class Root extends React.PureComponent { static displayName = "Root"; - state = { + state: State = { images: {}, - selectedImage: null, width: window.innerWidth } @@ -29,24 +29,52 @@ export class Root extends React.PureComponent { window.onresize = () => { this.setState({ width: window.innerWidth }); } + + window.onpopstate = this._loadHash; + + this._loadHash(); } render() { return

Ski


+ { this._bigPicture() }
; } + private _bigPicture = () => { + if (this.state.selectedImage && this.state.images[this.state.selectedImage]) { + return + } else { + return null; + } + } + + private _loadHash = () => { + if (window.location.hash.length > 0) { + this.setState({ selectedImage: window.location.hash.slice(1) }); + } else { + this.setState({ selectedImage: null }); + } + } + private _onImageSelected = (key: string) => { - this.setState(state => ({ - ...state, - selectedImage: key - })); + this.setState({ selectedImage: key }); + window.history.pushState(null, "", `#${key}`); + } + + private _showGrid = () => { + this.setState({ selectedImage: null }); + window.history.pushState(null, "", "#"); } }