2021-04-29 03:03:58 +00:00
|
|
|
import React, { useContext } from "react"
|
2021-05-07 03:02:20 +00:00
|
|
|
import { faAt, faClock, faGlobe, faHashtag, faMapPin } from "@fortawesome/free-solid-svg-icons"
|
2021-04-29 14:58:31 +00:00
|
|
|
import ContextRepositoryEditor from "../../contexts/ContextRepositoryEditor"
|
2021-05-18 14:23:54 +00:00
|
|
|
import Badge from "../base/Badge"
|
2021-04-29 02:27:06 +00:00
|
|
|
|
|
|
|
|
2021-04-29 03:03:58 +00:00
|
|
|
const CONDITION_COLORS = {
|
|
|
|
0: "Grey", // Hashtag
|
|
|
|
2: "Yellow", // Time
|
2021-05-07 03:02:20 +00:00
|
|
|
3: "Red", // Coordinates
|
|
|
|
4: "Red", // Place
|
|
|
|
5: "Green", // User
|
2021-04-29 03:03:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const CONDITION_ICONS = {
|
|
|
|
0: faHashtag, // Hashtag
|
|
|
|
2: faClock, // Time
|
2021-05-07 03:02:20 +00:00
|
|
|
3: faGlobe, // Coordinates
|
|
|
|
4: faMapPin, // Place
|
|
|
|
5: faAt, // User
|
2021-04-29 03:03:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-05-18 14:28:51 +00:00
|
|
|
* A {@link Badge} representing a Condition for a filter.
|
2021-04-29 03:03:58 +00:00
|
|
|
*
|
|
|
|
* @param condition - The Condition that this badge represents.
|
|
|
|
* @returns {JSX.Element}
|
|
|
|
* @constructor
|
|
|
|
*/
|
2021-05-18 14:23:54 +00:00
|
|
|
export default function BadgeCondition({ ...condition }) {
|
2021-04-29 03:03:58 +00:00
|
|
|
const { id, type, content } = condition
|
|
|
|
const color = CONDITION_COLORS[type]
|
|
|
|
const icon = CONDITION_ICONS[type]
|
2021-05-11 14:37:15 +00:00
|
|
|
const { removeRawCondition } = useContext(ContextRepositoryEditor)
|
2021-04-29 03:03:58 +00:00
|
|
|
|
2021-05-07 14:30:12 +00:00
|
|
|
let displayedContent = content
|
|
|
|
if(type === 3) {
|
|
|
|
let split = displayedContent.split(" ")
|
|
|
|
let radius = Number.parseFloat(split[1]).toFixed(0)
|
|
|
|
let radiusType = "m"
|
|
|
|
if(radius >= 2000) {
|
|
|
|
radius = Math.round(radius / 1000)
|
|
|
|
radiusType = "km"
|
|
|
|
}
|
|
|
|
let lat = Number(split[2]).toFixed(3)
|
|
|
|
let lng = Number(split[3]).toFixed(3)
|
|
|
|
displayedContent = `${split[0]} ${radius}${radiusType} ${lat} ${lng}`
|
|
|
|
}
|
|
|
|
|
2021-04-29 02:27:06 +00:00
|
|
|
return (
|
2021-05-18 14:23:54 +00:00
|
|
|
<Badge
|
2021-05-07 03:02:20 +00:00
|
|
|
title={id ? `💠 Condition ID: ${id}` : "✨ New Condition"}
|
2021-05-18 14:23:54 +00:00
|
|
|
color={color}
|
|
|
|
icon={icon}
|
|
|
|
onClickDelete={() => {
|
|
|
|
console.debug(`Removing Condition: `, condition)
|
|
|
|
removeRawCondition(condition)
|
|
|
|
}}
|
2021-04-29 03:03:58 +00:00
|
|
|
>
|
2021-05-18 14:23:54 +00:00
|
|
|
{displayedContent}
|
|
|
|
</Badge>
|
2021-04-29 02:27:06 +00:00
|
|
|
)
|
|
|
|
}
|