mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-22 01:36:29 -05:00
enhancement: use isLoggedIn hook
Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
parent
8e10fb6804
commit
3dfad0cea5
5 changed files with 19 additions and 10 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file)
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
*/
|
||||||
|
|
||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -14,16 +20,16 @@ import { Trans } from 'react-i18next'
|
||||||
import { CustomBranding } from '../../../components/common/custom-branding/custom-branding'
|
import { CustomBranding } from '../../../components/common/custom-branding/custom-branding'
|
||||||
import { IntroCustomContent } from '../../../components/intro-page/intro-custom-content'
|
import { IntroCustomContent } from '../../../components/intro-page/intro-custom-content'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { useApplicationState } from '../../../hooks/common/use-application-state'
|
|
||||||
import { RedirectToParamOrHistory } from '../../../components/login-page/redirect-to-param-or-history'
|
import { RedirectToParamOrHistory } from '../../../components/login-page/redirect-to-param-or-history'
|
||||||
import { Col, Container, Row } from 'react-bootstrap'
|
import { Col, Container, Row } from 'react-bootstrap'
|
||||||
import { LocalLoginCard } from '../../../components/login-page/local-login/local-login-card'
|
import { LocalLoginCard } from '../../../components/login-page/local-login/local-login-card'
|
||||||
import { LdapLoginCards } from '../../../components/login-page/ldap/ldap-login-cards'
|
import { LdapLoginCards } from '../../../components/login-page/ldap/ldap-login-cards'
|
||||||
import { OneClickLoginCard } from '../../../components/login-page/one-click/one-click-login-card'
|
import { OneClickLoginCard } from '../../../components/login-page/one-click/one-click-login-card'
|
||||||
import { GuestCard } from '../../../components/login-page/guest/guest-card'
|
import { GuestCard } from '../../../components/login-page/guest/guest-card'
|
||||||
|
import { useIsLoggedIn } from '../../../hooks/common/use-is-logged-in'
|
||||||
|
|
||||||
const LoginPage: NextPage = () => {
|
const LoginPage: NextPage = () => {
|
||||||
const userLoggedIn = useApplicationState((state) => !!state.user)
|
const userLoggedIn = useIsLoggedIn()
|
||||||
|
|
||||||
if (userLoggedIn) {
|
if (userLoggedIn) {
|
||||||
return <RedirectToParamOrHistory />
|
return <RedirectToParamOrHistory />
|
||||||
|
|
|
@ -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
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
@ -15,6 +15,7 @@ import React from 'react'
|
||||||
import { Dropdown } from 'react-bootstrap'
|
import { Dropdown } from 'react-bootstrap'
|
||||||
import { Cloud as IconCloud, Laptop as IconLaptop, ThreeDots as IconThreeDots } from 'react-bootstrap-icons'
|
import { Cloud as IconCloud, Laptop as IconLaptop, ThreeDots as IconThreeDots } from 'react-bootstrap-icons'
|
||||||
import { Trans, useTranslation } from 'react-i18next'
|
import { Trans, useTranslation } from 'react-i18next'
|
||||||
|
import { useIsLoggedIn } from '../../../hooks/common/use-is-logged-in'
|
||||||
|
|
||||||
export interface EntryMenuProps {
|
export interface EntryMenuProps {
|
||||||
id: string
|
id: string
|
||||||
|
@ -44,7 +45,7 @@ export const EntryMenu: React.FC<EntryMenuProps> = ({
|
||||||
className
|
className
|
||||||
}) => {
|
}) => {
|
||||||
useTranslation()
|
useTranslation()
|
||||||
const userExists = useApplicationState((state) => !!state.user)
|
const userExists = useIsLoggedIn()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dropdown className={`d-inline-flex ${className || ''}`} {...cypressId('history-entry-menu')}>
|
<Dropdown className={`d-inline-flex ${className || ''}`} {...cypressId('history-entry-menu')}>
|
||||||
|
|
|
@ -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
|
* 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 React, { useCallback } from 'react'
|
||||||
import { Button, Col } from 'react-bootstrap'
|
import { Button, Col } from 'react-bootstrap'
|
||||||
import { CloudUpload as IconCloudUpload } from 'react-bootstrap-icons'
|
import { CloudUpload as IconCloudUpload } from 'react-bootstrap-icons'
|
||||||
|
import { useIsLoggedIn } from '../../../hooks/common/use-is-logged-in'
|
||||||
|
|
||||||
export enum ViewStateEnum {
|
export enum ViewStateEnum {
|
||||||
CARD,
|
CARD,
|
||||||
|
@ -35,7 +36,7 @@ export enum ViewStateEnum {
|
||||||
*/
|
*/
|
||||||
export const HistoryToolbar: React.FC = () => {
|
export const HistoryToolbar: React.FC = () => {
|
||||||
const historyEntries = useApplicationState((state) => state.history)
|
const historyEntries = useApplicationState((state) => state.history)
|
||||||
const userExists = useApplicationState((state) => !!state.user)
|
const userExists = useIsLoggedIn()
|
||||||
const { showErrorNotification } = useUiNotifications()
|
const { showErrorNotification } = useUiNotifications()
|
||||||
const safeRefreshHistoryState = useSafeRefreshHistoryStateCallback()
|
const safeRefreshHistoryState = useSafeRefreshHistoryStateCallback()
|
||||||
useSyncToolbarStateToUrlEffect()
|
useSyncToolbarStateToUrlEffect()
|
||||||
|
|
|
@ -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
|
* 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 React, { useCallback, useRef, useState } from 'react'
|
||||||
import { Button } from 'react-bootstrap'
|
import { Button } from 'react-bootstrap'
|
||||||
import { Upload as IconUpload } from 'react-bootstrap-icons'
|
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.
|
* Button that lets the user select a history JSON file and uploads imports that into the history.
|
||||||
*/
|
*/
|
||||||
export const ImportHistoryButton: React.FC = () => {
|
export const ImportHistoryButton: React.FC = () => {
|
||||||
const userExists = useApplicationState((state) => !!state.user)
|
const userExists = useIsLoggedIn()
|
||||||
const historyState = useApplicationState((state) => state.history)
|
const historyState = useApplicationState((state) => state.history)
|
||||||
const uploadInput = useRef<HTMLInputElement>(null)
|
const uploadInput = useRef<HTMLInputElement>(null)
|
||||||
const [fileName, setFilename] = useState('')
|
const [fileName, setFilename] = useState('')
|
||||||
|
|
|
@ -3,15 +3,15 @@
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* 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 { SignInButton } from '../../../landing-layout/navigation/sign-in-button'
|
||||||
import { UserDropdown } from '../../../landing-layout/navigation/user-dropdown'
|
import { UserDropdown } from '../../../landing-layout/navigation/user-dropdown'
|
||||||
import React from 'react'
|
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.
|
* Renders either the user dropdown or the sign-in button depending on the user state.
|
||||||
*/
|
*/
|
||||||
export const UserElement: React.FC = () => {
|
export const UserElement: React.FC = () => {
|
||||||
const userExists = useApplicationState((state) => !!state.user)
|
const userExists = useIsLoggedIn()
|
||||||
return userExists ? <UserDropdown /> : <SignInButton size={'sm'} className={'h-100'} />
|
return userExists ? <UserDropdown /> : <SignInButton size={'sm'} className={'h-100'} />
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue