From 04af2350b688f8d655d9594f1cc83244ca0b781e Mon Sep 17 00:00:00 2001 From: Isaac Date: Wed, 16 Nov 2022 01:23:53 +0000 Subject: [PATCH] feat: don't show image again --- .../sections/background/Background.jsx | 4 +- .../widgets/background/Background.jsx | 10 ++-- .../widgets/background/PhotoInformation.jsx | 58 ++++++++++++++----- src/translations/de_DE.json | 8 ++- src/translations/en_GB.json | 6 +- src/translations/en_US.json | 8 ++- src/translations/es-419.json | 8 ++- src/translations/es.json | 8 ++- src/translations/fr.json | 8 ++- src/translations/id_ID.json | 8 ++- src/translations/nl.json | 8 ++- src/translations/no.json | 8 ++- src/translations/ru.json | 8 ++- src/translations/tr_TR.json | 8 ++- src/translations/zh_CN.json | 8 ++- 15 files changed, 122 insertions(+), 44 deletions(-) diff --git a/src/components/modals/main/settings/sections/background/Background.jsx b/src/components/modals/main/settings/sections/background/Background.jsx index 7f551956..933dbf42 100644 --- a/src/components/modals/main/settings/sections/background/Background.jsx +++ b/src/components/modals/main/settings/sections/background/Background.jsx @@ -67,7 +67,7 @@ export default class BackgroundSettings extends PureComponent { */} diff --git a/src/components/widgets/background/Background.jsx b/src/components/widgets/background/Background.jsx index 228b766e..fe034980 100644 --- a/src/components/widgets/background/Background.jsx +++ b/src/components/widgets/background/Background.jsx @@ -146,9 +146,9 @@ export default class Background extends PureComponent { let apiCategories; try { - let apiCategories = JSON.parse(localStorage.getItem('apiCategories')) + apiCategories = JSON.parse(localStorage.getItem('apiCategories')) } catch (error) { - let apiCategories = localStorage.getItem('apiCategories') + apiCategories = localStorage.getItem('apiCategories') } const type = localStorage.getItem('backgroundType'); @@ -161,6 +161,7 @@ export default class Background extends PureComponent { // API background const backgroundAPI = localStorage.getItem('backgroundAPI'); const apiQuality = localStorage.getItem('apiQuality'); + const backgroundExclude = JSON.parse(localStorage.getItem('backgroundExclude')); let requestURL, data; switch (backgroundAPI) { @@ -172,7 +173,7 @@ export default class Background extends PureComponent { break; // Defaults to Mue default: - requestURL = `${variables.constants.API_URL}/images/random?categories=${apiCategories}&quality=${apiQuality}`; + requestURL = `${variables.constants.API_URL}/images/random?categories=${apiCategories}&quality=${apiQuality}&excludes=${backgroundExclude}`; break; } @@ -415,7 +416,8 @@ export default class Background extends PureComponent { (this.state.type === 'api' && localStorage.getItem('backgroundAPI') !== this.state.currentAPI) || (this.state.type === 'custom' && - localStorage.getItem('customBackground') !== this.state.url) + localStorage.getItem('customBackground') !== this.state.url) || + JSON.parse(localStorage.getItem('backgroundExclude')).includes(this.state.photoInfo.pun) ) { return refresh(); } diff --git a/src/components/widgets/background/PhotoInformation.jsx b/src/components/widgets/background/PhotoInformation.jsx index ce1f026e..7a9e45d1 100644 --- a/src/components/widgets/background/PhotoInformation.jsx +++ b/src/components/widgets/background/PhotoInformation.jsx @@ -1,6 +1,7 @@ import variables from 'modules/variables'; import { useState, memo } from 'react'; import Favourite from './Favourite'; +import EventBus from 'modules/helpers/eventbus'; import { MdInfo, MdLocationOn, @@ -11,7 +12,8 @@ import { MdIosShare as Share, MdSource as Source, MdFavorite as MdFavourite, - MdCategory as Category + MdCategory as Category, + MdVisibilityOff as VisibilityOff } from 'react-icons/md'; import Tooltip from '../../helpers/tooltip/Tooltip'; import Modal from 'react-modal'; @@ -29,13 +31,24 @@ const formatText = (text) => { const downloadImage = async (info) => { const link = document.createElement('a'); link.href = await toDataURL(info.url); - link.download = `mue-${formatText(info.credit)}-${formatText(info.location)}.jpg`; + link.download = `mue-${formatText(info.credit)}-${formatText(info.location)}.jpg`; // image is more likely to be webp or avif btw document.body.appendChild(link); link.click(); document.body.removeChild(link); variables.stats.postEvent('feature', 'Background download'); }; +const excludeImage = async (info) => { + // eslint-disable-next-line no-restricted-globals + const confirmed = confirm(variables.getMessage('widgets.background.exclude_confirm', { category: info.category })); + if (!confirmed) return; + let backgroundExclude = JSON.parse(localStorage.getItem('backgroundExclude')); + backgroundExclude.push(info.pun); + backgroundExclude = JSON.stringify(backgroundExclude); + localStorage.setItem('backgroundExclude', backgroundExclude); + EventBus.dispatch('refresh', 'background'); +}; + function PhotoInformation({ info, url, api }) { const [width, setWidth] = useState(0); const [height, setHeight] = useState(0); @@ -97,15 +110,15 @@ function PhotoInformation({ info, url, api }) { const ddgProxy = localStorage.getItem('ddgProxy') === 'true'; // get resolution -// const img = new Image(); -// img.onload = (event) => { -// setWidth(event.target.width); -// setHeight(event.target.height); -// }; -// img.src = -// ddgProxy && !info.offline && !url.startsWith('data:') -// ? variables.constants.DDG_IMAGE_PROXY + url -// : url; + const img = new Image(); + img.onload = (event) => { + setWidth(event.target.width); + setHeight(event.target.height); + }; + img.src = + ddgProxy && !info.offline && !url.startsWith('data:') + ? variables.constants.DDG_IMAGE_PROXY + url + : url; // info is still there because we want the favourite button to work if (localStorage.getItem('photoInformation') === 'false') { @@ -284,9 +297,18 @@ function PhotoInformation({ info, url, api }) {
- - {api.charAt(0).toUpperCase() + api.slice(1)} - + {info.photoURL + ? ( + + {api.charAt(0).toUpperCase() + api.slice(1)} + + ) + : ( + + {api.charAt(0).toUpperCase() + api.slice(1)} + + ) + }
) : null} @@ -308,6 +330,14 @@ function PhotoInformation({ info, url, api }) { downloadImage(info)} /> ) : null} + {info.pun ? ( + + excludeImage(info)} /> + + ) : null} ) : null} diff --git a/src/translations/de_DE.json b/src/translations/de_DE.json index 072fb37a..9988e279 100644 --- a/src/translations/de_DE.json +++ b/src/translations/de_DE.json @@ -24,6 +24,9 @@ "resolution": "Resolution", "source": "Source", "category": "Category", + "exclude": "Don't show again", + "exclude_confirm": "Are you sure you don't want to see this image again?\nNote: if you don't like \"{category}\" images, you can deselect the category in the background source settings.", + "categories": "Categories", "photo": "Photo", "on": "on" }, @@ -194,7 +197,7 @@ "transition": "Weicher übergang", "photo_information": "Foto-Informationen anzeigen", "show_map": "Show location map on photo information if available", - "category": "Kategorie", + "categories": "Categories", "buttons": { "title": "Schaltflächen", "view": "Vollbild", @@ -263,7 +266,8 @@ "hour": "Stunde", "day": "Tag", "month": "Monat" - } + }, + "category": "Kategorie" }, "search": { "title": "Suche", diff --git a/src/translations/en_GB.json b/src/translations/en_GB.json index 6cc9eaf2..c19936fc 100644 --- a/src/translations/en_GB.json +++ b/src/translations/en_GB.json @@ -23,7 +23,9 @@ "camera": "Camera", "resolution": "Resolution", "source": "Source", - "category": "Category" + "category": "Category", + "exclude": "Don't show again", + "exclude_confirm": "Are you sure you don't want to see this image again?\nNote: if you don't like \"{category}\" images, you can deselect the category in the background source settings." }, "search": "Search", "quicklinks": { @@ -186,7 +188,7 @@ "transition": "Fade-in transition", "photo_information": "Show photo information", "show_map": "Show location map on photo information if available", - "category": "Category", + "categories": "Categories", "buttons": { "title": "Buttons", "view": "Maximise", diff --git a/src/translations/en_US.json b/src/translations/en_US.json index 9130cc09..6de50123 100644 --- a/src/translations/en_US.json +++ b/src/translations/en_US.json @@ -24,6 +24,9 @@ "resolution": "Resolution", "source": "Source", "category": "Category", + "exclude": "Don't show again", + "exclude_confirm": "Are you sure you don't want to see this image again?\nNote: if you don't like \"{category}\" images, you can deselect the category in the background source settings.", + "categories": "Categories", "photo": "Photo", "on": "on" }, @@ -194,7 +197,7 @@ "transition": "Fade-in transition", "photo_information": "Show photo information", "show_map": "Show location map on photo information if available", - "category": "Category", + "categories": "Categories", "buttons": { "title": "Buttons", "view": "Maximize", @@ -263,7 +266,8 @@ "hour": "Hour", "day": "Day", "month": "Month" - } + }, + "category": "Category" }, "search": { "title": "Search", diff --git a/src/translations/es-419.json b/src/translations/es-419.json index 51f16e45..29884727 100644 --- a/src/translations/es-419.json +++ b/src/translations/es-419.json @@ -24,6 +24,9 @@ "resolution": "Resolution", "source": "Source", "category": "Category", + "exclude": "Don't show again", + "exclude_confirm": "Are you sure you don't want to see this image again?\nNote: if you don't like \"{category}\" images, you can deselect the category in the background source settings.", + "categories": "Categories", "photo": "Photo", "on": "on" }, @@ -188,7 +191,7 @@ "transition": "Transición fade-in", "photo_information": "Ver información de la foto", "show_map": "Mostrar el mapa de la ubicación en la información de la foto si está disponible", - "category": "Categoría", + "categories": "Categories", "buttons": { "title": "Botones", "view": "Ver", @@ -257,7 +260,8 @@ "hour": "Hora", "day": "Día", "month": "Mes" - } + }, + "category": "Categoría" }, "search": { "title": "Búsqueda", diff --git a/src/translations/es.json b/src/translations/es.json index 9fb32aeb..318a0d76 100644 --- a/src/translations/es.json +++ b/src/translations/es.json @@ -24,6 +24,9 @@ "resolution": "Resolution", "source": "Source", "category": "Category", + "exclude": "Don't show again", + "exclude_confirm": "Are you sure you don't want to see this image again?\nNote: if you don't like \"{category}\" images, you can deselect the category in the background source settings.", + "categories": "Categories", "photo": "Photo", "on": "on" }, @@ -194,7 +197,7 @@ "transition": "Transición fade-in", "photo_information": "Ver información de la foto", "show_map": "Mostrar el mapa de la ubicación en la información de la foto si está disponible", - "category": "Categoría", + "categories": "Categories", "buttons": { "title": "Botones", "view": "Ver", @@ -263,7 +266,8 @@ "hour": "Hora", "day": "Día", "month": "Mes" - } + }, + "category": "Categoría" }, "search": { "title": "Búsqueda", diff --git a/src/translations/fr.json b/src/translations/fr.json index 42352d12..9827605b 100644 --- a/src/translations/fr.json +++ b/src/translations/fr.json @@ -24,6 +24,9 @@ "resolution": "Resolution", "source": "Source", "category": "Category", + "exclude": "Don't show again", + "exclude_confirm": "Are you sure you don't want to see this image again?\nNote: if you don't like \"{category}\" images, you can deselect the category in the background source settings.", + "categories": "Categories", "photo": "Photo", "on": "on" }, @@ -194,7 +197,7 @@ "transition": "Transition en fondu", "photo_information": "Show photo information", "show_map": "Show location map on photo information if available", - "category": "Catégorie", + "categories": "Categories", "buttons": { "title": "Boutons", "view": "Mode vue", @@ -263,7 +266,8 @@ "hour": "Hour", "day": "Day", "month": "Month" - } + }, + "category": "Catégorie" }, "search": { "title": "Barre de Recherche", diff --git a/src/translations/id_ID.json b/src/translations/id_ID.json index db6e67f7..713137b4 100644 --- a/src/translations/id_ID.json +++ b/src/translations/id_ID.json @@ -24,6 +24,9 @@ "resolution": "Resolution", "source": "Source", "category": "Category", + "exclude": "Don't show again", + "exclude_confirm": "Are you sure you don't want to see this image again?\nNote: if you don't like \"{category}\" images, you can deselect the category in the background source settings.", + "categories": "Categories", "photo": "Photo", "on": "on" }, @@ -194,7 +197,7 @@ "transition": "Transisi Fade-in", "photo_information": "Tampilkan informasi foto", "show_map": "Tampilkan informasi lokasi foto jika ada", - "category": "Kategori", + "categories": "Categories", "buttons": { "title": "Aksi", "view": "Layar Penuh", @@ -263,7 +266,8 @@ "hour": "Jam", "day": "Hari", "month": "Bulan" - } + }, + "category": "Kategori" }, "search": { "title": "Cari", diff --git a/src/translations/nl.json b/src/translations/nl.json index 14d1c76f..6f76ef48 100644 --- a/src/translations/nl.json +++ b/src/translations/nl.json @@ -24,6 +24,9 @@ "resolution": "Resolution", "source": "Source", "category": "Category", + "exclude": "Don't show again", + "exclude_confirm": "Are you sure you don't want to see this image again?\nNote: if you don't like \"{category}\" images, you can deselect the category in the background source settings.", + "categories": "Categories", "photo": "Photo", "on": "on" }, @@ -194,7 +197,7 @@ "transition": "Fade-in transition", "photo_information": "Show photo information", "show_map": "Show location map on photo information if available", - "category": "Category", + "categories": "Categories", "buttons": { "title": "Buttons", "view": "Weergave", @@ -263,7 +266,8 @@ "hour": "Hour", "day": "Day", "month": "Month" - } + }, + "category": "Category" }, "search": { "title": "Zoekbalk", diff --git a/src/translations/no.json b/src/translations/no.json index 7d36fc6c..810d850b 100644 --- a/src/translations/no.json +++ b/src/translations/no.json @@ -24,6 +24,9 @@ "resolution": "Resolution", "source": "Source", "category": "Category", + "exclude": "Don't show again", + "exclude_confirm": "Are you sure you don't want to see this image again?\nNote: if you don't like \"{category}\" images, you can deselect the category in the background source settings.", + "categories": "Categories", "photo": "Photo", "on": "on" }, @@ -194,7 +197,7 @@ "transition": "Fade-in transition", "photo_information": "Show photo information", "show_map": "Show location map on photo information if available", - "category": "Category", + "categories": "Categories", "buttons": { "title": "Buttons", "view": "Maximise", @@ -263,7 +266,8 @@ "hour": "Hour", "day": "Day", "month": "Month" - } + }, + "category": "Category" }, "search": { "title": "Søkebar", diff --git a/src/translations/ru.json b/src/translations/ru.json index a4596890..05d30478 100644 --- a/src/translations/ru.json +++ b/src/translations/ru.json @@ -24,6 +24,9 @@ "resolution": "Resolution", "source": "Source", "category": "Category", + "exclude": "Don't show again", + "exclude_confirm": "Are you sure you don't want to see this image again?\nNote: if you don't like \"{category}\" images, you can deselect the category in the background source settings.", + "categories": "Categories", "photo": "Photo", "on": "on" }, @@ -194,7 +197,7 @@ "transition": "Fade-in transition", "photo_information": "Show photo information", "show_map": "Show location map on photo information if available", - "category": "Category", + "categories": "Categories", "buttons": { "title": "Buttons", "view": "Просмотр", @@ -263,7 +266,8 @@ "hour": "Hour", "day": "Day", "month": "Month" - } + }, + "category": "Category" }, "search": { "title": "Панель поиска", diff --git a/src/translations/tr_TR.json b/src/translations/tr_TR.json index 85ebf0a0..7a01d21c 100644 --- a/src/translations/tr_TR.json +++ b/src/translations/tr_TR.json @@ -24,6 +24,9 @@ "resolution": "Resolution", "source": "Source", "category": "Category", + "exclude": "Don't show again", + "exclude_confirm": "Are you sure you don't want to see this image again?\nNote: if you don't like \"{category}\" images, you can deselect the category in the background source settings.", + "categories": "Categories", "photo": "Photo", "on": "on" }, @@ -194,7 +197,7 @@ "transition": "Geçiş Sırasında Solma", "photo_information": "Fotoğraf Bilgilerini Göster", "show_map": "Varsa Fotoğraf Bilgilerinde Konum Bilgisini Göster", - "category": "Kategori", + "categories": "Categories", "buttons": { "title": "Butonlar", "view": "Arka Planı Görüntüle", @@ -263,7 +266,8 @@ "hour": "Saatte Bir", "day": "Günde Bir", "month": "Ayda Bir" - } + }, + "category": "Kategori" }, "search": { "title": "Arama", diff --git a/src/translations/zh_CN.json b/src/translations/zh_CN.json index 9a478e6d..2040e4cd 100644 --- a/src/translations/zh_CN.json +++ b/src/translations/zh_CN.json @@ -24,6 +24,9 @@ "resolution": "Resolution", "source": "Source", "category": "Category", + "exclude": "Don't show again", + "exclude_confirm": "Are you sure you don't want to see this image again?\nNote: if you don't like \"{category}\" images, you can deselect the category in the background source settings.", + "categories": "Categories", "photo": "Photo", "on": "on" }, @@ -194,7 +197,7 @@ "transition": "过渡动画", "photo_information": "显示图片信息", "show_map": "在图片信息内显示位置信息 (如果可用)", - "category": "分类", + "categories": "Categories", "buttons": { "title": "显示顶部按钮", "view": "仅显示背景", @@ -263,7 +266,8 @@ "hour": "每小时", "day": "每天", "month": "每月" - } + }, + "category": "分类" }, "search": { "title": "搜索栏",