2021-04-29 03:03:58 +00:00
|
|
|
import React, { useContext } from "react"
|
2021-04-29 02:27:06 +00:00
|
|
|
import Style from "./ConditionBadge.module.css"
|
|
|
|
import classNames from "classnames"
|
|
|
|
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"
|
2021-04-29 14:58:31 +00:00
|
|
|
import ButtonSmallX from "../base/ButtonSmallX"
|
2021-04-29 14:23:11 +00:00
|
|
|
import { faAt, faClock, faHashtag, faMapPin } from "@fortawesome/free-solid-svg-icons"
|
2021-04-29 14:58:31 +00:00
|
|
|
import ContextRepositoryEditor from "../../contexts/ContextRepositoryEditor"
|
2021-04-29 02:27:06 +00:00
|
|
|
|
|
|
|
|
2021-04-29 03:03:58 +00:00
|
|
|
const CONDITION_COLORS = {
|
|
|
|
0: "Grey", // Hashtag
|
|
|
|
1: "Red", // Location
|
|
|
|
2: "Yellow", // Time
|
|
|
|
3: "Green", // User
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const CONDITION_ICONS = {
|
|
|
|
0: faHashtag, // Hashtag
|
|
|
|
1: faMapPin, // Location
|
|
|
|
2: faClock, // Time
|
2021-04-29 14:23:11 +00:00
|
|
|
3: faAt, // User
|
2021-04-29 03:03:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A small colored badge representing a Condition for a filter.
|
|
|
|
*
|
|
|
|
* @param condition - The Condition that this badge represents.
|
|
|
|
* @returns {JSX.Element}
|
|
|
|
* @constructor
|
|
|
|
*/
|
2021-04-29 14:17:22 +00:00
|
|
|
export default function ConditionBadge({ ...condition }) {
|
2021-04-29 03:03:58 +00:00
|
|
|
const { id, type, content } = condition
|
|
|
|
const color = CONDITION_COLORS[type]
|
|
|
|
const icon = CONDITION_ICONS[type]
|
|
|
|
const {removeCondition} = useContext(ContextRepositoryEditor)
|
|
|
|
|
2021-04-29 02:27:06 +00:00
|
|
|
return (
|
2021-04-29 03:03:58 +00:00
|
|
|
<div
|
|
|
|
title={`Condition ID: ${id}`}
|
|
|
|
className={classNames(Style.ConditionBadge, Style[`ConditionBadge${color}`])}
|
|
|
|
>
|
2021-04-29 02:27:06 +00:00
|
|
|
<div className={Style.Icon}>
|
|
|
|
<FontAwesomeIcon icon={icon}/>
|
|
|
|
</div>
|
|
|
|
<div>
|
2021-04-29 03:03:58 +00:00
|
|
|
{content}
|
2021-04-29 02:27:06 +00:00
|
|
|
</div>
|
|
|
|
<div>
|
2021-04-29 14:17:22 +00:00
|
|
|
<ButtonSmallX onClick={() => {
|
|
|
|
console.debug(`Removing Condition: `, condition)
|
|
|
|
removeCondition(condition)
|
|
|
|
}}/>
|
2021-04-29 02:27:06 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|