From 107f0f6fa3b6c6f8b77a99a81935612ec77a76d9 Mon Sep 17 00:00:00 2001 From: Tilman Vatteroth Date: Wed, 10 Mar 2021 22:45:05 +0100 Subject: [PATCH] Code improvements (#1086) * Extract code into hook * Refactor code to remove let * Reformat code * Extract version-info-modal into components * Use main block in landinglayout * Add fixedWidth and classname attribute to IconButton Signed-off-by: Tilman Vatteroth --- cypress/integration/intro.spec.ts | 3 +- .../common/icon-button/icon-button.tsx | 13 ++-- src/components/common/links/internal-link.tsx | 16 ++--- src/components/common/modals/common-modal.tsx | 11 ++-- .../landing-layout/footer/language-picker.tsx | 61 ++++++++++------- .../footer/powered-by-links.tsx | 13 ++-- .../landing-layout/footer/social-links.tsx | 10 ++- .../landing-layout/footer/version-info.tsx | 65 ------------------- .../footer/version-info/version-info-link.tsx | 25 +++++++ .../version-info-modal-column.tsx | 42 ++++++++++++ .../version-info/version-info-modal.tsx | 38 +++++++++++ .../landing-layout/landing-layout.tsx | 10 +-- .../navigation/user-dropdown.tsx | 15 +++-- .../login-page/auth/via-internal.tsx | 12 ++-- 14 files changed, 192 insertions(+), 142 deletions(-) delete mode 100644 src/components/landing-layout/footer/version-info.tsx create mode 100644 src/components/landing-layout/footer/version-info/version-info-link.tsx create mode 100644 src/components/landing-layout/footer/version-info/version-info-modal-column.tsx create mode 100644 src/components/landing-layout/footer/version-info/version-info-modal.tsx diff --git a/cypress/integration/intro.spec.ts b/cypress/integration/intro.spec.ts index ef153b942..2acd15294 100644 --- a/cypress/integration/intro.spec.ts +++ b/cypress/integration/intro.spec.ts @@ -53,8 +53,7 @@ describe('Intro page', () => { .click() cy.get('[data-cy="version-modal"]') .should('be.visible') - cy.get('[data-cy="version-modal"] [data-cy="close-version-modal-button"]') - .contains('Close') + cy.get('[data-cy="version-modal"] .modal-header .close') .click() cy.get('[data-cy="version-modal"]') .should('not.exist') diff --git a/src/components/common/icon-button/icon-button.tsx b/src/components/common/icon-button/icon-button.tsx index e248d9ad9..0facb1a89 100644 --- a/src/components/common/icon-button/icon-button.tsx +++ b/src/components/common/icon-button/icon-button.tsx @@ -1,7 +1,7 @@ /* - SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) - - SPDX-License-Identifier: AGPL-3.0-only + * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) + * + * SPDX-License-Identifier: AGPL-3.0-only */ import React from 'react' @@ -15,14 +15,15 @@ export interface IconButtonProps extends ButtonProps { icon: IconName onClick?: () => void border?: boolean + iconFixedWidth?: boolean } -export const IconButton: React.FC = ({ icon, children, border = false, ...props }) => { +export const IconButton: React.FC = ({ icon, children, iconFixedWidth = false, border = false, className, ...props }) => { return ( - - - - ) -} diff --git a/src/components/landing-layout/footer/version-info/version-info-link.tsx b/src/components/landing-layout/footer/version-info/version-info-link.tsx new file mode 100644 index 000000000..bd6827552 --- /dev/null +++ b/src/components/landing-layout/footer/version-info/version-info-link.tsx @@ -0,0 +1,25 @@ +/* + * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) + * + * SPDX-License-Identifier: AGPL-3.0-only + */ + +import React, { Fragment, useCallback, useState } from 'react' +import { Trans } from 'react-i18next' +import { Link } from 'react-router-dom' +import { VersionInfoModal } from './version-info-modal' + +export const VersionInfoLink: React.FC = () => { + const [show, setShow] = useState(false) + const closeModal = useCallback(() => setShow(false), []) + const showModal = useCallback(() => setShow(true), []) + + return ( + + + + + + + ) +} diff --git a/src/components/landing-layout/footer/version-info/version-info-modal-column.tsx b/src/components/landing-layout/footer/version-info/version-info-modal-column.tsx new file mode 100644 index 000000000..e99e2d8ea --- /dev/null +++ b/src/components/landing-layout/footer/version-info/version-info-modal-column.tsx @@ -0,0 +1,42 @@ +/* + * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) + * + * SPDX-License-Identifier: AGPL-3.0-only + */ + +import React from 'react' +import Col from 'react-bootstrap/esm/Col' +import { CopyableField } from '../../../common/copyable/copyable-field/copyable-field' +import { TranslatedExternalLink } from '../../../common/links/translated-external-link' +import { ShowIf } from '../../../common/show-if/show-if' +import { Trans, useTranslation } from 'react-i18next' + +export interface VersionInfoModalColumnProps { + titleI18nKey: string, + version: string, + sourceCodeLink: string, + issueTrackerLink: string +} + +export const VersionInfoModalColumn: React.FC = ({ titleI18nKey, issueTrackerLink, sourceCodeLink, version }) => { + useTranslation() + + return ( + +
+ + + + + + + + + ) +} diff --git a/src/components/landing-layout/footer/version-info/version-info-modal.tsx b/src/components/landing-layout/footer/version-info/version-info-modal.tsx new file mode 100644 index 000000000..f7fbe336a --- /dev/null +++ b/src/components/landing-layout/footer/version-info/version-info-modal.tsx @@ -0,0 +1,38 @@ +/* + * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) + * + * SPDX-License-Identifier: AGPL-3.0-only + */ + +import React from 'react' +import { CommonModal, CommonModalProps } from '../../../common/modals/common-modal' +import { Modal, Row } from 'react-bootstrap' +import { VersionInfoModalColumn } from './version-info-modal-column' +import frontendVersion from '../../../../version.json' +import { useSelector } from 'react-redux' +import { ApplicationState } from '../../../../redux' +import equal from 'fast-deep-equal' + +export const VersionInfoModal: React.FC = ({ onHide, show }) => { + const serverVersion = useSelector((state: ApplicationState) => state.config.version, equal) + + return ( + + + + + + + + + ) +} diff --git a/src/components/landing-layout/landing-layout.tsx b/src/components/landing-layout/landing-layout.tsx index 29289cfb0..37ee7bc84 100644 --- a/src/components/landing-layout/landing-layout.tsx +++ b/src/components/landing-layout/landing-layout.tsx @@ -1,7 +1,7 @@ /* - SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) - - SPDX-License-Identifier: AGPL-3.0-only + * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) + * + * SPDX-License-Identifier: AGPL-3.0-only */ import React from 'react' @@ -19,9 +19,9 @@ export const LandingLayout: React.FC = ({ children }) => {
-
+
{ children } -
+
diff --git a/src/components/landing-layout/navigation/user-dropdown.tsx b/src/components/landing-layout/navigation/user-dropdown.tsx index b823bba87..2c916393d 100644 --- a/src/components/landing-layout/navigation/user-dropdown.tsx +++ b/src/components/landing-layout/navigation/user-dropdown.tsx @@ -1,7 +1,7 @@ /* - SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) - - SPDX-License-Identifier: AGPL-3.0-only + * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) + * + * SPDX-License-Identifier: AGPL-3.0-only */ import equal from 'fast-deep-equal' @@ -42,10 +42,11 @@ export const UserDropdown: React.FC = () => { - { - clearUser() - } }> + { + clearUser() + } }> diff --git a/src/components/login-page/auth/via-internal.tsx b/src/components/login-page/auth/via-internal.tsx index ab3d449d3..2a3c65877 100644 --- a/src/components/login-page/auth/via-internal.tsx +++ b/src/components/login-page/auth/via-internal.tsx @@ -1,7 +1,7 @@ /* - SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) - - SPDX-License-Identifier: AGPL-3.0-only + * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) + * + * SPDX-License-Identifier: AGPL-3.0-only */ import React, { FormEvent, useCallback, useState } from 'react' @@ -42,8 +42,7 @@ export const ViaInternal: React.FC = () => { size="sm" placeholder={ t('login.auth.username') } onChange={ (event) => setUsername(event.currentTarget.value) } className="bg-dark text-light" - autoComplete='username' - /> + autoComplete='username'/> @@ -54,8 +53,7 @@ export const ViaInternal: React.FC = () => { placeholder={ t('login.auth.password') } onChange={ (event) => setPassword(event.currentTarget.value) } className="bg-dark text-light" - autoComplete='current-password' - /> + autoComplete='current-password'/>