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
find ./ -name '*.gql.ts' -delete |
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
const urlFactory = { | |
verify: (token: string) => `/verify/${token}`, | |
deed: ({ orgId, deedId }: { deedId: number; orgId: number }) => `/deed/${orgId}/${deedId}` | |
} | |
// Turn a factory object (like the one above) into a mapped type. | |
type URLFactoryMapped<T extends Record<keyof T, (...args: any) => any>> = | |
{ [K in keyof T]: (...args: Parameters<T[K]>) => ReturnType<T[K]> } | |
const url = <T extends keyof typeof urlFactory>(key: T, ...args: Parameters<typeof urlFactory[T]>) => { |
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
-- utility function for returning a random string of the given length | |
CREATE OR REPLACE FUNCTION random_string (string_length integer DEFAULT 10) | |
RETURNS varchar AS $$ | |
SELECT array_to_string( | |
ARRAY( | |
SELECT chr((65 + round(random() * 25))::integer) | |
FROM generate_series(1, string_length) | |
), '') $$ | |
LANGUAGE SQL; |
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 { execSync } from "child_process"; | |
import fetch from "node-fetch"; | |
const token = "YOUR_ACCESS_TOKEN"; | |
const project = "~/dev/deedmob/code/.git"; | |
const prev = "release-20220613.17-48-26"; | |
const next = "release-20220629.18-19-06"; | |
const repo = "DeedMob/deedmob"; | |
(async () => { |
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
const fs = require("fs"); | |
const path = require("path"); | |
const isValidFile = (filename) => !filename.startsWith("."); | |
const updateLastModifiedAt = async (filename) => { | |
const time = new Date(); | |
try { | |
fs.utimesSync(filename, time, time); | |
} catch (err) { | |
fs.closeSync(fs.openSync(filename, "w")); |
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
// resolve focus on opening and closing | |
useEffect(() => { | |
if (open) { | |
previousFocus.current = (document.activeElement as HTMLElement) ?? null; | |
nextFocus(getFocusableElements(container.current)); | |
} else { | |
previousFocus.current?.focus?.(); | |
previousFocus.current = null; | |
} | |
}, [open, portal]); |
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 const nextFocusable = (elements: HTMLElement[], forward = true) => { | |
const currentIndex = elements.findIndex((e) => e === document.activeElement); | |
let nextIndex = 0; | |
if (currentIndex > -1) { | |
if (forward) { | |
nextIndex = currentIndex < elements.length - 1 ? currentIndex + 1 : 0; | |
} else { | |
nextIndex = currentIndex > 0 ? currentIndex - 1 : elements.length - 1; | |
} |
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 const getFocusableElements = (parent?: HTMLElement | null): HTMLElement[] => { | |
if (!parent) return []; | |
return Array.from(parent.querySelectorAll("a[href], button, input, textarea, select, details,[tabindex]")) | |
.filter( | |
(el) => el.getAttribute("tabindex") !== "-1" && !el.hasAttribute("disabled") && !el.getAttribute("aria-hidden") | |
) | |
// sort tabindexes as follows: 1, 2, 3, 4, ..., 0, 0, 0 | |
.sort((a, b) => { | |
const aIndex = Number(a.getAttribute("tabindex")) ?? 0; // no `tabindex` means `tabindex=0` on a focusable element |
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
useEffect(() => { | |
document.getElementById("root")?.setAttribute("aria-hidden", open.toString()); | |
portal.current?.setAttribute("aria-hidden", (!open).toString()); | |
}, [open]); |
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 const usePortal = () => { | |
const portal = useRef(document.createElement("div")); | |
useEffect(() => { | |
const current = portal.current; | |
document.body.appendChild(portal.current); | |
return () => void document.body.removeChild(current); // let's avoid dangling `div`s | |
}, []); | |
return portal; |
NewerOlder