From 84dbe5cb69196b678016645d73c671dbd97716b5 Mon Sep 17 00:00:00 2001 From: David Ralph Date: Fri, 30 Apr 2021 22:49:04 +0100 Subject: [PATCH] feat: pexels background api --- package.json | 10 +++++----- .../main/settings/sections/background/Background.jsx | 4 ++++ src/components/widgets/background/Background.jsx | 9 ++++++++- src/components/widgets/background/PhotoInformation.jsx | 2 +- src/modules/constants.js | 1 + src/translations/de_DE.json | 1 + src/translations/en_GB.json | 1 + src/translations/en_US.json | 1 + src/translations/es.json | 1 + src/translations/fr.json | 1 + src/translations/nl.json | 1 + src/translations/no.json | 1 + src/translations/ru.json | 1 + src/translations/zh_CN.json | 1 + 14 files changed, 28 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 08c83eec..add8574d 100644 --- a/package.json +++ b/package.json @@ -27,12 +27,12 @@ "weather-icons-react": "1.2.0" }, "devDependencies": { - "@babel/core": "^7.13.16", + "@babel/core": "^7.14.0", "@babel/eslint-parser": "^7.13.14", "@babel/plugin-proposal-class-properties": "^7.13.0", "@babel/plugin-transform-react-constant-elements": "^7.13.13", "@babel/plugin-transform-runtime": "^7.13.15", - "@babel/preset-env": "^7.13.15", + "@babel/preset-env": "^7.14.0", "@babel/preset-react": "^7.13.13", "babel-loader": "^8.2.2", "babel-plugin-transform-react-class-to-function": "^1.2.2", @@ -42,11 +42,11 @@ "eslint-config-react-app": "^6.0.0", "eslint-webpack-plugin": "^2.5.4", "html-webpack-plugin": "^5.3.1", - "mini-css-extract-plugin": "^1.5.1", - "sass": "^1.32.11", + "mini-css-extract-plugin": "^1.6.0", + "sass": "^1.32.12", "sass-loader": "^11.0.1", "source-map-loader": "^2.0.1", - "webpack": "^5.36.0", + "webpack": "^5.36.2", "webpack-cli": "^4.6.0", "webpack-dev-server": "^3.11.2" }, diff --git a/src/components/modals/main/settings/sections/background/Background.jsx b/src/components/modals/main/settings/sections/background/Background.jsx index 624dd5f9..4d93e375 100644 --- a/src/components/modals/main/settings/sections/background/Background.jsx +++ b/src/components/modals/main/settings/sections/background/Background.jsx @@ -104,6 +104,10 @@ export default class BackgroundSettings extends React.PureComponent { { 'name': 'Unsplash', 'value': 'unsplash' + }, + { + 'name': 'Pexels', + 'value': 'pexels' } ]; diff --git a/src/components/widgets/background/Background.jsx b/src/components/widgets/background/Background.jsx index 363680c2..45a6fc8c 100644 --- a/src/components/widgets/background/Background.jsx +++ b/src/components/widgets/background/Background.jsx @@ -139,6 +139,9 @@ export default class Background extends React.PureComponent { //requestURL = `${window.constants.UNSPLASH_URL}/getImage?category=${apiCategory}`; requestURL = `${window.constants.UNSPLASH_URL}/getImage`; break; + case 'pexels': + requestURL = `${window.constants.PEXELS_URL}/getImage`; + break; // Defaults to Mue default: requestURL = `${window.constants.API_URL}/images/random?category=${apiCategory}`; @@ -152,13 +155,17 @@ export default class Background extends React.PureComponent { return this.offlineBackground(); } + let credit = data.photographer; + if (backgroundAPI === 'unsplash') credit = data.photographer + ` ${this.language.unsplash}`; + else if (backgroundAPI === 'pexels') credit = data.photographer + ` ${this.language.pexels}`; + this.setState({ url: data.file, type: 'api', currentAPI: backgroundAPI, photoInfo: { hidden: false, - credit: (backgroundAPI !== 'unsplash') ? data.photographer : data.photographer + ` ${this.language.unsplash}`, + credit: credit, location: (data.location.replace(/[null]+/g, '') !== ' ') ? data.location : 'N/A', camera: data.camera, resolution: data.resolution, diff --git a/src/components/widgets/background/PhotoInformation.jsx b/src/components/widgets/background/PhotoInformation.jsx index 0ed22ac1..a7e76e52 100644 --- a/src/components/widgets/background/PhotoInformation.jsx +++ b/src/components/widgets/background/PhotoInformation.jsx @@ -30,7 +30,7 @@ export default function PhotoInformation(props) { } // remove unsplash text - const photographer = props.info.credit.split(` ${language.unsplash}`)[0]; + const photographer = props.info.credit.split(` ${language.unsplash}`)[0].split(` ${language.pexels}`); let credit = props.info.credit; let photo = language.credit; diff --git a/src/modules/constants.js b/src/modules/constants.js index 80b525c6..938dc79c 100644 --- a/src/modules/constants.js +++ b/src/modules/constants.js @@ -1,5 +1,6 @@ export const API_URL = 'https://api.muetab.com'; export const UNSPLASH_URL = 'https://unsplash.muetab.com'; +export const PEXELS_URL = 'https://pexels.muetab.com'; export const MARKETPLACE_URL = 'https://marketplace.muetab.com'; export const WEATHER_URL = 'https://weather.muetab.com'; export const WEBSITE_URL = 'https://muetab.com'; diff --git a/src/translations/de_DE.json b/src/translations/de_DE.json index 0354b2c6..35a72dae 100644 --- a/src/translations/de_DE.json +++ b/src/translations/de_DE.json @@ -13,6 +13,7 @@ "background": { "credit": "Foto von", "unsplash": "unsplash.com", + "pexels": "pexels.com", "information": "Informationen", "download": "Download" }, diff --git a/src/translations/en_GB.json b/src/translations/en_GB.json index 23b25a27..4c928f92 100644 --- a/src/translations/en_GB.json +++ b/src/translations/en_GB.json @@ -13,6 +13,7 @@ "background": { "credit": "Photo by", "unsplash": "on Unsplash", + "pexels": "on Pexels", "information": "Information", "download": "Download" }, diff --git a/src/translations/en_US.json b/src/translations/en_US.json index 5980b728..689d040f 100644 --- a/src/translations/en_US.json +++ b/src/translations/en_US.json @@ -13,6 +13,7 @@ "background": { "credit": "Photo by", "unsplash": "on Unsplash", + "pexels": "on Pexels", "information": "Information", "download": "Download" }, diff --git a/src/translations/es.json b/src/translations/es.json index 5f27e8b3..ce7f6a99 100644 --- a/src/translations/es.json +++ b/src/translations/es.json @@ -13,6 +13,7 @@ "background": { "credit": "Foto por", "unsplash": "en Unsplash", + "pexels": "en Pexels", "information": "Información", "download": "Descargar" }, diff --git a/src/translations/fr.json b/src/translations/fr.json index 6a2a2c5d..2d1fe837 100644 --- a/src/translations/fr.json +++ b/src/translations/fr.json @@ -13,6 +13,7 @@ "background": { "credit": "Photo par", "unsplash": "sur Unsplash", + "pexels": "sur Pexels", "information": "Information", "download": "Téléchargement" }, diff --git a/src/translations/nl.json b/src/translations/nl.json index c06a9d3b..0a618554 100644 --- a/src/translations/nl.json +++ b/src/translations/nl.json @@ -13,6 +13,7 @@ "background": { "credit": "Foto van", "unsplash": "on Unsplash", + "pexels": "on Pexels", "information": "Information", "download": "Download" }, diff --git a/src/translations/no.json b/src/translations/no.json index 5cf66b04..476eaa41 100644 --- a/src/translations/no.json +++ b/src/translations/no.json @@ -13,6 +13,7 @@ "background": { "credit": "Bilde av", "unsplash": "on Unsplash", + "pexels": "on Pexels", "information": "Information", "download": "Download" }, diff --git a/src/translations/ru.json b/src/translations/ru.json index 9a149437..a5315774 100644 --- a/src/translations/ru.json +++ b/src/translations/ru.json @@ -13,6 +13,7 @@ "background": { "credit": "Фото", "unsplash": "on Unsplash", + "pexels": "on Pexels", "information": "Information", "download": "Download" }, diff --git a/src/translations/zh_CN.json b/src/translations/zh_CN.json index be47c830..9271a7ba 100644 --- a/src/translations/zh_CN.json +++ b/src/translations/zh_CN.json @@ -13,6 +13,7 @@ "background": { "credit": "图像作者:", "unsplash": "on Unsplash", + "pexels": "on Pexels", "information": "Information", "download": "Download" },