Skip to content

Instantly share code, notes, and snippets.

View samselikoff's full-sized avatar

Sam Selikoff samselikoff

View GitHub Profile
@samselikoff
samselikoff / 1-PictureForm.js
Last active June 8, 2023 02:04
Diff of the PictureForm component from "Let's build a feature – Cropped Image Uploads!" https://youtu.be/W5__zfYrtt8
import Button from "@/components/Button";
import ImageCropper, {
getCroppedImage,
getDataURLFromFile,
} from "@/components/ImageCropper";
import Modal from "@/components/Modal";
import useCurrentUser from "@/hooks/use-current-user";
import useMutation from "@/hooks/use-mutation";
import { UserIcon } from "@heroicons/react/outline";
import { gql } from "graphql-request";
import { isTest } from "@/lib/constants";
import { Dialog } from "@headlessui/react";
import { motion } from "framer-motion";
const TRANSITIONS = {
DURATION: !isTest ? 0.5 : 0,
EASE: [0.32, 0.72, 0, 1],
};
function Modal({ onClose = () => {}, initialFocusRef, children }) {
@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 = {
//
};