diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 887cd19..7a3c845 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,7 +1,7 @@ # These are supported funding model platforms github: kayteh -patreon: kata +patreon: roleypoly open_collective: # Replace with a single Open Collective username ko_fi: roleypoly tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel diff --git a/src/pages-deprecated/README.md b/src/pages-deprecated/README.md deleted file mode 100644 index 756d131..0000000 --- a/src/pages-deprecated/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Pages - -This is the Next.js root for the main UI. diff --git a/src/pages-deprecated/_app.tsx b/src/pages-deprecated/_app.tsx deleted file mode 100644 index c0c3b05..0000000 --- a/src/pages-deprecated/_app.tsx +++ /dev/null @@ -1,15 +0,0 @@ -import { InjectTypekitFont } from '@roleypoly/design-system/atoms/fonts'; -import { AppProps } from 'next/app'; -import * as React from 'react'; - -type Props = AppProps & { - sessionKey: string | null; -}; - -const App = (props: Props) => ( - <> - - - -); -export default App; diff --git a/src/pages-deprecated/_document.tsx b/src/pages-deprecated/_document.tsx deleted file mode 100644 index 14f4f25..0000000 --- a/src/pages-deprecated/_document.tsx +++ /dev/null @@ -1,30 +0,0 @@ -import Document, { DocumentContext } from 'next/document'; -import { ServerStyleSheet } from 'styled-components'; - -export default class MyDocument extends Document { - static async getInitialProps(ctx: DocumentContext) { - const sheet = new ServerStyleSheet(); - const originalRenderPage = ctx.renderPage; - - try { - ctx.renderPage = () => - originalRenderPage({ - enhanceApp: (App) => (props) => - sheet.collectStyles(), - }); - - const initialProps = await Document.getInitialProps(ctx); - return { - ...initialProps, - styles: ( - <> - {initialProps.styles} - {sheet.getStyleElement()} - - ), - }; - } finally { - sheet.seal(); - } - } -} diff --git a/src/pages-deprecated/auth/login.tsx b/src/pages-deprecated/auth/login.tsx deleted file mode 100644 index ce73ad4..0000000 --- a/src/pages-deprecated/auth/login.tsx +++ /dev/null @@ -1,70 +0,0 @@ -import { AuthLogin } from '@roleypoly/design-system/templates/auth-login'; -import { GetServerSideProps } from 'next'; -import getConfig from 'next/config'; -import Head from 'next/head'; -import * as React from 'react'; -import { GuildSlug } from 'roleypoly/common/types'; -import { apiFetch } from 'roleypoly/common/utils/isomorphicFetch'; - -const loginPage = (props: { apiURI: string; guildSlug?: GuildSlug }) => { - React.useEffect(() => { - if (props.guildSlug) { - sessionStorage.setItem('redirectAfterNewSession', `/s/${props.guildSlug.id}`); - } - }, [props.guildSlug]); - - return ( - <> - - - {props.guildSlug - ? `Logging into ${props.guildSlug.name}... - Roleypoly` - : `Logging in... - Roleypoly`} - - - 0} - discordOAuthLink={`${props.apiURI}/login-bounce`} - guildSlug={props.guildSlug} - /> - - ); -}; - -export default loginPage; - -export const getServerSideProps: GetServerSideProps = async (context) => { - const { publicRuntimeConfig } = getConfig(); - - try { - const guildID = context.query['r']; - console.log({ guildID }); - if (guildID) { - const guildSlug = await apiFetch( - `/get-slug/${guildID}`, - {}, - context as any - ); - - if (guildSlug) { - return { - props: { - apiURI: publicRuntimeConfig.apiPublicURI, - guildSlug, - }, - }; - } - } - } catch (e) { - // Do nothing. - } - - return { - props: { - apiURI: publicRuntimeConfig.apiPublicURI, - }, - redirect: { - destination: `${publicRuntimeConfig.apiPublicURI}/login-bounce`, - }, - }; -}; diff --git a/src/pages-deprecated/help/why-no-roles.tsx b/src/pages-deprecated/help/why-no-roles.tsx deleted file mode 100644 index 0c4bf74..0000000 --- a/src/pages-deprecated/help/why-no-roles.tsx +++ /dev/null @@ -1,13 +0,0 @@ -import { WhyNoRoles } from '@roleypoly/design-system/organisms/help-why-no-roles'; -import { - HelpPageProps, - HelpPageTemplate, -} from '@roleypoly/design-system/templates/help-page'; - -const WhyNoRolesPage = (props: HelpPageProps) => ( - - - -); - -export default WhyNoRolesPage; diff --git a/src/pages-deprecated/index.tsx b/src/pages-deprecated/index.tsx deleted file mode 100644 index 9c1d79c..0000000 --- a/src/pages-deprecated/index.tsx +++ /dev/null @@ -1,20 +0,0 @@ -import { LandingTemplate } from '@roleypoly/design-system/templates/landing'; -import { useRouter } from 'next/router'; -import * as React from 'react'; -import { useAppShellProps } from 'roleypoly/providers/appShellData'; - -const Index = () => { - const { - appShellProps: { guilds, user }, - } = useAppShellProps(); - const router = useRouter(); - - React.useEffect(() => { - if (user || guilds) { - void router.replace('/servers'); - } - }, [guilds, user]); - - return ; -}; -export default Index; diff --git a/src/pages-deprecated/machinery/error.tsx b/src/pages-deprecated/machinery/error.tsx deleted file mode 100644 index ab634b9..0000000 --- a/src/pages-deprecated/machinery/error.tsx +++ /dev/null @@ -1,17 +0,0 @@ -import { Error } from '@roleypoly/design-system/templates/errors'; -import { NextPageContext } from 'next'; -import * as React from 'react'; - -type Props = { - errorCode: string | number | any; -}; - -const ErrorPage = (props: Props) => ; - -ErrorPage.getInitialProps = (context: NextPageContext): Props => { - return { - errorCode: context.err || context.query.error_code, - }; -}; - -export default ErrorPage; diff --git a/src/pages-deprecated/machinery/logout.tsx b/src/pages-deprecated/machinery/logout.tsx deleted file mode 100644 index f0210c5..0000000 --- a/src/pages-deprecated/machinery/logout.tsx +++ /dev/null @@ -1,56 +0,0 @@ -import { Hero } from '@roleypoly/design-system/atoms/hero'; -import { AccentTitle } from '@roleypoly/design-system/atoms/typography'; -import { AppShell } from '@roleypoly/design-system/organisms/app-shell'; -import fetch from 'isomorphic-unfetch'; -import { GetServerSideProps } from 'next'; -import getConfig from 'next/config'; -import nookies from 'nookies'; -import * as React from 'react'; - -type Props = { - sessionID: string; -}; - -const Logout = (props: Props) => { - React.useEffect(() => { - sessionStorage.removeItem('session_key'); - sessionStorage.removeItem('session_data'); - location.href = '/'; - }, []); - - return ( - - - Logging you out... - - - ); -}; - -export const getServerSideProps: GetServerSideProps = async (context) => { - const { publicRuntimeConfig } = getConfig(); - - const sessionKey = nookies.get(context)['rp_session_key']; - if (!sessionKey) { - return { props: {} }; - } - try { - await fetch(`${publicRuntimeConfig.apiPublicURI}/revoke-session`, { - method: 'POST', - headers: { - authorization: `Bearer ${sessionKey}`, - }, - }); - } catch (e) {} - - nookies.set(context, 'rp_session_key', '', { - httpOnly: true, - maxAge: 0, - path: '/', - sameSite: 'strict', - }); - - return { props: {} }; -}; - -export default Logout; diff --git a/src/pages-deprecated/machinery/new-session.tsx b/src/pages-deprecated/machinery/new-session.tsx deleted file mode 100644 index f468c41..0000000 --- a/src/pages-deprecated/machinery/new-session.tsx +++ /dev/null @@ -1,57 +0,0 @@ -import { Hero } from '@roleypoly/design-system/atoms/hero'; -import { AccentTitle } from '@roleypoly/design-system/atoms/typography'; -import { AppShell } from '@roleypoly/design-system/organisms/app-shell'; -import { NextPageContext } from 'next'; -import getConfig from 'next/config'; -import { useRouter } from 'next/router'; -import nookies from 'nookies'; -import * as React from 'react'; - -type Props = { - sessionID: string; - apiURI: string; -}; - -const NewSession = (props: Props) => { - const { sessionID, apiURI } = props; - const router = useRouter(); - - React.useEffect(() => { - sessionStorage.setItem('session_key', sessionID); - localStorage.setItem('api_uri', apiURI); - - const nextURL = sessionStorage.getItem('redirectAfterNewSession') || '/servers'; - sessionStorage.removeItem('redirectAfterNewSession'); - void router.replace(nextURL); - }, [sessionID, apiURI]); - - return ( - - - Logging you in... - - - ); -}; - -export const getServerSideProps = async ( - context: NextPageContext -): Promise<{ props: Props }> => { - const { publicRuntimeConfig } = getConfig(); - const apiURI = publicRuntimeConfig.apiPublicURI; - const sessionID = context.query.session_id as string; - if (!sessionID) { - throw new Error("I shouldn't be here today."); - } - - nookies.set(context, 'rp_session_key', sessionID, { - httpOnly: true, - maxAge: 60 * 60 * 6, - path: '/', - sameSite: 'strict', - }); - - return { props: { sessionID, apiURI } }; -}; - -export default NewSession; diff --git a/src/pages-deprecated/s/[id].tsx b/src/pages-deprecated/s/[id].tsx deleted file mode 100644 index cfe8a55..0000000 --- a/src/pages-deprecated/s/[id].tsx +++ /dev/null @@ -1,159 +0,0 @@ -import { RolePickerTemplate } from '@roleypoly/design-system/templates/role-picker'; -import { NextPage, NextPageContext } from 'next'; -import Head from 'next/head'; -import { useRouter } from 'next/router'; -import * as React from 'react'; -import { - Member, - PresentableGuild, - Role, - RoleTransaction, - RoleUpdate, - TransactionType, - UserGuildPermissions, -} from 'roleypoly/common/types'; -import { apiFetch, getSessionKey } from 'roleypoly/common/utils/isomorphicFetch'; -import { useAppShellProps } from 'roleypoly/providers/appShellData'; - -type Props = - | { - data: PresentableGuild; - redirect: null; - } - | { - data: null; - redirect: string; - }; - -const createUpdatePayload = ( - oldRoles: Role['id'][], - newRoles: Role['id'][] -): RoleTransaction[] => { - const transactions: RoleTransaction[] = []; - - // Removes: old roles not in new roles - for (let oldID of oldRoles) { - if (!newRoles.includes(oldID)) { - transactions.push({ - id: oldID, - action: TransactionType.Remove, - }); - } - } - - // Adds: new roles not in old roles - for (let newID of newRoles) { - if (!oldRoles.includes(newID)) { - transactions.push({ - id: newID, - action: TransactionType.Add, - }); - } - } - - return transactions; -}; - -const RolePickerPage: NextPage = (props) => { - const router = useRouter(); - - React.useEffect(() => { - if (props.redirect !== null) { - void router.replace(props.redirect || '/auth/login'); - } - }, [props.redirect]); - - if (!props.data) { - return null; - } - - const { appShellProps } = useAppShellProps(); - - const [isPending, updatePending] = React.useState(false); - const [memberRoles, updateMemberRoles] = React.useState(props.data.member.roles); - - const handlePickerSubmit = (guildID: string, oldRoles: Role['id'][]) => async ( - newRoles: Role['id'][] - ) => { - if (isPending) { - return; - } - - updatePending(true); - - const payload: RoleUpdate = { - knownState: oldRoles, - transactions: createUpdatePayload(oldRoles, newRoles), - }; - - const patchedMember = await apiFetch(`/update-roles/${guildID}`, { - method: 'PATCH', - body: JSON.stringify(payload), - }); - - if (!patchedMember) { - console.error('role update failed', patchedMember); - return; - } - - updatePending(false); - updateMemberRoles(patchedMember.roles); - console.log('accepted', { patchedMember }); - }; - - return ( - <> - - Picking roles on {props.data.guild.name} - Roleypoly - - - - ); -}; - -RolePickerPage.getInitialProps = async (context: NextPageContext): Promise => { - const serverID = context.query.id; - if (!serverID) { - throw new Error('serverID missing'); - } - - if (!getSessionKey()) { - return { - data: null, - redirect: `/auth/login?r=${serverID}`, - }; - } - - try { - const pickerData = await apiFetch( - `/get-picker-data/${serverID}`, - undefined, - context - ); - - if (!pickerData) { - throw new Error('Picker data failed.'); - } - return { - data: pickerData, - redirect: null, - }; - } catch (e) { - return { - data: null, - redirect: `/auth/login?r=${serverID}`, - }; - } -}; - -export default RolePickerPage; diff --git a/src/pages-deprecated/s/[id]/edit.tsx b/src/pages-deprecated/s/[id]/edit.tsx deleted file mode 100644 index 6b6185a..0000000 --- a/src/pages-deprecated/s/[id]/edit.tsx +++ /dev/null @@ -1,10 +0,0 @@ -import Link from 'next/link'; -import * as React from 'react'; - -const ServerEditor = () => ( -
- Go back -
-); - -export default ServerEditor; diff --git a/src/pages-deprecated/s/[id]/setup.tsx b/src/pages-deprecated/s/[id]/setup.tsx deleted file mode 100644 index a9c66a3..0000000 --- a/src/pages-deprecated/s/[id]/setup.tsx +++ /dev/null @@ -1,33 +0,0 @@ -import { ServerSetupTemplate } from '@roleypoly/design-system/templates/server-setup'; -import { NextPageContext } from 'next'; -import { useRouter } from 'next/router'; -import * as React from 'react'; -import { useAppShellProps } from 'roleypoly/providers/appShellData'; - -const serverSetup = (props: { guildID: string }) => { - const { appShellProps } = useAppShellProps(); - - const guildSlug = appShellProps.guilds?.find((guild) => guild.id === props.guildID); - - if (!guildSlug) { - const router = useRouter(); - void router.push('/machinery/error?error_code=404'); - return null; - } - - return ( - - ); -}; - -serverSetup.getInitialProps = async (context: NextPageContext) => { - return { - guildID: context.query.id, - }; -}; - -export default serverSetup; diff --git a/src/pages-deprecated/servers.tsx b/src/pages-deprecated/servers.tsx deleted file mode 100644 index bc1bc09..0000000 --- a/src/pages-deprecated/servers.tsx +++ /dev/null @@ -1,17 +0,0 @@ -import { ServersTemplate } from '@roleypoly/design-system/templates/servers'; -import Head from 'next/head'; -import { useAppShellProps } from 'roleypoly/providers/appShellData'; - -const Servers = () => { - const { appShellProps } = useAppShellProps(); - return ( - <> - - Viewing your servers - Roleypoly - - - - ); -}; - -export default Servers;