mirror of
https://github.com/Xevion/bus-reminder.git
synced 2025-12-08 14:06:35 -06:00
Separate client & server utility functions
This commit is contained in:
22
src/components/Layout.tsx
Normal file
22
src/components/Layout.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import { FunctionComponent } from 'react';
|
||||
import { classNames } from '@/utils/client';
|
||||
|
||||
export type LayoutProps = {
|
||||
className?: string;
|
||||
children: React.ReactNode;
|
||||
};
|
||||
|
||||
const Layout: FunctionComponent<LayoutProps> = ({ children, className }) => {
|
||||
return (
|
||||
<div
|
||||
className={classNames(
|
||||
'flex text-zinc-200 bg-zinc-900 min-h-screen h-full flex-col justify-center py-12 sm:px-6 lg:px-8',
|
||||
className
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Layout;
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
import { unauthorized } from '@/utils/helpers';
|
||||
import { unauthorized } from '@/utils/server';
|
||||
|
||||
type StatusData = { status: ResponseStatus };
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
import { fetchConfiguration, setConfiguration } from '@/db';
|
||||
import { Configuration, ConfigurationSchema } from '@/timing';
|
||||
import { unauthorized } from '@/utils/helpers';
|
||||
import { unauthorized } from '@/utils/server';
|
||||
|
||||
type StatusData = { status: ResponseStatus };
|
||||
|
||||
|
||||
@@ -11,7 +11,8 @@ import {
|
||||
} from '@/db';
|
||||
import { localNow } from '@/utils/timezone';
|
||||
import logger from '@/logger';
|
||||
import { parseBoolean, unauthorized } from '@/utils/helpers';
|
||||
import { parseBoolean } from '@/utils/client';
|
||||
import { unauthorized } from '@/utils/server';
|
||||
|
||||
type ResponseData = {
|
||||
diff: number;
|
||||
|
||||
12
src/utils/client.ts
Normal file
12
src/utils/client.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
export function parseBoolean(
|
||||
value: string | string[] | undefined | null
|
||||
): boolean {
|
||||
if (value == undefined) return false;
|
||||
if (Array.isArray(value)) return false;
|
||||
value = value.toLowerCase();
|
||||
return value === 'true' || value === '1' || value === 'yes';
|
||||
}
|
||||
|
||||
export function classNames(...classes: (string | undefined)[]): string {
|
||||
return classes.filter(Boolean).join(' ');
|
||||
}
|
||||
@@ -12,13 +12,4 @@ export function unauthorized(
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function parseBoolean(
|
||||
value: string | string[] | undefined | null
|
||||
): boolean {
|
||||
if (value == undefined) return false;
|
||||
if (Array.isArray(value)) return false;
|
||||
value = value.toLowerCase();
|
||||
return value === 'true' || value === '1' || value === 'yes';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user