From 33dd17eeda3255ecf0d711c7c6bb86d3e8f7cfd4 Mon Sep 17 00:00:00 2001 From: "Kalle (Sendou)" <38327916+Sendouc@users.noreply.github.com> Date: Sun, 19 Dec 2021 11:15:22 +0200 Subject: [PATCH] utils switch to using function keyword --- app/utils/index.ts | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/app/utils/index.ts b/app/utils/index.ts index 1e6137db9..bc5c0dbaf 100644 --- a/app/utils/index.ts +++ b/app/utils/index.ts @@ -2,11 +2,12 @@ import { json } from "remix"; import invariant from "tiny-invariant"; import { useLocation } from "remix"; -export const makeTitle = (endOfTitle?: string) => - endOfTitle ? `sendou.ink | ${endOfTitle}` : "sendou.ink"; +export function makeTitle(endOfTitle?: string) { + return endOfTitle ? `sendou.ink | ${endOfTitle}` : "sendou.ink"; +} /** Get logged in user from context. Throws with 401 error if no user found. */ -export const requireUser = (ctx: any) => { +export function requireUser(ctx: any) { const user = ctx.user; if (!user) { @@ -14,28 +15,28 @@ export const requireUser = (ctx: any) => { } return user as NonNullable; -}; +} /** Get logged in user from context. Doesn't throw. */ -export const getUser = (ctx: any) => { +export function getUser(ctx: any) { const user = ctx.user; return user as LoggedInUser; -}; +} /** Get link to log in with query param set as current page */ -export const getLogInUrl = (location: ReturnType) => { +export function getLogInUrl(location: ReturnType) { return `/auth/discord?origin=${encodeURIComponent(location.pathname)}`; -}; +} /** Get fields from `request.formData()`. Throw an error if the formData doesn't contain a requested field. */ -export const formDataFromRequest = async ({ +export async function formDataFromRequest({ request, fields, }: { request: Request; fields: T[]; -}): Promise> => { +}): Promise> { const formData = await request.formData(); let result: Partial> = {}; @@ -48,7 +49,7 @@ export const formDataFromRequest = async ({ } return result as Record; -}; +} export type LoggedInUser = { id: string;