Change poll icon color when active (#680) (#898)

This commit is contained in:
JP Melanson 2024-03-06 15:02:48 -05:00 committed by GitHub
parent 2fc1ef44dd
commit ecf859ee4c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 20 additions and 1 deletions

View File

@ -17,6 +17,7 @@ import { useRouter } from 'next/router'
import { Badge } from 'react-bootstrap'
import AdIcon from '../svgs/advertisement-fill.svg'
import { DownZap } from './dont-link-this'
import { timeLeft } from '../lib/time'
export function SearchTitle ({ title }) {
return reactStringReplace(title, /\*\*\*([^*]+)\*\*\*/g, (match, i) => {
@ -69,7 +70,7 @@ export default function Item ({ item, rank, belowTitle, right, full, children, s
}} ref={titleRef} className={`${styles.title} text-reset me-2`}
>
{item.searchTitle ? <SearchTitle title={item.searchTitle} /> : item.title}
{item.pollCost && <span className={styles.icon}> <PollIcon className='fill-grey ms-1' height={14} width={14} /></span>}
{item.pollCost && <PollIndicator item={item} />}
{item.bounty > 0 &&
<span className={styles.icon}>
<ActionTooltip notForm overlayText={`${numWithUnits(item.bounty)} ${item.bountyPaidTo?.length ? ' paid' : ' bounty'}`}>
@ -139,3 +140,21 @@ export function ItemSkeleton ({ rank, children }) {
</>
)
}
function PollIndicator ({ item }) {
const hasExpiration = !!item.pollExpiresAt
const timeRemaining = timeLeft(new Date(item.pollExpiresAt))
const isActive = !hasExpiration || !!timeRemaining
return (
<span className={styles.icon} title={isActive ? 'active' : 'results in'}>
<PollIcon
className={`${
isActive
? 'fill-success'
: 'fill-grey'
} ms-1`} height={14} width={14}
/>
</span>
)
}