From 89a8621de166f4fb182a2eab9b8d882ee3fe1082 Mon Sep 17 00:00:00 2001 From: David Ralph Date: Wed, 16 Sep 2020 12:32:09 +0100 Subject: [PATCH] bug fixes and favourite button --- src/App.jsx | 3 +++ src/components/widgets/Background.jsx | 6 +++++ src/components/widgets/Favourite.jsx | 35 +++++++++++++++++++++++++++ src/components/widgets/Search.jsx | 2 +- src/scss/modules/_credit.scss | 10 ++++++-- 5 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 src/components/widgets/Favourite.jsx diff --git a/src/App.jsx b/src/App.jsx index 217f09d8..bdf3ffae 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -6,6 +6,7 @@ import Greeting from './components/widgets/Greeting'; import Quote from './components/widgets/Quote'; import Search from './components/widgets/Search'; import Maximise from './components/widgets/Maximise'; +import Favourite from './components/widgets/Favourite'; import Navbar from './components/Navbar'; @@ -68,12 +69,14 @@ export default class App extends React.PureComponent {

{language.credit}

+
+ this.setState({ settingsModal: false })} isOpen={this.state.settingsModal} className={modalClassList} overlayClassName={overlayClassList} ariaHideApp={false}> this.favourite()} /> + }; + } + + favourite() { + if (localStorage.getItem('favourite')) { + localStorage.removeItem('favourite'); + this.setState({ favourited: this.favourite()} /> }); + } else { + const url = document.getElementById('backgroundImage').style.backgroundImage.replace('url("', '').replace('")', ''); + const credit = document.getElementById('credit').textContent; + const location = document.getElementById('location').textContent; + localStorage.setItem('favourite', JSON.stringify({ url: url, credit: credit, location: location })); + this.setState({ favourited: this.favourite()} /> }); + } + } + + componentDidMount() { + if (localStorage.getItem('favourite')) this.setState({ favourited: this.favourite()} /> }); + } + + render() { + return
+ {this.state.favourited} +
+ } +} \ No newline at end of file diff --git a/src/components/widgets/Search.jsx b/src/components/widgets/Search.jsx index 07f687b0..b062981f 100644 --- a/src/components/widgets/Search.jsx +++ b/src/components/widgets/Search.jsx @@ -24,7 +24,7 @@ export default class Search extends React.PureComponent { const searchButton = () => { let value = document.getElementById('searchtext').value; if (!value) value = 'mue fast'; - window.location.href = url + '?q=' + value; + window.location.href = url + `?${query}=` + value; }; return ( diff --git a/src/scss/modules/_credit.scss b/src/scss/modules/_credit.scss index 2a9ba056..c6cd468f 100644 --- a/src/scss/modules/_credit.scss +++ b/src/scss/modules/_credit.scss @@ -15,6 +15,12 @@ right: 25px; } +.favourite { + position: absolute; + bottom: 10px; + right: 50px; +} + #photographer { position: absolute; bottom: 10px; @@ -22,12 +28,12 @@ width: 1000px; } -.locationicon, #viewButton { +.locationicon, #viewButton, #favouriteButton { width: auto; cursor: pointer; } -.navbar-container > svg, #backgroundCredits > svg, #viewButton > svg { +.navbar-container > svg, #backgroundCredits > svg, #viewButton > svg, #favouriteButton > svg { font-size: calc(10px + 1.5vmin) !important; position: absolute; bottom: 2px;