Skip to content

Commit

Permalink
feat: trigger loading after mount
Browse files Browse the repository at this point in the history
  • Loading branch information
wmahad committed Jul 29, 2020
1 parent 816209c commit 752a193
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 22 deletions.
10 changes: 7 additions & 3 deletions src/components/autoComplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,13 @@
};
}, [searchParam]);

if (loading) {
B.triggerEvent('onLoad', loading);
}
const mounted = useRef(true);
useEffect(() => {
if (!mounted.current && loading) {
B.triggerEvent('onLoad', loading);
}
mounted.current = false;
}, [loading]);

if (err && !displayError) {
B.triggerEvent('onError', err.message);
Expand Down
10 changes: 7 additions & 3 deletions src/components/checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,13 @@
const { loading, error: err, data, refetch } =
model && useGetAll(model, { filter, skip: 0, take: 50 });

if (loading) {
B.triggerEvent('onLoad', loading);
}
const mounted = useRef(true);
useEffect(() => {
if (!mounted.current && loading) {
B.triggerEvent('onLoad', loading);
}
mounted.current = false;
}, [loading]);

if (err && !displayError) {
B.triggerEvent('onError', err.message);
Expand Down
13 changes: 9 additions & 4 deletions src/components/dataList.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,20 @@
});
}, []);

const mounted = useRef(true);
useEffect(() => {
if (!mounted.current && loading) {
B.triggerEvent('onLoad', loading);
}
mounted.current = false;
}, [loading]);

const canvasLayout = () => {
if (!model) {
return builderLayout();
}

if (loading) {
B.triggerEvent('onLoad', loading);
return 'loading...';
}
if (loading) return 'loading...';

if (error && !displayError) {
B.triggerEvent('onError', error.message);
Expand Down
10 changes: 7 additions & 3 deletions src/components/dataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,13 @@
repeat();
});

if (loading) {
B.triggerEvent('onLoad', loading);
}
const mounted = useRef(true);
useEffect(() => {
if (!mounted.current && loading) {
B.triggerEvent('onLoad', loading);
}
mounted.current = false;
}, [loading]);

if (error && !displayError) {
B.triggerEvent('onError', error.message);
Expand Down
10 changes: 7 additions & 3 deletions src/components/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,13 @@
B.triggerEvent('onLoad', loading);
}

if (isFetching) {
B.triggerEvent('onLoad', isFetching);
}
const mounted = useRef(true);
useEffect(() => {
if (!mounted.current && isFetching) {
B.triggerEvent('onLoad', isFetching);
}
mounted.current = false;
}, [isFetching]);

if (err && !displayError) {
B.triggerEvent('onError', formErrorMessage || err.message);
Expand Down
10 changes: 7 additions & 3 deletions src/components/radio.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,13 @@
const { loading, error: err, data, refetch } =
model && useGetAll(model, { filter, skip: 0, take: 50 });

if (loading) {
B.triggerEvent('onLoad', loading);
}
const mounted = useRef(true);
useEffect(() => {
if (!mounted.current && loading) {
B.triggerEvent('onLoad', loading);
}
mounted.current = false;
}, [loading]);

if (err && !displayError) {
B.triggerEvent('onError', err.message);
Expand Down
10 changes: 7 additions & 3 deletions src/components/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,13 @@
const { loading, error, data, refetch } =
model && useGetAll(model, { filter, skip: 0, take: 50 });

if (loading) {
B.triggerEvent('onLoad', loading);
}
const mounted = useRef(true);
useEffect(() => {
if (!mounted.current && loading) {
B.triggerEvent('onLoad', loading);
}
mounted.current = false;
}, [loading]);

if (error && !displayError) {
B.triggerEvent('onError', error.message);
Expand Down

0 comments on commit 752a193

Please sign in to comment.