snl live banner

This commit is contained in:
keyan 2023-06-19 20:26:34 -05:00
parent 59ee15b551
commit 747371a4e4
10 changed files with 133 additions and 9 deletions

18
api/resolvers/admin.js Normal file
View File

@ -0,0 +1,18 @@
export default {
Query: {
snl: async (parent, _, { models }) => {
const { live } = await models.snl.findFirst()
return live
}
},
Mutation: {
onAirToggle: async (parent, _, { models, me }) => {
if (me.id !== 616) {
throw new Error('not an admin')
}
const { id, live } = await models.snl.findFirst()
await models.snl.update({ where: { id }, data: { live: !live } })
return !live
}
}
}

View File

@ -13,6 +13,7 @@ import rewards from './rewards'
import referrals from './referrals'
import price from './price'
import { GraphQLJSONObject } from 'graphql-type-json'
import admin from './admin'
export default [user, item, message, wallet, lnurl, notifications, invite, sub,
upload, search, growth, rewards, referrals, price, { JSONObject: GraphQLJSONObject }]
upload, search, growth, rewards, referrals, price, admin, { JSONObject: GraphQLJSONObject }]

11
api/typeDefs/admin.js Normal file
View File

@ -0,0 +1,11 @@
import { gql } from 'apollo-server-micro'
export default gql`
extend type Query {
snl: Boolean!
}
extend type Mutation {
onAirToggle: Boolean!
}
`

View File

@ -13,6 +13,7 @@ import growth from './growth'
import rewards from './rewards'
import referrals from './referrals'
import price from './price'
import admin from './admin'
const link = gql`
type Query {
@ -29,4 +30,4 @@ const link = gql`
`
export default [link, user, item, message, wallet, lnurl, notifications, invite,
sub, upload, growth, rewards, referrals, price]
sub, upload, growth, rewards, referrals, price, admin]

41
components/snl.js Normal file
View File

@ -0,0 +1,41 @@
import { Alert } from 'react-bootstrap'
import YouTube from '../svgs/youtube-line.svg'
import { useEffect, useState } from 'react'
import { gql, useQuery } from '@apollo/client'
export default function Snl () {
const [show, setShow] = useState()
const { data } = useQuery(gql`{ snl }`, {
fetchPolicy: 'cache-and-network'
})
useEffect(() => {
const dismissed = localStorage.getItem('snl')
if (dismissed && dismissed > new Date(dismissed) < new Date(new Date().setDate(new Date().getDate() - 6))) {
return
}
if (data?.snl) {
setShow(true)
}
}, [data])
if (!show) return null
return (
<div className='d-flex'>
<Alert
variant='info' className='font-weight-bold mb-3 d-flex py-2 flex-shrink align-items-center'
onClose={() => {
setShow(undefined)
localStorage.setItem('snl', new Date())
}}
dismissible
>
<a href='https://www.youtube.com/@stackernews/live'>
<YouTube width={24} height={24} className='mr-2 fill-info' />Stacker News Live is streaming this week's top stories
</a>
</Alert>
</div>
)
}

View File

@ -2,12 +2,14 @@ import Layout from '../components/layout'
import Items from '../components/items'
import { getGetServerSideProps } from '../api/ssrApollo'
import { ITEMS } from '../fragments/items'
import Snl from '../components/snl'
export const getServerSideProps = getGetServerSideProps(ITEMS)
export default function Index ({ data: { items: { items, pins, cursor } } }) {
return (
<Layout>
<Snl />
<Items
items={items} pins={pins} cursor={cursor}
rank

34
pages/live.js Normal file
View File

@ -0,0 +1,34 @@
import { Button } from 'react-bootstrap'
import LayoutCenter from '../components/layout-center'
import Snl from '../components/snl'
import { gql } from 'apollo-server-micro'
import { useMutation, useQuery } from '@apollo/client'
export default function Index () {
const [toggle] = useMutation(
gql`
mutation onAirToggle {
onAirToggle
}`, {
update (cache, { data: { onAirToggle } }) {
cache.modify({
id: 'ROOT_QUERY',
fields: {
snl: () => onAirToggle
}
})
}
}
)
const { data } = useQuery(gql`{ snl }`, {
fetchPolicy: 'cache-only'
})
return (
<LayoutCenter>
<Snl />
<Button variant={data?.snl ? 'primary' : 'danger'} onClick={toggle}>go: {data?.snl ? 'off' : 'on'} air</Button>
</LayoutCenter>
)
}

View File

@ -0,0 +1,10 @@
-- CreateTable
CREATE TABLE "Snl" (
"id" SERIAL NOT NULL,
"live" BOOLEAN NOT NULL DEFAULT false,
PRIMARY KEY ("id")
);
INSERT INTO "Snl" ("live") VALUES (false);
INSERT INTO "users" ("name") VALUES ('live');

View File

@ -10,6 +10,11 @@ generator client {
provider = "prisma-client-js"
}
model Snl {
id Int @id @default(autoincrement())
live Boolean @default(false)
}
model User {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map(name: "created_at")
@ -86,7 +91,7 @@ model User {
greeterMode Boolean @default(false)
Earn Earn[]
Upload Upload[] @relation(name: "Uploads")
Upload Upload[] @relation(name: "Uploads")
PollVote PollVote[]
Donation Donation[]
ReferralAct ReferralAct[]
@ -301,11 +306,11 @@ model Item {
// fields for polls
pollCost Int?
User User[]
PollOption PollOption[]
PollVote PollVote[]
Bookmark Bookmark[]
ThreadSubscription ThreadSubscription[]
User User[]
PollOption PollOption[]
PollVote PollVote[]
Bookmark Bookmark[]
ThreadSubscription ThreadSubscription[]
@@index([weightedVotes])
@@index([weightedDownVotes])

1
svgs/youtube-line.svg Normal file
View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19.6069 6.99482C19.5307 6.69695 19.3152 6.47221 19.0684 6.40288C18.6299 6.28062 16.501 6 12.001 6C7.50098 6 5.37252 6.28073 4.93225 6.40323C4.68776 6.47123 4.4723 6.69593 4.3951 6.99482C4.2863 7.41923 4.00098 9.19595 4.00098 12C4.00098 14.804 4.2863 16.5808 4.3954 17.0064C4.47126 17.3031 4.68676 17.5278 4.93251 17.5968C5.37252 17.7193 7.50098 18 12.001 18C16.501 18 18.6299 17.7194 19.0697 17.5968C19.3142 17.5288 19.5297 17.3041 19.6069 17.0052C19.7157 16.5808 20.001 14.8 20.001 12C20.001 9.2 19.7157 7.41923 19.6069 6.99482ZM21.5442 6.49818C22.001 8.28 22.001 12 22.001 12C22.001 12 22.001 15.72 21.5442 17.5018C21.2897 18.4873 20.547 19.2618 19.6056 19.5236C17.8971 20 12.001 20 12.001 20C12.001 20 6.10837 20 4.39637 19.5236C3.45146 19.2582 2.70879 18.4836 2.45774 17.5018C2.00098 15.72 2.00098 12 2.00098 12C2.00098 12 2.00098 8.28 2.45774 6.49818C2.71227 5.51273 3.45495 4.73818 4.39637 4.47636C6.10837 4 12.001 4 12.001 4C12.001 4 17.8971 4 19.6056 4.47636C20.5505 4.74182 21.2932 5.51636 21.5442 6.49818ZM10.001 15.5V8.5L16.001 12L10.001 15.5Z"></path></svg>

After

Width:  |  Height:  |  Size: 1.1 KiB