From db576298cb8eb24d6cd77a9ebcebe0db1014b97c Mon Sep 17 00:00:00 2001 From: Xevion Date: Mon, 27 Feb 2023 19:53:46 -0600 Subject: [PATCH] Slight reformatting with prettier --- src/pages/login.tsx | 103 +++++++++++++++++++++++--------------------- src/timing.ts | 17 +++++--- 2 files changed, 65 insertions(+), 55 deletions(-) diff --git a/src/pages/login.tsx b/src/pages/login.tsx index fb70280..a9e56ae 100644 --- a/src/pages/login.tsx +++ b/src/pages/login.tsx @@ -1,54 +1,59 @@ -import {NextPage} from "next"; -import {useForm} from "react-hook-form"; -import {useState} from "react"; -import {useRouter} from "next/router"; - +import { NextPage } from 'next'; +import { useForm } from 'react-hook-form'; +import { useState } from 'react'; +import { useRouter } from 'next/router'; const LoginPage: NextPage = () => { - type FormProps = { token: string; } - const {handleSubmit, register} = useForm(); - const [error, setError] = useState(null); - const router = useRouter(); + type FormProps = { token: string }; + const { handleSubmit, register } = useForm(); + const [error, setError] = useState(null); + const router = useRouter(); - async function onSubmit(data: FormProps) { - const response = await fetch(`/api/check?key=${data.token}`) - if (response.status === 200) { - setError(false); - router.push({pathname: "/", query: {"key": data.token}}).then(); - } else - setError(true); - } + async function onSubmit(data: FormProps) { + const response = await fetch(`/api/check?key=${data.token}`); + if (response.status === 200) { + setError(false); + router.push({ pathname: '/', query: { key: data.token } }).then(); + } else setError(true); + } - return
-
-
-
-
- -
- -
- {error ?

- The token given was not valid. -

: null} -
-
- -
-
-
-
-
-} + return ( +
+
+
+
+
+ +
+ +
+ {error ? ( +

+ The token given was not valid. +

+ ) : null} +
+
+ +
+
+
+
+
+ ); +}; -export default LoginPage; \ No newline at end of file +export default LoginPage; diff --git a/src/timing.ts b/src/timing.ts index 31b91a0..3e5516c 100644 --- a/src/timing.ts +++ b/src/timing.ts @@ -45,9 +45,12 @@ const TimeConfigSchema = z.object({ return parsed; }), // The days this configuration is active on. - days: z.array(DayEnumSchema).nonempty().transform(arr => { - return new Set(arr); - }), + days: z + .array(DayEnumSchema) + .nonempty() + .transform((arr) => { + return new Set(arr); + }), // If a notification isn't delivery within 10 minutes e.g. "00:30", 24 hour time maxLate: z .string() @@ -211,11 +214,15 @@ const dayAsNumber: Record = { export async function getMatchingTime( config: Configuration, - now = new Date() + now: Date = new Date() ): Promise { const times = config.times.filter((time) => { // If the day doesn't match, skip. if (!time.days.has(dayAsNumber[now.getDay().toString()])) return false; + const nowTime = { + hours: now.getHours(), + minutes: now.getMinutes() + }; const startTime = time.time; const endTime = addTime( @@ -223,8 +230,6 @@ export async function getMatchingTime( time.maxLate ?? { hours: 0, minutes: 0 } ); - const nowTime = { hours: now.getHours(), minutes: now.getMinutes() }; - return ( compareTime(nowTime, startTime) >= 0 && compareTime(nowTime, endTime) <= 0 );