Skip to content

Instantly share code, notes, and snippets.

export let action: ActionFunction = async ({ request, params }) => {
let session = await requireAuthSession(request);
await ensureUserAccount(session.get("auth"));
let data = Object.fromEntries(await request.formData());
invariant(typeof data._action === "string", "_action should be string");
switch (data._action) {
case Actions.CREATE_TASK:
case Actions.UPDATE_TASK_NAME: {
import type { LoaderFunction, ActionFunction } from "remix";
import { useLoaderData, useFetcher } from "remix";
import invariant from "tiny-invariant";
import cuid from "cuid";
import React from "react";
import type { Task, User } from "@prisma/client";
import { requireAuthSession } from "~/util/magic-auth";
import { ensureUserAccount } from "~/util/account";
import { placeCaretAtEnd } from "~/components/range";
import { getBacklog } from "~/models/backlog";
import { createServer } from "http";
createServer(async (req, res) => {
if (req.url === "/app.js") {
res.setHeader("Content-Type", "application/javascript; charset=UTF-8");
res.setHeader("Cache-Control", "max-age=10");
res.write(`console.log("lol")`);
res.end();
return;
}
// root.tsx
import { getUserSession, requireUser, logout } from "~/session";
export function loader({ request }) {
// use case: know if the user is logged in, no redirect to /login
let userSession = await getUserSession(request);
let isAuthenticated = userSession.has("userId");
return { isAuthenticated };
}
@ryanflorence
ryanflorence / Await.ts
Created November 12, 2021 20:39
Infer the return type of a promise.
type Await<T extends (...args: any) => any> = T extends (
...args: any
) => Promise<infer U>
? U
: T extends (...args: any) => infer U
? U
: any;
async function load() {
import crypto from "crypto";
import { renderToStaticMarkup } from "react-dom/server";
import createMailgun from "mailgun-js";
import type { ActionFunction, LoaderFunction, Session } from "remix";
import { createCookieSessionStorage, json, redirect } from "remix";
/*******************************************************************************
* Before we can do anything, we need to make sure the environment has
* everything we need. If anything is missing, we just prevent the app from
* starting up.

Slow Speed, Short Rope

  • Surface 180s (Jet ski)
    • Push with back foot to release fins
    • upper body shouldn't really move
  • Surface 360s both TS/HS (jet ski)
    • lean against the line
    • sqaut to get good advance
    • pull with two hands
  • traveling
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
import { createCookieSessionStorage } from "remix";
let { getSession, commitSession, destroySession } = createCookieSessionStorage({
cookie: {
name: "__session",
secrets: ["r3m1xr0ck5"]
}
});
export { getSession, commitSession, destroySession };
const pageMachine = Machine({
id: 'pageTransition',
initial: 'idle',
context: {
location: '/',
nextLocation: null,
data: {},
forms: new Map(),
error: null