Skip to content

Commit

Permalink
clip: Reload sources by clicking sources button
Browse files Browse the repository at this point in the history
  • Loading branch information
jtojnar committed Jan 5, 2022
1 parent 7e18294 commit 54f1530
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
12 changes: 11 additions & 1 deletion assets/js/templates/NavToolBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Link } from 'react-router-dom';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import * as icons from '../icons';
import { LocalizationContext } from '../helpers/i18n';
import { forceReload } from '../helpers/uri';

function handleReloadAll({ reloadAll, setReloading, setNavExpanded }) {
setReloading(true);
Expand Down Expand Up @@ -39,6 +40,15 @@ export default function NavToolBar({ reloadAll, setNavExpanded }) {
[setNavExpanded]
);

const settingsLink = React.useCallback(
(location) => ({
...location,
pathname: '/manage/sources',
state: forceReload(location),
}),
[]
);

const logoutOnClick = React.useCallback(
() => handleLogOut({ setNavExpanded }),
[setNavExpanded]
Expand Down Expand Up @@ -66,7 +76,7 @@ export default function NavToolBar({ reloadAll, setNavExpanded }) {
title={_('settingsbutton')}
aria-label={_('settingsbutton')}
accessKey="t"
to="/manage/sources"
to={settingsLink}
onClick={settingsOnClick}
>
<FontAwesomeIcon
Expand Down
5 changes: 4 additions & 1 deletion assets/js/templates/SourcesPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { SpinnerBig } from './Spinner';
import { LoadingState } from '../requests/LoadingState';
import * as sourceRequests from '../requests/sources';
import { getAllSources } from '../requests/sources';
import { useShouldReload } from '../helpers/hooks';
import { LocalizationContext } from '../helpers/i18n';
import { HttpError } from '../errors';

Expand Down Expand Up @@ -75,6 +76,8 @@ export default function SourcesPage() {

const [loadingState, setLoadingState] = React.useState(LoadingState.INITIAL);

const forceReload = useShouldReload();

React.useEffect(() => {
const abortController = new AbortController();

Expand All @@ -83,7 +86,7 @@ export default function SourcesPage() {
return () => {
abortController.abort();
};
}, []);
}, [forceReload]);

const addOnClick = React.useCallback(
(event) => handleAddSource({ event, setSources, setSpouts }),
Expand Down

0 comments on commit 54f1530

Please sign in to comment.