From ecc0897ee6f8cf2c8374c1280cdd99d1cc650c1d Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 21 Sep 2023 13:45:58 -0500 Subject: [PATCH] Delete PublicLayout and legacy LandingPage --- .../__tests__/landing-page.test.tsx | 40 ---- src/features/landing-page/index.tsx | 108 ----------- .../components/__tests__/header.test.tsx | 25 --- .../public-layout/components/footer.tsx | 51 ------ .../public-layout/components/header.tsx | 171 ------------------ .../public-layout/components/sonar.tsx | 16 -- src/features/public-layout/index.tsx | 41 ----- 7 files changed, 452 deletions(-) delete mode 100644 src/features/landing-page/__tests__/landing-page.test.tsx delete mode 100644 src/features/landing-page/index.tsx delete mode 100644 src/features/public-layout/components/__tests__/header.test.tsx delete mode 100644 src/features/public-layout/components/footer.tsx delete mode 100644 src/features/public-layout/components/header.tsx delete mode 100644 src/features/public-layout/components/sonar.tsx delete mode 100644 src/features/public-layout/index.tsx diff --git a/src/features/landing-page/__tests__/landing-page.test.tsx b/src/features/landing-page/__tests__/landing-page.test.tsx deleted file mode 100644 index bbc96deebf..0000000000 --- a/src/features/landing-page/__tests__/landing-page.test.tsx +++ /dev/null @@ -1,40 +0,0 @@ -import React from 'react'; - -import { rememberInstance } from 'soapbox/actions/instance'; -import { render, screen, rootReducer } from 'soapbox/jest/test-helpers'; - -import LandingPage from '..'; - -describe('', () => { - it('renders a RegistrationForm for an open Pleroma instance', () => { - - const state = rootReducer(undefined, { - type: rememberInstance.fulfilled.type, - payload: { - version: '2.7.2 (compatible; Pleroma 2.3.0)', - registrations: true, - }, - }); - - render(, undefined, state); - - expect(screen.queryByTestId('registrations-open')).toBeInTheDocument(); - expect(screen.queryByTestId('registrations-closed')).not.toBeInTheDocument(); - }); - - it('renders "closed" message for a closed Pleroma instance', () => { - - const state = rootReducer(undefined, { - type: rememberInstance.fulfilled.type, - payload: { - version: '2.7.2 (compatible; Pleroma 2.3.0)', - registrations: false, - }, - }); - - render(, undefined, state); - - expect(screen.queryByTestId('registrations-closed')).toBeInTheDocument(); - expect(screen.queryByTestId('registrations-open')).not.toBeInTheDocument(); - }); -}); diff --git a/src/features/landing-page/index.tsx b/src/features/landing-page/index.tsx deleted file mode 100644 index a31d7d3137..0000000000 --- a/src/features/landing-page/index.tsx +++ /dev/null @@ -1,108 +0,0 @@ -import React from 'react'; -import { FormattedMessage } from 'react-intl'; - -import { prepareRequest } from 'soapbox/actions/consumer-auth'; -import Markup from 'soapbox/components/markup'; -import { Button, Card, CardBody, Stack, Text } from 'soapbox/components/ui'; -import RegistrationForm from 'soapbox/features/auth-login/components/registration-form'; -import { useAppDispatch, useFeatures, useInstance, useSoapboxConfig } from 'soapbox/hooks'; -import { capitalize } from 'soapbox/utils/strings'; - -const LandingPage = () => { - const dispatch = useAppDispatch(); - const features = useFeatures(); - const soapboxConfig = useSoapboxConfig(); - const instance = useInstance(); - - /** Registrations are closed */ - const renderClosed = () => { - return ( - - - - - - - - - ); - }; - - /** Mastodon API registrations are open */ - const renderOpen = () => { - return ; - }; - - /** Display login button for external provider. */ - const renderProvider = () => { - const { authProvider } = soapboxConfig; - - return ( - - - - - - - - - - ); - }; - - // Render registration flow depending on features - const renderBody = () => { - if (soapboxConfig.authProvider) { - return renderProvider(); - } else if (features.accountCreation && instance.registrations) { - return renderOpen(); - } else { - return renderClosed(); - } - }; - - return ( -
-
-
-
-
- -

- {instance.title} -

- - -
-
-
-
- - - {renderBody()} - - -
-
-
-
- ); -}; - -export default LandingPage; diff --git a/src/features/public-layout/components/__tests__/header.test.tsx b/src/features/public-layout/components/__tests__/header.test.tsx deleted file mode 100644 index 4472ce7b44..0000000000 --- a/src/features/public-layout/components/__tests__/header.test.tsx +++ /dev/null @@ -1,25 +0,0 @@ -import React from 'react'; - -import { storeOpen } from 'soapbox/jest/mock-stores'; -import { render, screen } from 'soapbox/jest/test-helpers'; - -import Header from '../header'; - -describe('
', () => { - it('successfully renders', () => { - render(
); - expect(screen.getByTestId('public-layout-header')).toBeInTheDocument(); - }); - - it('doesn\'t display the signup button by default', () => { - render(
); - expect(screen.queryByText('Register')).not.toBeInTheDocument(); - }); - - describe('with registrations enabled', () => { - it('displays the signup button', () => { - render(
, undefined, storeOpen); - expect(screen.getByText('Register')).toBeInTheDocument(); - }); - }); -}); \ No newline at end of file diff --git a/src/features/public-layout/components/footer.tsx b/src/features/public-layout/components/footer.tsx deleted file mode 100644 index 4038b5d186..0000000000 --- a/src/features/public-layout/components/footer.tsx +++ /dev/null @@ -1,51 +0,0 @@ -import { List as ImmutableList } from 'immutable'; -import React from 'react'; -import { Link } from 'react-router-dom'; - -import { getSettings } from 'soapbox/actions/settings'; -import { getSoapboxConfig } from 'soapbox/actions/soapbox'; -import { Text } from 'soapbox/components/ui'; -import { useAppSelector } from 'soapbox/hooks'; - -import type { FooterItem } from 'soapbox/types/soapbox'; - -const Footer = () => { - const { copyright, navlinks, locale } = useAppSelector((state) => { - const soapboxConfig = getSoapboxConfig(state); - - return { - copyright: soapboxConfig.copyright, - navlinks: (soapboxConfig.navlinks.get('homeFooter') || ImmutableList()) as ImmutableList, - locale: getSettings(state).get('locale') as string, - }; - }); - - return ( -
-
- {navlinks.map((link, idx) => { - const url = link.get('url'); - const isExternal = url.startsWith('http'); - const Comp = (isExternal ? 'a' : Link) as 'a'; - const compProps = isExternal ? { href: url, target: '_blank' } : { to: url }; - - return ( -
- - - {(link.getIn(['titleLocales', locale]) || link.get('title')) as string} - - -
- ); - })} -
- -
- {copyright} -
-
- ); -}; - -export default Footer; diff --git a/src/features/public-layout/components/header.tsx b/src/features/public-layout/components/header.tsx deleted file mode 100644 index 1d6edae19c..0000000000 --- a/src/features/public-layout/components/header.tsx +++ /dev/null @@ -1,171 +0,0 @@ -import React from 'react'; -import { defineMessages, FormattedMessage, useIntl } from 'react-intl'; -import { Link, Redirect } from 'react-router-dom'; - -import { logIn, verifyCredentials } from 'soapbox/actions/auth'; -import { fetchInstance } from 'soapbox/actions/instance'; -import { openModal } from 'soapbox/actions/modals'; -import SiteLogo from 'soapbox/components/site-logo'; -import { Button, Form, HStack, IconButton, Input, Tooltip } from 'soapbox/components/ui'; -import { useSoapboxConfig, useOwnAccount, useAppDispatch, useRegistrationStatus, useFeatures } from 'soapbox/hooks'; - -import Sonar from './sonar'; - -import type { AxiosError } from 'axios'; - -const messages = defineMessages({ - menu: { id: 'header.menu.title', defaultMessage: 'Open menu' }, - home: { id: 'header.home.label', defaultMessage: 'Home' }, - login: { id: 'header.login.label', defaultMessage: 'Log in' }, - register: { id: 'header.register.label', defaultMessage: 'Register' }, - username: { id: 'header.login.username.placeholder', defaultMessage: 'E-mail or username' }, - email: { id: 'header.login.email.placeholder', defaultMessage: 'E-mail address' }, - password: { id: 'header.login.password.label', defaultMessage: 'Password' }, - forgotPassword: { id: 'header.login.forgot_password', defaultMessage: 'Forgot password?' }, -}); - -const Header = () => { - const dispatch = useAppDispatch(); - const intl = useIntl(); - const features = useFeatures(); - - const { account } = useOwnAccount(); - const soapboxConfig = useSoapboxConfig(); - const { isOpen } = useRegistrationStatus(); - const { links } = soapboxConfig; - - const [isLoading, setLoading] = React.useState(false); - const [username, setUsername] = React.useState(''); - const [password, setPassword] = React.useState(''); - const [shouldRedirect, setShouldRedirect] = React.useState(false); - const [mfaToken, setMfaToken] = React.useState(false); - - const open = () => dispatch(openModal('LANDING_PAGE')); - - const handleSubmit: React.FormEventHandler = (event) => { - event.preventDefault(); - setLoading(true); - - dispatch(logIn(username, password) as any) - .then(({ access_token }: { access_token: string }) => ( - dispatch(verifyCredentials(access_token) as any) - // Refetch the instance for authenticated fetch - .then(() => dispatch(fetchInstance())) - .then(() => setShouldRedirect(true)) - )) - .catch((error: AxiosError) => { - setLoading(false); - - const data: any = error.response?.data; - if (data?.error === 'mfa_required') { - setMfaToken(data.mfa_token); - } - }); - }; - - if (account && shouldRedirect) return ; - if (mfaToken) return ; - - return ( -
- -
- ); -}; - -export default Header; diff --git a/src/features/public-layout/components/sonar.tsx b/src/features/public-layout/components/sonar.tsx deleted file mode 100644 index 1106d5ba5c..0000000000 --- a/src/features/public-layout/components/sonar.tsx +++ /dev/null @@ -1,16 +0,0 @@ -import React from 'react'; - -const Sonar = () => ( -
-
-
-
-
-
- -
-
-
-); - -export default Sonar; diff --git a/src/features/public-layout/index.tsx b/src/features/public-layout/index.tsx deleted file mode 100644 index e39bb7508b..0000000000 --- a/src/features/public-layout/index.tsx +++ /dev/null @@ -1,41 +0,0 @@ -import React from 'react'; -import { Switch, Route, Redirect } from 'react-router-dom'; - -import LandingGradient from 'soapbox/components/landing-gradient'; -import { useAppSelector } from 'soapbox/hooks'; -import { isStandalone } from 'soapbox/utils/state'; - -import LandingPage from '../landing-page'; - -import Footer from './components/footer'; -import Header from './components/header'; - -const PublicLayout = () => { - const standalone = useAppSelector((state) => isStandalone(state)); - - if (standalone) { - return ; - } - - return ( -
- - -
-
-
- -
- - - -
-
- -
-
- ); -}; - -export default PublicLayout;