diff --git a/api/resolvers/admin.js b/api/resolvers/admin.js new file mode 100644 index 00000000..1032b9a0 --- /dev/null +++ b/api/resolvers/admin.js @@ -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 + } + } +} diff --git a/api/resolvers/index.js b/api/resolvers/index.js index a8ba9572..a4286ef8 100644 --- a/api/resolvers/index.js +++ b/api/resolvers/index.js @@ -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 }] diff --git a/api/typeDefs/admin.js b/api/typeDefs/admin.js new file mode 100644 index 00000000..704219bc --- /dev/null +++ b/api/typeDefs/admin.js @@ -0,0 +1,11 @@ +import { gql } from 'apollo-server-micro' + +export default gql` + extend type Query { + snl: Boolean! + } + + extend type Mutation { + onAirToggle: Boolean! + } +` diff --git a/api/typeDefs/index.js b/api/typeDefs/index.js index 50d172b3..0745be29 100644 --- a/api/typeDefs/index.js +++ b/api/typeDefs/index.js @@ -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] diff --git a/components/snl.js b/components/snl.js new file mode 100644 index 00000000..6fe5b5de --- /dev/null +++ b/components/snl.js @@ -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 ( +
+ { + setShow(undefined) + localStorage.setItem('snl', new Date()) + }} + dismissible + > + + Stacker News Live is streaming this week's top stories + + +
+ ) +} diff --git a/pages/index.js b/pages/index.js index 9b3e141e..38ebb32e 100644 --- a/pages/index.js +++ b/pages/index.js @@ -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 ( + onAirToggle + } + }) + } + } + ) + + const { data } = useQuery(gql`{ snl }`, { + fetchPolicy: 'cache-only' + }) + + return ( + + + + + ) +} diff --git a/prisma/migrations/20230620011238_snl/migration.sql b/prisma/migrations/20230620011238_snl/migration.sql new file mode 100644 index 00000000..a2738df1 --- /dev/null +++ b/prisma/migrations/20230620011238_snl/migration.sql @@ -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'); diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 3f6972cd..b3b9a89b 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -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]) @@ -573,4 +578,4 @@ model ThreadSubscription { @@id([userId, itemId]) @@index([createdAt]) -} \ No newline at end of file +} diff --git a/svgs/youtube-line.svg b/svgs/youtube-line.svg new file mode 100644 index 00000000..91cc4955 --- /dev/null +++ b/svgs/youtube-line.svg @@ -0,0 +1 @@ + \ No newline at end of file