Skip to content

Commit

Permalink
wip await useNavigate and useRevalidator
Browse files Browse the repository at this point in the history
  • Loading branch information
Zasa-san committed Jan 21, 2025
1 parent 11576d3 commit 3291d32
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 24 deletions.
14 changes: 7 additions & 7 deletions app/react/I18N/components/I18NLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,20 @@ const I18NLink = (props: I18NLinkProps) => {
}, delay);
};

const _navigate = () => {
navigate(to, { replace });
const _navigate = async () => {
await navigate(to, { replace });
scrollToHashWithRetry(location.hash);
};

const onClickHandler = (e: { preventDefault: () => void }) => {
const onClickHandler = async (e: { preventDefault: () => void }) => {
e.preventDefault();
if (disabled) return;

if (onClick && confirmTitle) {
props.mainContext.confirm({
accept: () => {
accept: async () => {
onClick(e);
_navigate();
await _navigate();
},
title: confirmTitle,
message: confirmMessage,
Expand All @@ -71,10 +71,10 @@ const I18NLink = (props: I18NLinkProps) => {

if (onClick) {
onClick(e);
_navigate();
await _navigate();
return;
}
_navigate();
await _navigate();
};

useEffect(() => {
Expand Down
4 changes: 2 additions & 2 deletions app/react/Library/actions/libraryActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ function encodeSearch(_search, appendQ = true) {
return appendQ ? `?q=${encodedSearch}` : encodedSearch;
}

function setSearchInUrl(searchParams, location, navigate) {
async function setSearchInUrl(searchParams, location, navigate) {
const { pathname } = location;
const path = `${pathname}/`.replace(/\/\//g, '/');
const query = new URLSearchParams(location.search);
Expand All @@ -246,7 +246,7 @@ function searchDocuments(
limit = 30,
from = 0
) {
return (dispatch, getState) => {
return async (dispatch, getState) => {
const state = getState().library;
const currentSearch = search || state.search;
const currentFilters = filters || state.filters;
Expand Down
4 changes: 2 additions & 2 deletions app/react/Markdown/components/SearchBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { SearchTipsContent } from 'app/App/SearchTipsContent';
const SearchBox = ({ placeholder, classname }) => {
const navigate = useNavigate();

const search = ({ searchTerm }) => {
navigate(`/library/?q=${rison.encode({ searchTerm })}`);
const search = async ({ searchTerm }) => {
await navigate(`/library/?q=${rison.encode({ searchTerm })}`);
};

return (
Expand Down
10 changes: 5 additions & 5 deletions app/react/V2/Routes/Settings/Pages/PageEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ const PageEditor = () => {
});
};

const handleRevalidate = (response: Page) => {
const handleRevalidate = async (response: Page) => {
if (!page.sharedId) {
navigate(`/${response.language}/settings/pages/page/${response.sharedId}`, {
await navigate(`/${response.language}/settings/pages/page/${response.sharedId}`, {
replace: true,
});
} else {
revalidator.revalidate();
await revalidator.revalidate();
}
};

Expand All @@ -106,7 +106,7 @@ const PageEditor = () => {
notify(response);

if (!hasErrors) {
handleRevalidate(response);
await handleRevalidate(response);
}
};

Expand All @@ -119,7 +119,7 @@ const PageEditor = () => {
if (!hasErrors) {
const pageUrl = getPageUrl(response.sharedId!, response.title);
window.open(`${window.location.origin}/${pageUrl}`);
handleRevalidate(response);
await handleRevalidate(response);
}
};

Expand Down
4 changes: 2 additions & 2 deletions app/react/V2/Routes/Settings/Thesauri/EditThesaurus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@ const EditThesaurus = () => {
}}
disabled={isEmpty(getValues().name)}
getThesaurus={getCurrentStatus}
onSuccess={(savedThesaurus: ThesaurusSchema) => {
onSuccess={async (savedThesaurus: ThesaurusSchema) => {
setValue('_id', savedThesaurus._id);
setNotifications({
type: 'success',
text: <Translate>Thesauri updated.</Translate>,
});
navigate(`../edit/${savedThesaurus._id}`);
await navigate(`../edit/${savedThesaurus._id}`);
setIsImporting(false);
}}
onFailure={() => {
Expand Down
8 changes: 4 additions & 4 deletions app/react/V2/Routes/Settings/Thesauri/ThesaurusForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ const ThesaurusForm = ({
const [thesauri, setThesauri] = useAtom(thesauriAtom);
const setNotifications = useSetAtom(notificationAtom);

const handleRevalidate = (savedThesaurus: ClientThesaurus) => {
const handleRevalidate = async (savedThesaurus: ClientThesaurus) => {
if (!thesaurus?._id) {
navigate(`../edit/${savedThesaurus._id}`);
await navigate(`../edit/${savedThesaurus._id}`);
} else {
revalidator.revalidate();
await revalidator.revalidate();
}
};

Expand All @@ -68,7 +68,7 @@ const ThesaurusForm = ({
<Translate>Thesauri added.</Translate>
),
});
handleRevalidate(savedThesaurus);
await handleRevalidate(savedThesaurus);
};

const formSubmit: SubmitHandler<ClientThesaurus> = async data => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ interface ThesauriTableProps {

const ThesauriTable = ({ currentThesauri, setSelectedThesauri }: ThesauriTableProps) => {
const navigate = useNavigate();
const navigateToEditThesaurus = (thesaurus: Row<ThesauriRow>) => {
navigate(`./edit/${thesaurus.original._id}`);
const navigateToEditThesaurus = async (thesaurus: Row<ThesauriRow>) => {
await navigate(`./edit/${thesaurus.original._id}`);
};

return (
Expand Down

0 comments on commit 3291d32

Please sign in to comment.