Skip to content

Instantly share code, notes, and snippets.

View samselikoff's full-sized avatar

Sam Selikoff samselikoff

View GitHub Profile
@samselikoff
samselikoff / valtio-use-auth.js
Created March 4, 2022 13:10
Zustand auth store vs Valtio auth store
import firebaseProvider from "@/lib/auth-providers/firebase";
import testProvider from "@/lib/auth-providers/test";
import { proxy, useSnapshot } from "valtio";
import { gql } from "graphql-request";
import request from "@/lib/request";
let isServer = typeof window === "undefined";
let isTest = !isServer && window.Cypress;
let mocksEnabled = process.env.NEXT_PUBLIC_ENABLE_MOCKS;
@samselikoff
samselikoff / signup-test.diff
Created February 22, 2022 17:55
Mocking Firebase + Hasura to test signing up
diff --git a/cypress/integration/signup.spec.js b/cypress/integration/signup.spec.js
index 3654bdd..4d7aefe 100644
--- a/cypress/integration/signup.spec.js
+++ b/cypress/integration/signup.spec.js
@@ -1,5 +1,14 @@
describe("signup", () => {
- it.skip("lets a user signup");
+ it("lets a user signup", () => {
+ cy.visit("/");
+ cy.contains("Sign up").click();
import Spinner from "@/components/Spinner";
import useCurrentUser from "@/hooks/use-current-user";
import useMutation from "@/hooks/use-mutation";
import { Dialog, Switch } from "@headlessui/react";
import * as Icons from "@heroicons/react/solid";
import { format, startOfWeek } from "date-fns";
import { Formik } from "formik";
import { AnimatePresence, motion } from "framer-motion";
import { gql } from "graphql-request";
import { useState, useRef } from "react";
<div className="grid grid-cols-2 mt-8 gap-y-4 gap-x-4">
{categories.map((category) => (
<motion.button
whileTap={{ scale: 1.05 }}
onMouseDown={() => setCategoryPressed(category.id)}
onMouseUp={() => setCategoryPressed(null)}
className="relative w-full py-3 overflow-hidden bg-white border rounded-lg"
key={category.id}
>
<motion.span
import Spinner from "@/components/Spinner";
import useCurrentUser from "@/hooks/use-current-user";
import useMutation from "@/hooks/use-mutation";
import { Dialog, Switch } from "@headlessui/react";
import { CheckIcon } from "@heroicons/react/solid";
import { format, startOfWeek } from "date-fns";
import { Field, Formik } from "formik";
import { motion } from "framer-motion";
import { gql } from "graphql-request";
import { useRef } from "react";
/* TODO: Describe tw-reset */
/*! tailwindcss v2.2.16 | MIT License | https://tailwindcss.com */
/*! modern-normalize v1.1.0 | MIT License | https://github.com/sindresorhus/modern-normalize */
/*
Document
========
*/
@samselikoff
samselikoff / _app.js
Last active August 25, 2021 20:33
From Lesson 9 of my upcoming Egghead course on Tailwind
import Head from "next/head";
import "tailwindcss/tailwind.css";
import "../styles.css";
import Link from "next/link";
import { useRouter } from "next/router";
function MyApp({ Component, pageProps }) {
let router = useRouter();
return (
@samselikoff
samselikoff / authed-swr-provider.js
Created July 19, 2021 04:32
Example useAuth hook using Zustand, SWR and Suspense
import firebase from "firebase/app";
import "firebase/auth";
import { gql, GraphQLClient } from "graphql-request";
import { SWRConfig } from "swr";
import create from "zustand";
import { computed } from "zustand-middleware-computed-state";
const firebaseConfig = {
//
};
@samselikoff
samselikoff / next.config.js
Last active May 6, 2021 14:18
withProse remark plugin that escapes `prose` for MDX components
let { withProse } = require("./src/remark/withProse");
let { withSyntaxHighlighting } = require("./src/remark/withSyntaxHighlighting");
let { withTableOfContents } = require("./src/remark/withTableOfContents");
let { withExamples } = require("./src/remark/withExamples");
let { withLayout } = require("./src/remark/withLayout");
let { withNextLinks } = require("./src/remark/withNextLinks");
let { VueLoaderPlugin } = require("vue-loader");
let path = require("path");
const withMDX = require("@next/mdx")({
@samselikoff
samselikoff / image-cropper.js
Created April 27, 2021 13:27
ImageCropper from Fitness App as of 4/27/21
import { animate, motion, useMotionValue } from "framer-motion";
import { useEffect, useLayoutEffect, useRef, useState } from "react";
import { usePrevious } from "react-use";
import { useGesture } from "react-use-gesture";
export function ImageCropper({
dataURL,
aspectRatio,
crop,
onCropChange,