Skip to content

Instantly share code, notes, and snippets.

View trevorblades's full-sized avatar
🌵
#AlwaysLearning

Trevor Blades trevorblades

🌵
#AlwaysLearning
View GitHub Profile
@trevorblades
trevorblades / gatsby-node.js
Created March 17, 2021 20:11
Querying for something when a Gatsby node is created
import {GraphQLClient, gql} from 'graphql-request';
const client = new GraphQLClient('https://api.shopify.com/graphql', {
headers: {
authorization: 'Bearer MY_TOKEN' // environment variables here
}
});
const GET_PRODUCTS = gql`
query GetProducts($query: String!) {
@trevorblades
trevorblades / auth.js
Last active February 14, 2021 03:33
Knoword auth flow
import axios from 'axios';
import bcrypt from 'bcryptjs';
import {
AuthenticationError,
ForbiddenError,
UserInputError,
gql
} from 'apollo-server-express';
import {Op} from 'sequelize';
import {User} from '../db';
@trevorblades
trevorblades / gatsby-node.js
Created November 13, 2020 21:18
Chakra color mode w/ CSS variables
import React from 'react';
import theme from './src/gatsby-plugin-chakra-ui/theme';
import {getColor} from '@chakra-ui/theme-tools';
// a helper function to create color variables given a variable name and theme keys
function createVar(name, light, dark) {
return `
root.style.setProperty(
'${name}',
mql.matches
@trevorblades
trevorblades / ListPacks.jsx
Created October 5, 2020 19:17
Pagination helpers in AC3
import PackGrid, {CardSkeleton, PacksLoading} from '../PackGrid';
import PackLoader from './PackLoader';
import PropTypes from 'prop-types';
import React, {useEffect, useState} from 'react';
import {NetworkStatus, gql, useQuery} from '@apollo/client';
import {PACK_LISTING_FRAGMENT} from '../../utils';
import {Text} from '@chakra-ui/core';
const LIST_PACKS = gql`
query ListPacks(
@trevorblades
trevorblades / PostLayout.js
Created August 31, 2020 02:25
Auto-generated social images
import PageLayout from './PageLayout';
import PropTypes from 'prop-types';
import React from 'react';
import getShareImage from '@jlengstorf/get-share-image';
import {Helmet} from 'react-helmet';
export default function PostLayout({children, pageContext}) {
const {title, description, tags} = pageContext.frontmatter;
const shareImage = getShareImage({
title,
update packs set old_id = id;
create extension "uuid-ossp";
alter table packs alter column id set data type uuid using (uuid_generate_v4());
update "packWords" P set "packId2" = (select id from packs where old_id = P."packId");
update "games" P set "packId2" = (select id from packs where old_id = P."packId");
drop sequence packs_id_seq;
@trevorblades
trevorblades / block-form.js
Created May 2, 2020 20:15
GitHub-style image uploads
import PropTypes from 'prop-types';
import React, {useState} from 'react';
import {BLOCK_FRAGMENT, CREATE_SIGNED_URL, uploadFile} from '../utils';
import {Box, Button, Flex, Input, Stack, Text, Textarea} from '@chakra-ui/core';
import {gql, useMutation} from '@apollo/client';
const CREATE_BLOCK = gql`
mutation CreateBlock($input: CreateBlockInput!) {
createBlock(input: $input) {
...BlockFragment

test

const foo = 123;
async function uploadFile(file, url, handleProgress) {
return new Promise((resolve, reject) => {
const req = new XMLHttpRequest();
req.upload.addEventListener('progress', handleProgress);
req.addEventListener('load', () => resolve(true));
req.addEventListener('error', () => {
const error = new Error('Upload failed');
reject(error);
});
import {Trick} from '../db';
import {gql} from 'apollo-server';
export const typeDef = gql`
type Attempt {
id: ID
successful: Boolean
offense: Boolean
redos: Int
skaterId: String