mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-04-24 19:39:11 +00:00
chore: update codestyle due to prettier/rule updates
This commit is contained in:
parent
f632bfa6e5
commit
10e095656f
16 changed files with 298 additions and 292 deletions
|
@ -10,7 +10,8 @@ import {
|
||||||
} from '../utils/responses';
|
} from '../utils/responses';
|
||||||
|
|
||||||
export const ClearGuildCache = withSession(
|
export const ClearGuildCache = withSession(
|
||||||
(session) => async (request: Request): Promise<Response> => {
|
(session) =>
|
||||||
|
async (request: Request): Promise<Response> => {
|
||||||
const url = new URL(request.url);
|
const url = new URL(request.url);
|
||||||
const [, , guildID] = url.pathname.split('/');
|
const [, , guildID] = url.pathname.split('/');
|
||||||
if (!guildID) {
|
if (!guildID) {
|
||||||
|
|
|
@ -5,7 +5,8 @@ import { getGuild, getGuildData, getGuildMemberRoles } from '../utils/guild';
|
||||||
const fail = () => respond({ error: 'guild not found' }, { status: 404 });
|
const fail = () => respond({ error: 'guild not found' }, { status: 404 });
|
||||||
|
|
||||||
export const GetPickerData = withSession(
|
export const GetPickerData = withSession(
|
||||||
(session: SessionData) => async (request: Request): Promise<Response> => {
|
(session: SessionData) =>
|
||||||
|
async (request: Request): Promise<Response> => {
|
||||||
const url = new URL(request.url);
|
const url = new URL(request.url);
|
||||||
const [, , guildID] = url.pathname.split('/');
|
const [, , guildID] = url.pathname.split('/');
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,8 @@ import {
|
||||||
} from '../utils/responses';
|
} from '../utils/responses';
|
||||||
|
|
||||||
export const SyncFromLegacy = withSession(
|
export const SyncFromLegacy = withSession(
|
||||||
(session) => async (request: Request): Promise<Response> => {
|
(session) =>
|
||||||
|
async (request: Request): Promise<Response> => {
|
||||||
const url = new URL(request.url);
|
const url = new URL(request.url);
|
||||||
const [, , guildID] = url.pathname.split('/');
|
const [, , guildID] = url.pathname.split('/');
|
||||||
if (!guildID) {
|
if (!guildID) {
|
||||||
|
|
|
@ -21,7 +21,8 @@ import {
|
||||||
const notFound = () => respond({ error: 'guild not found' }, { status: 404 });
|
const notFound = () => respond({ error: 'guild not found' }, { status: 404 });
|
||||||
|
|
||||||
export const UpdateRoles = withSession(
|
export const UpdateRoles = withSession(
|
||||||
({ guilds, user: { id: userID } }: SessionData) => async (request: Request) => {
|
({ guilds, user: { id: userID } }: SessionData) =>
|
||||||
|
async (request: Request) => {
|
||||||
const updateRequest = (await request.json()) as RoleUpdate;
|
const updateRequest = (await request.json()) as RoleUpdate;
|
||||||
const [, , guildID] = new URL(request.url).pathname.split('/');
|
const [, , guildID] = new URL(request.url).pathname.split('/');
|
||||||
|
|
||||||
|
|
|
@ -27,10 +27,12 @@ export const addCORS = (init: ResponseInit = {}) => ({
|
||||||
export const respond = (obj: Record<string, any>, init: ResponseInit = {}) =>
|
export const respond = (obj: Record<string, any>, init: ResponseInit = {}) =>
|
||||||
new Response(JSON.stringify(obj), addCORS(init));
|
new Response(JSON.stringify(obj), addCORS(init));
|
||||||
|
|
||||||
export const resolveFailures = (
|
export const resolveFailures =
|
||||||
|
(
|
||||||
handleWith: () => Response,
|
handleWith: () => Response,
|
||||||
handler: (request: Request) => Promise<Response> | Response
|
handler: (request: Request) => Promise<Response> | Response
|
||||||
) => async (request: Request): Promise<Response> => {
|
) =>
|
||||||
|
async (request: Request): Promise<Response> => {
|
||||||
try {
|
try {
|
||||||
return handler(request);
|
return handler(request);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -106,12 +108,14 @@ export const discordFetch = async <T>(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const cacheLayer = <Identity, Data>(
|
export const cacheLayer =
|
||||||
|
<Identity, Data>(
|
||||||
kv: WrappedKVNamespace,
|
kv: WrappedKVNamespace,
|
||||||
keyFactory: (identity: Identity) => string,
|
keyFactory: (identity: Identity) => string,
|
||||||
missHandler: (identity: Identity) => Promise<Data | null>,
|
missHandler: (identity: Identity) => Promise<Data | null>,
|
||||||
ttlSeconds?: number
|
ttlSeconds?: number
|
||||||
) => async (
|
) =>
|
||||||
|
async (
|
||||||
identity: Identity,
|
identity: Identity,
|
||||||
options: { skipCachePull?: boolean } = {}
|
options: { skipCachePull?: boolean } = {}
|
||||||
): Promise<Data | null> => {
|
): Promise<Data | null> => {
|
||||||
|
@ -142,9 +146,9 @@ const NotAuthenticated = (extra?: string) =>
|
||||||
{ status: 403 }
|
{ status: 403 }
|
||||||
);
|
);
|
||||||
|
|
||||||
export const withSession = (
|
export const withSession =
|
||||||
wrappedHandler: (session: SessionData) => Handler
|
(wrappedHandler: (session: SessionData) => Handler): Handler =>
|
||||||
): Handler => async (request: Request): Promise<Response> => {
|
async (request: Request): Promise<Response> => {
|
||||||
const sessionID = getSessionID(request);
|
const sessionID = getSessionID(request);
|
||||||
if (!sessionID) {
|
if (!sessionID) {
|
||||||
return NotAuthenticated('missing authentication');
|
return NotAuthenticated('missing authentication');
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const self = (global as any) as Record<string, string>;
|
const self = global as any as Record<string, string>;
|
||||||
|
|
||||||
const env = (key: string) => self[key] ?? '';
|
const env = (key: string) => self[key] ?? '';
|
||||||
|
|
||||||
|
|
|
@ -53,11 +53,7 @@ class EmulatedKV implements KVNamespace {
|
||||||
this.data.delete(key);
|
this.data.delete(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
async list(options?: {
|
async list(options?: { prefix?: string; limit?: number; cursor?: string }): Promise<{
|
||||||
prefix?: string;
|
|
||||||
limit?: number;
|
|
||||||
cursor?: string;
|
|
||||||
}): Promise<{
|
|
||||||
keys: { name: string; expiration?: number; metadata?: unknown }[];
|
keys: { name: string; expiration?: number; metadata?: unknown }[];
|
||||||
list_complete: boolean;
|
list_complete: boolean;
|
||||||
cursor: string;
|
cursor: string;
|
||||||
|
@ -83,7 +79,7 @@ class EmulatedKV implements KVNamespace {
|
||||||
const kvOrLocal = (namespace: KVNamespace | null): KVNamespace =>
|
const kvOrLocal = (namespace: KVNamespace | null): KVNamespace =>
|
||||||
namespace || new EmulatedKV();
|
namespace || new EmulatedKV();
|
||||||
|
|
||||||
const self = (global as any) as Record<string, any>;
|
const self = global as any as Record<string, any>;
|
||||||
|
|
||||||
export const Sessions = new WrappedKVNamespace(kvOrLocal(self.KV_SESSIONS ?? null));
|
export const Sessions = new WrappedKVNamespace(kvOrLocal(self.KV_SESSIONS ?? null));
|
||||||
export const GuildData = new WrappedKVNamespace(kvOrLocal(self.KV_GUILD_DATA ?? null));
|
export const GuildData = new WrappedKVNamespace(kvOrLocal(self.KV_GUILD_DATA ?? null));
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
import { WrappedKVNamespace } from './kv';
|
import { WrappedKVNamespace } from './kv';
|
||||||
|
|
||||||
export const useRateLimiter = (
|
export const useRateLimiter =
|
||||||
kv: WrappedKVNamespace,
|
(kv: WrappedKVNamespace, key: string, timeoutSeconds: number) =>
|
||||||
key: string,
|
async (): Promise<boolean> => {
|
||||||
timeoutSeconds: number
|
|
||||||
) => async (): Promise<boolean> => {
|
|
||||||
const value = await kv.get<boolean>(key);
|
const value = await kv.get<boolean>(key);
|
||||||
if (value) {
|
if (value) {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { roleypolyTheme } from './theme';
|
|
||||||
import { mdxComponents } from '../atoms/typography/mdx';
|
import { mdxComponents } from '../atoms/typography/mdx';
|
||||||
|
import { roleypolyTheme } from './theme';
|
||||||
|
|
||||||
export const parameters = {
|
export const parameters = {
|
||||||
actions: { argTypesRegex: '^on[A-Z].*' },
|
actions: { argTypesRegex: '^on[A-Z].*' },
|
||||||
|
|
|
@ -10,9 +10,10 @@ type DynamicLogoProps = LogoFlagProps & {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const DynamicLogomark = (props: Partial<DynamicLogoProps>) => {
|
export const DynamicLogomark = (props: Partial<DynamicLogoProps>) => {
|
||||||
const variant = React.useMemo(() => getRelevantVariant(props.currentDate), [
|
const variant = React.useMemo(
|
||||||
props.currentDate,
|
() => getRelevantVariant(props.currentDate),
|
||||||
]);
|
[props.currentDate]
|
||||||
|
);
|
||||||
|
|
||||||
if (!variant) {
|
if (!variant) {
|
||||||
return <Logomark {...props} />;
|
return <Logomark {...props} />;
|
||||||
|
@ -35,9 +36,10 @@ export const DynamicLogomark = (props: Partial<DynamicLogoProps>) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const DynamicLogotype = (props: Partial<DynamicLogoProps>) => {
|
export const DynamicLogotype = (props: Partial<DynamicLogoProps>) => {
|
||||||
const variant = React.useMemo(() => getRelevantVariant(props.currentDate), [
|
const variant = React.useMemo(
|
||||||
props.currentDate,
|
() => getRelevantVariant(props.currentDate),
|
||||||
]);
|
[props.currentDate]
|
||||||
|
);
|
||||||
|
|
||||||
if (!variant) {
|
if (!variant) {
|
||||||
return <Logotype {...props} />;
|
return <Logotype {...props} />;
|
||||||
|
|
|
@ -38,9 +38,9 @@ export const EditorCategory = (props: Props) => {
|
||||||
const [roleSearchPopoverActive, setRoleSearchPopoverActive] = React.useState(false);
|
const [roleSearchPopoverActive, setRoleSearchPopoverActive] = React.useState(false);
|
||||||
const [roleSearchTerm, updateSearchTerm] = React.useState('');
|
const [roleSearchTerm, updateSearchTerm] = React.useState('');
|
||||||
|
|
||||||
const onUpdate = (key: keyof typeof props.category, pred?: (newValue: any) => any) => (
|
const onUpdate =
|
||||||
newValue: any
|
(key: keyof typeof props.category, pred?: (newValue: any) => any) =>
|
||||||
) => {
|
(newValue: any) => {
|
||||||
props.onChange({
|
props.onChange({
|
||||||
...props.category,
|
...props.category,
|
||||||
[key]: pred ? pred(newValue) : newValue,
|
[key]: pred ? pred(newValue) : newValue,
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { FeatureFlag, FeatureFlagProvider, FeatureFlagsContext } from './FeatureFlags';
|
import { FeatureFlag, FeatureFlagProvider, FeatureFlagsContext } from './FeatureFlags';
|
||||||
|
|
||||||
export const FeatureFlagDecorator = (flags: FeatureFlag[]) => (
|
export const FeatureFlagDecorator =
|
||||||
storyFn: () => React.ReactNode
|
(flags: FeatureFlag[]) => (storyFn: () => React.ReactNode) => {
|
||||||
) => {
|
|
||||||
return (
|
return (
|
||||||
<FeatureFlagsContext.Provider value={new FeatureFlagProvider(flags)}>
|
<FeatureFlagsContext.Provider value={new FeatureFlagProvider(flags)}>
|
||||||
{storyFn()}
|
{storyFn()}
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
|
||||||
export const withContext = <T, K extends T>(
|
export const withContext =
|
||||||
|
<T, K extends T>(
|
||||||
Context: React.Context<T>,
|
Context: React.Context<T>,
|
||||||
Component: React.ComponentType<K>
|
Component: React.ComponentType<K>
|
||||||
): React.FunctionComponent<K> => (props) => (
|
): React.FunctionComponent<K> =>
|
||||||
|
(props) =>
|
||||||
|
(
|
||||||
<Context.Consumer>
|
<Context.Consumer>
|
||||||
{(context) => <Component {...props} {...context} />}
|
{(context) => <Component {...props} {...context} />}
|
||||||
</Context.Consumer>
|
</Context.Consumer>
|
||||||
|
|
|
@ -47,9 +47,8 @@ export const useSessionContext = () => React.useContext(SessionContext);
|
||||||
|
|
||||||
export const SessionContextProvider = (props: { children: React.ReactNode }) => {
|
export const SessionContextProvider = (props: { children: React.ReactNode }) => {
|
||||||
const { fetch } = useApiContext();
|
const { fetch } = useApiContext();
|
||||||
const [sessionID, setSessionID] = React.useState<SessionContextT['sessionID']>(
|
const [sessionID, setSessionID] =
|
||||||
undefined
|
React.useState<SessionContextT['sessionID']>(undefined);
|
||||||
);
|
|
||||||
const [sessionState, setSessionState] = React.useState<SessionState>(
|
const [sessionState, setSessionState] = React.useState<SessionState>(
|
||||||
SessionState.NoAuth
|
SessionState.NoAuth
|
||||||
);
|
);
|
||||||
|
|
|
@ -41,9 +41,10 @@ const Picker = (props: PickerProps) => {
|
||||||
fetchPickerData();
|
fetchPickerData();
|
||||||
}, [props.serverID, authedFetch, pushRecentGuild]);
|
}, [props.serverID, authedFetch, pushRecentGuild]);
|
||||||
|
|
||||||
React.useCallback((serverID) => pushRecentGuild(serverID), [pushRecentGuild])(
|
React.useCallback(
|
||||||
props.serverID
|
(serverID) => pushRecentGuild(serverID),
|
||||||
);
|
[pushRecentGuild]
|
||||||
|
)(props.serverID);
|
||||||
|
|
||||||
if (!isAuthenticated) {
|
if (!isAuthenticated) {
|
||||||
return <Redirect to={`/auth/login?r=${props.serverID}`} replace />;
|
return <Redirect to={`/auth/login?r=${props.serverID}`} replace />;
|
||||||
|
|
Loading…
Add table
Reference in a new issue