mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-06-16 17:49:09 +00:00
chore: update prettier tab width for consistency (#175)
This commit is contained in:
parent
a931f8c69c
commit
f24d2fcc99
247 changed files with 7224 additions and 7375 deletions
|
@ -5,50 +5,50 @@ import { useApiContext } from '../../contexts/api/ApiContext';
|
|||
import { Title } from '../../utils/metaTitle';
|
||||
|
||||
const Login = () => {
|
||||
const { apiUrl, fetch } = useApiContext();
|
||||
// If ?r is in query, then let's render the slug page
|
||||
// If not, redirect.
|
||||
const [guildSlug, setGuildSlug] = React.useState<GuildSlug | null>(null);
|
||||
const [oauthLink, setOauthLink] = React.useState(`${apiUrl}/login-bounce`);
|
||||
const { apiUrl, fetch } = useApiContext();
|
||||
// If ?r is in query, then let's render the slug page
|
||||
// If not, redirect.
|
||||
const [guildSlug, setGuildSlug] = React.useState<GuildSlug | null>(null);
|
||||
const [oauthLink, setOauthLink] = React.useState(`${apiUrl}/login-bounce`);
|
||||
|
||||
React.useEffect(() => {
|
||||
const url = new URL(window.location.href);
|
||||
const callbackHost = new URL('/', url);
|
||||
const redirectServerID = url.searchParams.get('r');
|
||||
const redirectUrl = `${apiUrl}/login-bounce?cbh=${callbackHost.href}`;
|
||||
if (!redirectServerID) {
|
||||
window.location.href = redirectUrl;
|
||||
return;
|
||||
}
|
||||
|
||||
setOauthLink(redirectUrl);
|
||||
localStorage.setItem('rp_postauth_redirect', `/s/${redirectServerID}`);
|
||||
|
||||
const fetchGuildSlug = async (id: string) => {
|
||||
const response = await fetch(`/get-slug/${id}`);
|
||||
if (response.status === 200) {
|
||||
const slug = await response.json();
|
||||
setGuildSlug(slug);
|
||||
}
|
||||
};
|
||||
|
||||
fetchGuildSlug(redirectServerID);
|
||||
}, [apiUrl, fetch]);
|
||||
|
||||
if (guildSlug === null) {
|
||||
return <div>Loading...</div>;
|
||||
React.useEffect(() => {
|
||||
const url = new URL(window.location.href);
|
||||
const callbackHost = new URL('/', url);
|
||||
const redirectServerID = url.searchParams.get('r');
|
||||
const redirectUrl = `${apiUrl}/login-bounce?cbh=${callbackHost.href}`;
|
||||
if (!redirectServerID) {
|
||||
window.location.href = redirectUrl;
|
||||
return;
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Title title={'Login to Roleypoly'} />
|
||||
<AuthLogin
|
||||
guildSlug={guildSlug}
|
||||
onSendSecretCode={() => {}}
|
||||
discordOAuthLink={oauthLink}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
setOauthLink(redirectUrl);
|
||||
localStorage.setItem('rp_postauth_redirect', `/s/${redirectServerID}`);
|
||||
|
||||
const fetchGuildSlug = async (id: string) => {
|
||||
const response = await fetch(`/get-slug/${id}`);
|
||||
if (response.status === 200) {
|
||||
const slug = await response.json();
|
||||
setGuildSlug(slug);
|
||||
}
|
||||
};
|
||||
|
||||
fetchGuildSlug(redirectServerID);
|
||||
}, [apiUrl, fetch]);
|
||||
|
||||
if (guildSlug === null) {
|
||||
return <div>Loading...</div>;
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Title title={'Login to Roleypoly'} />
|
||||
<AuthLogin
|
||||
guildSlug={guildSlug}
|
||||
onSendSecretCode={() => {}}
|
||||
discordOAuthLink={oauthLink}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default Login;
|
||||
|
|
|
@ -2,23 +2,23 @@ import { useApiContext } from '../../contexts/api/ApiContext';
|
|||
import { useSessionContext } from '../../contexts/session/SessionContext';
|
||||
|
||||
const SessionDebug = () => {
|
||||
const session = useSessionContext();
|
||||
const api = useApiContext();
|
||||
const session = useSessionContext();
|
||||
const api = useApiContext();
|
||||
|
||||
return (
|
||||
<pre>
|
||||
{JSON.stringify(
|
||||
{
|
||||
apiUrl: api.apiUrl,
|
||||
isAuthenticated: session.isAuthenticated,
|
||||
user: session.session?.user || null,
|
||||
guilds: session.session?.guilds || null,
|
||||
},
|
||||
null,
|
||||
' '
|
||||
)}
|
||||
</pre>
|
||||
);
|
||||
return (
|
||||
<pre>
|
||||
{JSON.stringify(
|
||||
{
|
||||
apiUrl: api.apiUrl,
|
||||
isAuthenticated: session.isAuthenticated,
|
||||
user: session.session?.user || null,
|
||||
guilds: session.session?.guilds || null,
|
||||
},
|
||||
null,
|
||||
' '
|
||||
)}
|
||||
</pre>
|
||||
);
|
||||
};
|
||||
|
||||
export default SessionDebug;
|
||||
|
|
|
@ -3,49 +3,49 @@ import * as React from 'react';
|
|||
import { useApiContext } from '../../contexts/api/ApiContext';
|
||||
|
||||
const SetApi = () => {
|
||||
const apiContext = useApiContext();
|
||||
const [apiField, setApiField] = React.useState(apiContext.apiUrl);
|
||||
const apiContext = useApiContext();
|
||||
const [apiField, setApiField] = React.useState(apiContext.apiUrl);
|
||||
|
||||
const setApi = () => {
|
||||
// Clear storage to get rid of old API data
|
||||
localStorage.clear();
|
||||
sessionStorage.clear();
|
||||
const setApi = () => {
|
||||
// Clear storage to get rid of old API data
|
||||
localStorage.clear();
|
||||
sessionStorage.clear();
|
||||
|
||||
apiContext.setApiUrl(apiField);
|
||||
apiContext.setApiUrl(apiField);
|
||||
|
||||
navigate('/');
|
||||
};
|
||||
navigate('/');
|
||||
};
|
||||
|
||||
const quickSettingClick = (url: string) => () => {
|
||||
setApiField(url);
|
||||
};
|
||||
const quickSettingClick = (url: string) => () => {
|
||||
setApiField(url);
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div>
|
||||
<input
|
||||
type="text"
|
||||
value={apiField}
|
||||
onChange={(ev) => {
|
||||
setApiField(ev.target.value);
|
||||
}}
|
||||
/>
|
||||
<button onClick={setApi}>Set & Go</button>
|
||||
</div>
|
||||
<div>
|
||||
Quick Settings:
|
||||
<button onClick={quickSettingClick('https://api-prod.roleypoly.com')}>
|
||||
Production (api-prod)
|
||||
</button>
|
||||
<button onClick={quickSettingClick('https://api-stage.roleypoly.com')}>
|
||||
Staging (api-stage)
|
||||
</button>
|
||||
<button onClick={quickSettingClick('http://localhost:6609')}>
|
||||
Local (:6609)
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
return (
|
||||
<div>
|
||||
<div>
|
||||
<input
|
||||
type="text"
|
||||
value={apiField}
|
||||
onChange={(ev) => {
|
||||
setApiField(ev.target.value);
|
||||
}}
|
||||
/>
|
||||
<button onClick={setApi}>Set & Go</button>
|
||||
</div>
|
||||
<div>
|
||||
Quick Settings:
|
||||
<button onClick={quickSettingClick('https://api-prod.roleypoly.com')}>
|
||||
Production (api-prod)
|
||||
</button>
|
||||
<button onClick={quickSettingClick('https://api-stage.roleypoly.com')}>
|
||||
Staging (api-stage)
|
||||
</button>
|
||||
<button onClick={quickSettingClick('http://localhost:6609')}>
|
||||
Local (:6609)
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default SetApi;
|
||||
|
|
|
@ -6,19 +6,19 @@ import { useSessionContext } from '../contexts/session/SessionContext';
|
|||
import { Title } from '../utils/metaTitle';
|
||||
|
||||
const Landing = () => {
|
||||
const { isAuthenticated } = useSessionContext();
|
||||
const appShellProps = useAppShellProps();
|
||||
const { isAuthenticated } = useSessionContext();
|
||||
const appShellProps = useAppShellProps();
|
||||
|
||||
if (isAuthenticated) {
|
||||
return <Redirect to="/servers" />;
|
||||
}
|
||||
if (isAuthenticated) {
|
||||
return <Redirect to="/servers" />;
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Title title={`Roleypoly - Tame your Discord roles.`} />
|
||||
<LandingTemplate {...appShellProps} />
|
||||
</>
|
||||
);
|
||||
return (
|
||||
<>
|
||||
<Title title={`Roleypoly - Tame your Discord roles.`} />
|
||||
<LandingTemplate {...appShellProps} />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default Landing;
|
||||
|
|
|
@ -2,23 +2,23 @@ import * as React from 'react';
|
|||
import { Title } from '../../utils/metaTitle';
|
||||
|
||||
const NewSession = () => {
|
||||
React.useEffect(() => {
|
||||
const url = new URL(window.location.href);
|
||||
const id = url.searchParams.get('session_id');
|
||||
if (id) {
|
||||
localStorage.setItem('rp_session_key', id);
|
||||
React.useEffect(() => {
|
||||
const url = new URL(window.location.href);
|
||||
const id = url.searchParams.get('session_id');
|
||||
if (id) {
|
||||
localStorage.setItem('rp_session_key', id);
|
||||
|
||||
const redirectUrl = localStorage.getItem('rp_postauth_redirect');
|
||||
window.location.href = redirectUrl || '/';
|
||||
}
|
||||
});
|
||||
const redirectUrl = localStorage.getItem('rp_postauth_redirect');
|
||||
window.location.href = redirectUrl || '/';
|
||||
}
|
||||
});
|
||||
|
||||
return (
|
||||
<>
|
||||
<Title title="Logging you into Roleypoly..." />
|
||||
<div>Redirecting you...</div>
|
||||
</>
|
||||
);
|
||||
return (
|
||||
<>
|
||||
<Title title="Logging you into Roleypoly..." />
|
||||
<div>Redirecting you...</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default NewSession;
|
||||
|
|
|
@ -10,106 +10,106 @@ import { Title } from '../utils/metaTitle';
|
|||
import { makeRoleTransactions } from '../utils/roleTransactions';
|
||||
|
||||
type PickerProps = {
|
||||
serverID: string;
|
||||
serverID: string;
|
||||
};
|
||||
|
||||
const Picker = (props: PickerProps) => {
|
||||
const { session, authedFetch, isAuthenticated } = useSessionContext();
|
||||
const { pushRecentGuild } = useRecentGuilds();
|
||||
const appShellProps = useAppShellProps();
|
||||
const { session, authedFetch, isAuthenticated } = useSessionContext();
|
||||
const { pushRecentGuild } = useRecentGuilds();
|
||||
const appShellProps = useAppShellProps();
|
||||
|
||||
const [pickerData, setPickerData] = React.useState<PresentableGuild | null | false>(
|
||||
null
|
||||
);
|
||||
const [pending, setPending] = React.useState(false);
|
||||
const [pickerData, setPickerData] = React.useState<PresentableGuild | null | false>(
|
||||
null
|
||||
);
|
||||
const [pending, setPending] = React.useState(false);
|
||||
|
||||
React.useEffect(() => {
|
||||
const fetchPickerData = async () => {
|
||||
const response = await authedFetch(`/get-picker-data/${props.serverID}`);
|
||||
const data = await response.json();
|
||||
React.useEffect(() => {
|
||||
const fetchPickerData = async () => {
|
||||
const response = await authedFetch(`/get-picker-data/${props.serverID}`);
|
||||
const data = await response.json();
|
||||
|
||||
if (response.status !== 200) {
|
||||
setPickerData(false);
|
||||
return;
|
||||
}
|
||||
if (response.status !== 200) {
|
||||
setPickerData(false);
|
||||
return;
|
||||
}
|
||||
|
||||
setPickerData(data);
|
||||
};
|
||||
|
||||
fetchPickerData();
|
||||
}, [props.serverID, authedFetch, pushRecentGuild]);
|
||||
|
||||
React.useCallback((serverID) => pushRecentGuild(serverID), [pushRecentGuild])(
|
||||
props.serverID
|
||||
);
|
||||
|
||||
if (!isAuthenticated) {
|
||||
return <Redirect to={`/auth/login?r=${props.serverID}`} replace />;
|
||||
}
|
||||
|
||||
if (pickerData === null) {
|
||||
return <div>Loading...</div>;
|
||||
}
|
||||
|
||||
if (pickerData === false) {
|
||||
if (session && session.user && session.guilds) {
|
||||
const guildSlug = session.guilds.find((guild) => guild.id === props.serverID);
|
||||
if (!guildSlug) {
|
||||
throw new Error('placeholder: guild not found in user slugs, 404');
|
||||
}
|
||||
|
||||
return (
|
||||
<ServerSetupTemplate
|
||||
activeGuildId={props.serverID}
|
||||
guildSlug={guildSlug}
|
||||
{...appShellProps}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
throw new Error('placeholder: session state is odd, 404');
|
||||
}
|
||||
|
||||
const onSubmit = async (submittedRoles: string[]) => {
|
||||
if (pending === true) {
|
||||
return;
|
||||
}
|
||||
|
||||
setPending(true);
|
||||
const updatePayload: RoleUpdate = {
|
||||
knownState: pickerData.member.roles,
|
||||
transactions: makeRoleTransactions(pickerData.member.roles, submittedRoles),
|
||||
};
|
||||
|
||||
const response = await authedFetch(`/update-roles/${props.serverID}`, {
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify(updatePayload),
|
||||
});
|
||||
if (response.status === 200) {
|
||||
setPickerData({
|
||||
...pickerData,
|
||||
member: { ...pickerData.member, roles: (await response.json()).roles },
|
||||
});
|
||||
}
|
||||
|
||||
setPending(false);
|
||||
setPickerData(data);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Title title={`${pickerData.guild.name} - Roleypoly`} />
|
||||
<RolePickerTemplate
|
||||
activeGuildId={props.serverID}
|
||||
{...appShellProps}
|
||||
guild={pickerData.guild}
|
||||
guildData={pickerData.data}
|
||||
member={pickerData.member}
|
||||
roles={pickerData.roles}
|
||||
editable={pickerData.guild.permissionLevel > UserGuildPermissions.User}
|
||||
onSubmit={onSubmit}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
fetchPickerData();
|
||||
}, [props.serverID, authedFetch, pushRecentGuild]);
|
||||
|
||||
React.useCallback((serverID) => pushRecentGuild(serverID), [pushRecentGuild])(
|
||||
props.serverID
|
||||
);
|
||||
|
||||
if (!isAuthenticated) {
|
||||
return <Redirect to={`/auth/login?r=${props.serverID}`} replace />;
|
||||
}
|
||||
|
||||
if (pickerData === null) {
|
||||
return <div>Loading...</div>;
|
||||
}
|
||||
|
||||
if (pickerData === false) {
|
||||
if (session && session.user && session.guilds) {
|
||||
const guildSlug = session.guilds.find((guild) => guild.id === props.serverID);
|
||||
if (!guildSlug) {
|
||||
throw new Error('placeholder: guild not found in user slugs, 404');
|
||||
}
|
||||
|
||||
return (
|
||||
<ServerSetupTemplate
|
||||
activeGuildId={props.serverID}
|
||||
guildSlug={guildSlug}
|
||||
{...appShellProps}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
throw new Error('placeholder: session state is odd, 404');
|
||||
}
|
||||
|
||||
const onSubmit = async (submittedRoles: string[]) => {
|
||||
if (pending === true) {
|
||||
return;
|
||||
}
|
||||
|
||||
setPending(true);
|
||||
const updatePayload: RoleUpdate = {
|
||||
knownState: pickerData.member.roles,
|
||||
transactions: makeRoleTransactions(pickerData.member.roles, submittedRoles),
|
||||
};
|
||||
|
||||
const response = await authedFetch(`/update-roles/${props.serverID}`, {
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify(updatePayload),
|
||||
});
|
||||
if (response.status === 200) {
|
||||
setPickerData({
|
||||
...pickerData,
|
||||
member: { ...pickerData.member, roles: (await response.json()).roles },
|
||||
});
|
||||
}
|
||||
|
||||
setPending(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Title title={`${pickerData.guild.name} - Roleypoly`} />
|
||||
<RolePickerTemplate
|
||||
activeGuildId={props.serverID}
|
||||
{...appShellProps}
|
||||
guild={pickerData.guild}
|
||||
guildData={pickerData.data}
|
||||
member={pickerData.member}
|
||||
roles={pickerData.roles}
|
||||
editable={pickerData.guild.permissionLevel > UserGuildPermissions.User}
|
||||
onSubmit={onSubmit}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default Picker;
|
||||
|
|
|
@ -6,18 +6,18 @@ import { useSessionContext } from '../contexts/session/SessionContext';
|
|||
import { Title } from '../utils/metaTitle';
|
||||
|
||||
const ServersPage = () => {
|
||||
const { isAuthenticated, session } = useSessionContext();
|
||||
const appShellProps = useAppShellProps();
|
||||
if (!isAuthenticated || !session) {
|
||||
return <Redirect to="/" />;
|
||||
}
|
||||
const { isAuthenticated, session } = useSessionContext();
|
||||
const appShellProps = useAppShellProps();
|
||||
if (!isAuthenticated || !session) {
|
||||
return <Redirect to="/" />;
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Title title={'Your Guilds - Roleypoly'} />
|
||||
<ServersTemplate {...appShellProps} />
|
||||
</>
|
||||
);
|
||||
return (
|
||||
<>
|
||||
<Title title={'Your Guilds - Roleypoly'} />
|
||||
<ServersTemplate {...appShellProps} />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default ServersPage;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue