From 3dfad0cea5aba368be1046a795995c08e5556d40 Mon Sep 17 00:00:00 2001 From: Erik Michelson Date: Sat, 7 Oct 2023 12:03:49 +0200 Subject: [PATCH] enhancement: use isLoggedIn hook Signed-off-by: Erik Michelson --- frontend/src/app/(editor)/login/page.tsx | 10 ++++++++-- .../components/history-page/entry-menu/entry-menu.tsx | 5 +++-- .../history-page/history-toolbar/history-toolbar.tsx | 5 +++-- .../history-toolbar/import-history-button.tsx | 5 +++-- .../layout/app-bar/app-bar-elements/user-element.tsx | 4 ++-- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/frontend/src/app/(editor)/login/page.tsx b/frontend/src/app/(editor)/login/page.tsx index 1c1c0654c..1489e8434 100644 --- a/frontend/src/app/(editor)/login/page.tsx +++ b/frontend/src/app/(editor)/login/page.tsx @@ -1,3 +1,9 @@ +/* + * SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file) + * + * SPDX-License-Identifier: AGPL-3.0-only + */ + 'use client' /* @@ -14,16 +20,16 @@ import { Trans } from 'react-i18next' import { CustomBranding } from '../../../components/common/custom-branding/custom-branding' import { IntroCustomContent } from '../../../components/intro-page/intro-custom-content' import React from 'react' -import { useApplicationState } from '../../../hooks/common/use-application-state' import { RedirectToParamOrHistory } from '../../../components/login-page/redirect-to-param-or-history' import { Col, Container, Row } from 'react-bootstrap' import { LocalLoginCard } from '../../../components/login-page/local-login/local-login-card' import { LdapLoginCards } from '../../../components/login-page/ldap/ldap-login-cards' import { OneClickLoginCard } from '../../../components/login-page/one-click/one-click-login-card' import { GuestCard } from '../../../components/login-page/guest/guest-card' +import { useIsLoggedIn } from '../../../hooks/common/use-is-logged-in' const LoginPage: NextPage = () => { - const userLoggedIn = useApplicationState((state) => !!state.user) + const userLoggedIn = useIsLoggedIn() if (userLoggedIn) { return diff --git a/frontend/src/components/history-page/entry-menu/entry-menu.tsx b/frontend/src/components/history-page/entry-menu/entry-menu.tsx index 8226355c8..0a0649aff 100644 --- a/frontend/src/components/history-page/entry-menu/entry-menu.tsx +++ b/frontend/src/components/history-page/entry-menu/entry-menu.tsx @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) + * SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ @@ -15,6 +15,7 @@ import React from 'react' import { Dropdown } from 'react-bootstrap' import { Cloud as IconCloud, Laptop as IconLaptop, ThreeDots as IconThreeDots } from 'react-bootstrap-icons' import { Trans, useTranslation } from 'react-i18next' +import { useIsLoggedIn } from '../../../hooks/common/use-is-logged-in' export interface EntryMenuProps { id: string @@ -44,7 +45,7 @@ export const EntryMenu: React.FC = ({ className }) => { useTranslation() - const userExists = useApplicationState((state) => !!state.user) + const userExists = useIsLoggedIn() return ( diff --git a/frontend/src/components/history-page/history-toolbar/history-toolbar.tsx b/frontend/src/components/history-page/history-toolbar/history-toolbar.tsx index 842b5471b..b4e974754 100644 --- a/frontend/src/components/history-page/history-toolbar/history-toolbar.tsx +++ b/frontend/src/components/history-page/history-toolbar/history-toolbar.tsx @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) + * SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ @@ -24,6 +24,7 @@ import { useSyncToolbarStateToUrlEffect } from './toolbar-context/use-sync-toolb import React, { useCallback } from 'react' import { Button, Col } from 'react-bootstrap' import { CloudUpload as IconCloudUpload } from 'react-bootstrap-icons' +import { useIsLoggedIn } from '../../../hooks/common/use-is-logged-in' export enum ViewStateEnum { CARD, @@ -35,7 +36,7 @@ export enum ViewStateEnum { */ export const HistoryToolbar: React.FC = () => { const historyEntries = useApplicationState((state) => state.history) - const userExists = useApplicationState((state) => !!state.user) + const userExists = useIsLoggedIn() const { showErrorNotification } = useUiNotifications() const safeRefreshHistoryState = useSafeRefreshHistoryStateCallback() useSyncToolbarStateToUrlEffect() diff --git a/frontend/src/components/history-page/history-toolbar/import-history-button.tsx b/frontend/src/components/history-page/history-toolbar/import-history-button.tsx index 2918db665..d941b64d1 100644 --- a/frontend/src/components/history-page/history-toolbar/import-history-button.tsx +++ b/frontend/src/components/history-page/history-toolbar/import-history-button.tsx @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) + * SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ @@ -16,12 +16,13 @@ import { useSafeRefreshHistoryStateCallback } from './hooks/use-safe-refresh-his import React, { useCallback, useRef, useState } from 'react' import { Button } from 'react-bootstrap' import { Upload as IconUpload } from 'react-bootstrap-icons' +import { useIsLoggedIn } from '../../../hooks/common/use-is-logged-in' /** * Button that lets the user select a history JSON file and uploads imports that into the history. */ export const ImportHistoryButton: React.FC = () => { - const userExists = useApplicationState((state) => !!state.user) + const userExists = useIsLoggedIn() const historyState = useApplicationState((state) => state.history) const uploadInput = useRef(null) const [fileName, setFilename] = useState('') diff --git a/frontend/src/components/layout/app-bar/app-bar-elements/user-element.tsx b/frontend/src/components/layout/app-bar/app-bar-elements/user-element.tsx index e4f0809ab..06b83a13e 100644 --- a/frontend/src/components/layout/app-bar/app-bar-elements/user-element.tsx +++ b/frontend/src/components/layout/app-bar/app-bar-elements/user-element.tsx @@ -3,15 +3,15 @@ * * SPDX-License-Identifier: AGPL-3.0-only */ -import { useApplicationState } from '../../../../hooks/common/use-application-state' import { SignInButton } from '../../../landing-layout/navigation/sign-in-button' import { UserDropdown } from '../../../landing-layout/navigation/user-dropdown' import React from 'react' +import { useIsLoggedIn } from '../../../../hooks/common/use-is-logged-in' /** * Renders either the user dropdown or the sign-in button depending on the user state. */ export const UserElement: React.FC = () => { - const userExists = useApplicationState((state) => !!state.user) + const userExists = useIsLoggedIn() return userExists ? : }