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'
|
2023-07-23 15:08:43 +00:00
|
|
|
import { dayPivot } from '../lib/time'
|
2023-06-20 01:26:34 +00:00
|
|
|
|
2023-07-23 15:08:43 +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-07-23 15:08:43 +00:00
|
|
|
if (!ignorePreference && dismissed && dismissed > new Date(dismissed) < dayPivot(new Date(), -6)) {
|
2023-06-20 01:26:34 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-07-23 15:08:43 +00:00
|
|
|
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>
|
|
|
|
)
|
|
|
|
}
|