stacker.news/components/snl.js

41 lines
1.2 KiB
JavaScript
Raw Normal View History

2023-07-24 18:35:05 +00:00
import Alert from 'react-bootstrap/Alert'
2023-06-20 01:26:34 +00:00
import YouTube from '../svgs/youtube-line.svg'
import { useEffect, useState } from 'react'
import { gql, useQuery } from '@apollo/client'
import { dayPivot } from '../lib/time'
2023-06-20 01:26:34 +00:00
export default function Snl ({ ignorePreference }) {
2023-06-20 01:26:34 +00:00
const [show, setShow] = useState()
const { data } = useQuery(gql`{ snl }`, {
fetchPolicy: 'cache-and-network'
})
useEffect(() => {
2023-07-25 14:14:45 +00:00
const dismissed = window.localStorage.getItem('snl')
2023-08-10 22:35:11 +00:00
if (!ignorePreference && dismissed && dismissed > new Date(dismissed) < datePivot(new Date(), { days: -6 })) {
2023-06-20 01:26:34 +00:00
return
}
setShow(data?.snl)
}, [data, ignorePreference])
2023-06-20 01:26:34 +00:00
if (!show) return null
return (
<div className='d-flex'>
<Alert
2023-07-24 18:35:05 +00:00
variant='info' className='fw-bold mb-3 d-flex py-2 flex-shrink align-items-center'
2023-06-20 01:26:34 +00:00
onClose={() => {
setShow(undefined)
2023-07-25 14:14:45 +00:00
window.localStorage.setItem('snl', new Date())
2023-06-20 01:26:34 +00:00
}}
dismissible
>
<a href='https://www.youtube.com/@stackernews/live'>
2023-07-24 18:35:05 +00:00
<YouTube width={24} height={24} className='me-2 fill-info' />Stacker News Live is streaming this week's top stories
2023-06-20 01:26:34 +00:00
</a>
</Alert>
</div>
)
}