hedgedoc/src/components/history-page/history-page.tsx
Erik Michelson 003658dc4d
The History PR: II - Add URL params (#1157)
* Add location state dependency

Signed-off-by: Erik Michelson <github@erik.michelson.eu>

* Split toolbar state into single location states

Signed-off-by: Erik Michelson <github@erik.michelson.eu>

* Add CHANGELOG entry

Signed-off-by: Erik Michelson <github@erik.michelson.eu>

* Pin dependency

Signed-off-by: Erik Michelson <github@erik.michelson.eu>

* Use react state for view because of side-effects

The locationState was resetted on each search or tags filter update because these updates pushed a change to the location thus resulting in loss of the location state for the view.

Signed-off-by: Erik Michelson <github@erik.michelson.eu>

* Remove unneeded import

Signed-off-by: Erik Michelson <github@erik.michelson.eu>

* Change CHANGELOG entry

Signed-off-by: Erik Michelson <github@erik.michelson.eu>

* Removed unnecessary typecast

Signed-off-by: Erik Michelson <github@erik.michelson.eu>
2021-04-24 23:25:01 +02:00

51 lines
1.7 KiB
TypeScript

/*
SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
SPDX-License-Identifier: AGPL-3.0-only
*/
import React, { Fragment, useEffect, useMemo, useState } from 'react'
import { Row } from 'react-bootstrap'
import { Trans, useTranslation } from 'react-i18next'
import { useSelector } from 'react-redux'
import { ApplicationState } from '../../redux'
import { HistoryContent } from './history-content/history-content'
import { HistoryToolbar, HistoryToolbarState, initToolbarState } from './history-toolbar/history-toolbar'
import { sortAndFilterEntries } from './utils'
import { refreshHistoryState } from '../../redux/history/methods'
import { HistoryEntry } from '../../redux/history/types'
import { showErrorNotification } from '../../redux/ui-notifications/methods'
export const HistoryPage: React.FC = () => {
const { t } = useTranslation()
const allEntries = useSelector((state: ApplicationState) => state.history)
const [toolbarState, setToolbarState] = useState<HistoryToolbarState>(initToolbarState)
const entriesToShow = useMemo<HistoryEntry[]>(() =>
sortAndFilterEntries(allEntries, toolbarState),
[allEntries, toolbarState])
useEffect(() => {
refreshHistoryState().catch(
showErrorNotification(t('landing.history.error.getHistory.text'))
)
}, [t])
return (
<Fragment>
<h1 className="mb-4">
<Trans i18nKey="landing.navigation.history"/>
</h1>
<Row className={ 'justify-content-center mt-5 mb-3' }>
<HistoryToolbar
onSettingsChange={ setToolbarState }
/>
</Row>
<HistoryContent
viewState={ toolbarState.viewState }
entries={ entriesToShow }
/>
</Fragment>
)
}