Skip to content

Instantly share code, notes, and snippets.

View coryhouse's full-sized avatar

Cory House coryhouse

View GitHub Profile
@coryhouse
coryhouse / GetUserPermissionsResponse.ts
Last active July 6, 2023 14:23
Permission response
/** Return this when the user signs in */
type GetUserPermissionsResponse = {
featurePermissions: FeaturePermission[];
projectPermissions: ProjectPermission[];
};
type FeaturePermission = {
subModuleId: number;
permissions: Permission[];
};
@coryhouse
coryhouse / useHasCamera.ts
Created May 20, 2023 19:18
useHasCamera custom hook
import { useEffect, useState } from "react";
type Cameras = {
back: boolean;
front: boolean;
};
/** Returns a device's cameras and their location */
export default function useHasCamera() {
const [cameras, setCameras] = useState<Cameras | null>(null);
@coryhouse
coryhouse / extensions.json
Created April 10, 2023 16:11
Put this file in .vscode to recommend extensions
{
"recommendations": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"streetsidesoftware.code-spell-checker",
"GitHub.vscode-pull-request-github",
"ms-playwright.playwright",
"pflannery.vscode-versionlens",
"ZixuanChen.vitest-explorer"
]
@coryhouse
coryhouse / AllComponents.test.ts
Created May 25, 2022 19:02
Enforce tests exist for each component
// This file assures that a Jest test file and Cypress test file exists for each component.
import path from "path";
import fs from "fs";
function getFiles(filepath: string) {
return fs.readdirSync(filepath).filter(function (file) {
return fs.statSync(path.join(filepath, file)).isFile();
});
}
@coryhouse
coryhouse / mockDataSchema.js
Last active March 13, 2021 13:37
Mock Data Schema for "Building a JavaScript Development Environment" on Pluralsight
export const schema = {
type: "object",
properties: {
users: {
type: "array",
minItems: 3,
maxItems: 5,
items: {
type: "object",
properties: {
@coryhouse
coryhouse / webpack.config.dev.js
Created February 28, 2021 20:50
Development Webpack config for "Building a JavaScript Development Environment" on Pluralsight
import path from "path";
export default {
mode: "development",
devtool: "eval-source-map",
entry: "./src/index.js",
output: {
path: path.resolve(__dirname, "src"),
publicPath: "/",
filename: "bundle.js",
@coryhouse
coryhouse / package.json
Created February 28, 2021 18:46
package.json for Building a JS Development Environment on Pluralsight
{
"name": "javascript-development-environment",
"version": "1.0.0",
"description": "JavaScript development environment Pluralsight course by Cory House",
"scripts": {
},
"author": "Cory House",
"license": "MIT",
"dependencies": {
"whatwg-fetch": "3.6.2"
import React from "react";
import { getUsers } from "./services/userService";
import { useQuery } from "react-query";
export default function ReactQueryDemo() {
const { data, isLoading, error } = useQuery("users", getUsers);
if (isLoading) return "Loading...";
if (error) return "Oops!";
return data[0].username;
}
import React from "react";
import useFetch from "./useFetch";
export default function HookDemo() {
const { data, loading, error } = useFetch("users");
if (loading) return "Loading...";
if (error) return "Oops!";
return data[0].username;
}
import { useState, useEffect, useRef } from "react";
// This custom hook centralizes and streamlines handling of HTTP calls
export default function useFetch(url, init) {
const [data, setData] = useState(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
const prevInit = useRef();
const prevUrl = useRef();