View useAutoplay.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { MutableRefObject, useEffect } from 'react'; | |
const AUTO_PLAY_DELAY = 1500; | |
const PLAY_ERROR_NO_INTERACTION = | |
"play() failed because the user didn't interact with the document first"; | |
export default function useAutoplay( | |
videoRef: MutableRefObject<HTMLVideoElement | HTMLAudioElement | undefined>, | |
isActive: boolean, | |
) { |
View useResponsiveGridWithLastRowCentering.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import useBreakpointValueWithDeviceType from '@/hooks/useBreakpointValueWithUADetection/useBreakpointValueWithDeviceType'; | |
import { BoxProps } from '@chakra-ui/react'; | |
import { useMemo } from 'react'; | |
// Controlling Leftover Grid Items with Pseudo-selectors | |
// @see https://css-irl.info/controlling-leftover-grid-items/ | |
function generateCenteredGridStyles(columnCount: number): BoxProps['sx'] { | |
const itemStyles: Record<string, string | Record<string, string>> = { | |
gridColumn: 'span 2', |
View Compose.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Components = | |
| React.ElementType | |
| [React.ElementType, { [key: string]: unknown }]; | |
const Compose = ({ | |
components, | |
children, | |
}: { | |
components: Components[]; | |
children: JSX.Element; |
View composeContextProviders.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function composeContextProviders(providers: React.ElementType[]) { | |
return providers.reduce( | |
(Prev, Curr) => | |
function ComposedProviderWrapper({ children }) { | |
return ( | |
<Prev> | |
<Curr>{children}</Curr> | |
</Prev> | |
); | |
}, |
View createDialogContext.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createContext, useContext, useState } from 'react'; | |
class NoContextProviderError extends Error { | |
constructor() { | |
super('Context value was undefined'); | |
} | |
} | |
/** | |
* Utility to create a context for a dialog, to reduce boilerplate |
View getImageFileDimensions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get the dimensions of an image file | |
* Check the mime type before calling this function | |
*/ | |
export default function getImageFileDimensions( | |
imageFile: File, | |
): Promise<{ width: number; height: number }> { | |
return new Promise((resolve, reject) => { | |
if (!(window.File && window.FileReader && window.FileList && window.Blob)) { | |
reject( |
View marketing-site-render.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type { NextApiRequest, NextApiResponse } from 'next'; | |
function replaceUrlsInHtmlPage(htmlPage: string, urls: string[], newUrl: string) { | |
return urls.reduce((memo, url) => memo.replace(new RegExp(url, 'g'), newUrl), htmlPage); | |
} | |
/** | |
* This endpoint is used as a fallback for any route that is not handled by Next.js. | |
* This way, we can mix a marketing site hosted in WordPress and the app in the same domain | |
*/ |
View smoothScroll.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Inspired by https://codepen.io/oxleberry/pen/BOEBaB | |
* | |
* With added support for horizontal scrolling, scrolling the window, and linear easing | |
* | |
* native scrollTo or scrollIntoView conflict with each other if there are different horizontal and vertical scrolls happening | |
*/ | |
// Easing equations, http://www.gizma.com/easing/ | |
function easeOutCubic(t: number, b: number, c: number, d: number) { |
View export_env_vars.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# wraps the env var values in quotes and handles newlines | |
# It's a more sohisticated version from just doing export $($ENV_VARS) | |
# and it doesn't break with newline characters, quotes or spaces in the values (note the encoding with sed) | |
eval "$( | |
printf '%s\n' "$ENV_VARS" | while IFS='' read -r line; do | |
key=$(printf '%s\n' "$line"| sed 's/"/\\"/g' | cut -d '=' -f 1) | |
value=$(printf '%s\n' "$line" | cut -d '=' -f 2- | sed 's/"/\\\"/g') |
View json_to_env_var_format.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Formats something like | |
# | |
# '{"MODE":"dev","HOST":"db"}' | |
# | |
# to | |
# | |
# MODE=dev | |
# HOST=db |
NewerOlder