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 ( +