Skip to content

Instantly share code, notes, and snippets.

View ghankerson's full-sized avatar

Geoff Hankerson ghankerson

  • American Public Media
View GitHub Profile
"use client";
import { useState } from "react";
import { useForm } from "react-hook-form";
import { Prisma } from "@prisma/client";
import Song from './Song';
interface PollProps {
poll: Prisma.pollsSelect;
}
import React, { ReactNode } from 'react';
import { Notifier } from '@airbrake/browser';
interface Props {
fallbackUI?: ReactNode;
}
interface StateProps {
hasError: boolean;
}
@ghankerson
ghankerson / viafoura.jsx
Last active December 13, 2021 20:06
Viafoura/React/Next JS/Single page app implementation
import Head from 'next/head';
import { useRouter } from 'next/router';
import loadScript from '../../utils/loadScript';
const Content = ({
useViafoura,
}) => {
const router = useRouter();
const source = '//cdn.viafoura.net/vf-v2.js';
const [viaFouraReady, setViafouraReady] = useState(false);
@ghankerson
ghankerson / loadScript.js
Last active December 13, 2021 19:19
Abbreviated NextJS/React Viafoura Implementation loadScript
const loadScript = function(id, src, callback) {
const existingScript = document.getElementById(id);
if (!existingScript) {
const script = document.createElement('script');
script.src = src;
script.id = id;
document.body.appendChild(script);
script.onload = () => {
@ghankerson
ghankerson / audio.html
Created June 2, 2020 21:11
HTML Audio tag for live stream
<audio controls>
<source src="https://news-utility.stream.publicradio.org/news-utility.aac" type="audio/aac">
<source src="https://news-utility.stream.publicradio.org/news-utility.mp3" type="audio/mpeg">
</audio>
import fetch from 'cross-fetch';
import { ApolloClient } from 'apollo-client';
import { createHttpLink } from 'apollo-link-http';
import { InMemoryCache } from 'apollo-cache-inmemory';
import FragmentMatcher from './FragmentMatcher';
const cache = new InMemoryCache({ fragmentMatcher: FragmentMatcher }).restore(window.__APOLLO_STATE__);
export function client(graphqlEnv) {
return new ApolloClient({
import React from 'react';
import ReactDOM from 'react-dom/server';
import { ApolloProvider, renderToStringWithData } from 'react-apollo';
import { HelmetProvider } from 'react-helmet-async';
import { ServerLocation } from 'apm-titan';
// import { client } from '../shared/graphql/graphqlClient';
import App from '../shared/App';
import fs from 'fs';
import os from 'os';
import {
import App from '../shared/App';
import React from 'react';
import { hydrate } from 'react-dom';
import { ApolloProvider } from 'react-apollo';
import { HelmetProvider } from 'react-helmet-async';
import { client } from '../shared/graphql/graphqlClient';
import '@babel/polyfill';
const graphqlEnv = window.location.href.match(/local|dev/) ? '-dev' : '';
import React, { useContext } from 'react';
import PropTypes from 'prop-types';
import { Teaser, Pagination, Heading } from 'apm-titan';
import { Image } from 'apm-mimas';
import AudioPlayButton from '../AudioPlayButton/AudioPlayButton';
import { format } from 'date-fns';
import { Body } from 'amat-react';
import { truncateAmat } from '../../utils/utils';
import Icon from '../Icon/Icon';
import MetaTags from '../../MetaTags/MetaTags';
import { gql } from 'apollo-boost';
export function episodesQuery(contextSlug, pageNum) {
return gql`
{
episodesList: collection(contentAreaSlug: "${contextSlug}", slug: "${contextSlug}" ) {
id
title
results(page: ${pageNum}, pageSize: 18) {
nextPage