From 9954d8af1d02e6d08cf2a643a3a2e996a9d3f847 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 23 May 2021 15:45:00 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20FilterHasImage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nest_frontend/LocalizationStrings.js | 13 +++-- .../interactive/BoxFilterHasImage.js | 55 +++++++++++++++++++ .../components/interactive/PickerFilter.js | 8 ++- .../components/interactive/SummaryTweet.js | 9 +-- .../components/providers/RepositoryViewer.js | 2 + nest_frontend/objects/Filter.js | 24 +++++++- 6 files changed, 98 insertions(+), 13 deletions(-) create mode 100644 nest_frontend/components/interactive/BoxFilterHasImage.js diff --git a/nest_frontend/LocalizationStrings.js b/nest_frontend/LocalizationStrings.js index d910b7b..7734d2c 100644 --- a/nest_frontend/LocalizationStrings.js +++ b/nest_frontend/LocalizationStrings.js @@ -9,7 +9,7 @@ * "{number} km radius" * ``` */ -export default { +const LOCALIZATION = { // 🇮🇹 it: { appName: "N.E.S.T.", @@ -28,9 +28,10 @@ export default { byZone: "area", byHashtag: "hashtag", byUser: "utente", + byHasImage: "immagine", byTimePeriod: "arco di tempo", byContents: "contenuti", - byHasPlace: "localizzazione attiva?", + byHasPlace: "punto di interesse", timeBefore: "Prima", timeAfter: "Dopo", conditions: "Condizioni", @@ -121,9 +122,10 @@ export default { byZone: "zone", byHashtag: "hashtag", byUser: "user", + byHasImage: "image", byTimePeriod: "time period", byContents: "contents", - byHasPlace: "is localized?", + byHasPlace: "point of interest", timeBefore: "Before", timeAfter: "After", conditions: "Conditions", @@ -214,9 +216,10 @@ export default { byZone: "vyöhykkeen mukaan", byHashtag: "hashtagin mukaan", byUser: "käyttäjän mukaan", + byHasImage: "kuva", byTimePeriod: "aikajakson mukaan", byContents: "sisältö", - byHasPlace: "on paikallistettu?", + byHasPlace: "kiinnostuksen kohde", timeBefore: "Ennen", timeAfter: "Jälkeen", conditions: "Ehdot", @@ -289,4 +292,4 @@ export default { postPop: "Aktiivisimmat käyttäjät", filters: "Suodattimet", }, -} +} \ No newline at end of file diff --git a/nest_frontend/components/interactive/BoxFilterHasImage.js b/nest_frontend/components/interactive/BoxFilterHasImage.js new file mode 100644 index 0000000..75569d2 --- /dev/null +++ b/nest_frontend/components/interactive/BoxFilterHasImage.js @@ -0,0 +1,55 @@ +import React from "react" +import BoxFull from "../base/BoxFull" +import FormInline from "../base/FormInline" +import useRepositoryViewer from "../../hooks/useRepositoryViewer" +import useStrings from "../../hooks/useStrings" +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" +import { faImage, faPlus } from "@fortawesome/free-solid-svg-icons" +import { FilterWithImage } from "../../objects/Filter" +import ButtonIconOnly from "../base/ButtonIconOnly" + + +/** + * A {@link BoxFull} that allows the user to add a {@link FilterWithImage} to a RepositoryViewer. + * + * @param props - Additional props to pass to the box. + * @returns {JSX.Element} + * @constructor + */ +export default function BoxFilterHasImage({ ...props }) { + const strings = useStrings() + + const { appendFilter } = useRepositoryViewer() + + const submit = () => { + appendFilter(new FilterWithImage()) + } + + // TODO: translate this + + return ( + + {strings.searchBy} +   + +   + {strings.byHasImage} + + } + {...props} + > + +
+ {strings.hasImageExplaination} +
+ +
+
+ ) +} diff --git a/nest_frontend/components/interactive/PickerFilter.js b/nest_frontend/components/interactive/PickerFilter.js index 807081c..6850e88 100644 --- a/nest_frontend/components/interactive/PickerFilter.js +++ b/nest_frontend/components/interactive/PickerFilter.js @@ -4,7 +4,7 @@ import { faAt, faClock, faFont, - faHashtag, + faHashtag, faImage, faLocationArrow, faMapMarkerAlt, faMapPin, @@ -43,6 +43,12 @@ export default function PickerFilter({ ...props }) { name={"user"} icon={faAt} /> + : null} {filterTab === "hashtag" ? : null} {filterTab === "user" ? : null} + {filterTab === "image" ? : null} {filterTab === "time" ? : null} {filterTab === "place" ? : null} {filterTab === "location" ? : null} diff --git a/nest_frontend/objects/Filter.js b/nest_frontend/objects/Filter.js index a18584c..a0d13cc 100644 --- a/nest_frontend/objects/Filter.js +++ b/nest_frontend/objects/Filter.js @@ -3,7 +3,7 @@ import { faClock, faFilter, faFont, - faHashtag, + faHashtag, faImage, faLocationArrow, faMapMarkerAlt, faMapPin, @@ -220,3 +220,25 @@ export class FilterInsideTimeRay extends Filter { } } } + + +/** + * Check if a tweet has an associated `image_url`. + */ +export class FilterWithImage extends Filter { + constructor(negate = false) { + super(negate) + } + + check(tweet) { + return Boolean(tweet["image_url"]) + } + + display() { + return { + color: "Grey", + icon: faImage, + children: "" + } + } +} \ No newline at end of file