fix: Failure loading collections on frontend results in loading loop (#2176)
Co-authored-by: Tom Moor <tom.moor@gmail.com>
This commit is contained in:
@ -20,6 +20,7 @@ type Props = {
|
|||||||
|
|
||||||
function Collections({ onCreateCollection }: Props) {
|
function Collections({ onCreateCollection }: Props) {
|
||||||
const [isFetching, setFetching] = React.useState(false);
|
const [isFetching, setFetching] = React.useState(false);
|
||||||
|
const [fetchError, setFetchError] = React.useState();
|
||||||
const { ui, policies, documents, collections } = useStores();
|
const { ui, policies, documents, collections } = useStores();
|
||||||
const isPreloaded: boolean = !!collections.orderedData.length;
|
const isPreloaded: boolean = !!collections.orderedData.length;
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@ -32,17 +33,25 @@ function Collections({ onCreateCollection }: Props) {
|
|||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
async function load() {
|
async function load() {
|
||||||
if (!collections.isLoaded && !isFetching) {
|
if (!collections.isLoaded && !isFetching && !fetchError) {
|
||||||
try {
|
try {
|
||||||
setFetching(true);
|
setFetching(true);
|
||||||
await collections.fetchPage({ limit: 100 });
|
await collections.fetchPage({ limit: 100 });
|
||||||
|
} catch (error) {
|
||||||
|
ui.showToast(
|
||||||
|
t("Collections could not be loaded, please reload the app"),
|
||||||
|
{
|
||||||
|
type: "error",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
setFetchError(error);
|
||||||
} finally {
|
} finally {
|
||||||
setFetching(false);
|
setFetching(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
load();
|
load();
|
||||||
}, [collections, isFetching]);
|
}, [collections, isFetching, ui, fetchError, t]);
|
||||||
|
|
||||||
const [{ isCollectionDropping }, dropToReorderCollection] = useDrop({
|
const [{ isCollectionDropping }, dropToReorderCollection] = useDrop({
|
||||||
accept: "collection",
|
accept: "collection",
|
||||||
@ -92,7 +101,7 @@ function Collections({ onCreateCollection }: Props) {
|
|||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!collections.isLoaded) {
|
if (!collections.isLoaded || fetchError) {
|
||||||
return (
|
return (
|
||||||
<Flex column>
|
<Flex column>
|
||||||
<Header>{t("Collections")}</Header>
|
<Header>{t("Collections")}</Header>
|
||||||
|
@ -109,6 +109,7 @@
|
|||||||
"Dismiss": "Dismiss",
|
"Dismiss": "Dismiss",
|
||||||
"Keyboard shortcuts": "Keyboard shortcuts",
|
"Keyboard shortcuts": "Keyboard shortcuts",
|
||||||
"Back": "Back",
|
"Back": "Back",
|
||||||
|
"Collections could not be loaded, please reload the app": "Collections could not be loaded, please reload the app",
|
||||||
"New collection": "New collection",
|
"New collection": "New collection",
|
||||||
"Collections": "Collections",
|
"Collections": "Collections",
|
||||||
"Untitled": "Untitled",
|
"Untitled": "Untitled",
|
||||||
|
Reference in New Issue
Block a user