Skip to content

Commit

Permalink
fix: better loading
Browse files Browse the repository at this point in the history
  • Loading branch information
rpenido committed Oct 25, 2023
1 parent d2c4985 commit 2a0244d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
13 changes: 10 additions & 3 deletions src/taxonomy/api/hooks/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,26 @@ export const useTaxonomyDetailDataResponse = (taxonomyId) => {
/**
* @param {number} taxonomyId
* @param {import("../types.mjs").QueryOptions} options
* @returns {Pick<import('@tanstack/react-query').UseQueryResult, "error" | "isError" | "isFetched" | "isSuccess">}
* @returns {
* Pick<
* import('@tanstack/react-query').UseQueryResult,
* "error" | "isError" | "isFetched" | "isLoading" | "isSuccess"
* >
* }
*/
export const useTagListDataStatus = (taxonomyId, options) => {
const {
isError,
error,
isError,
isFetched,
isLoading,
isSuccess,
} = useTagListData(taxonomyId, options);
return {
isError,
error,
isError,
isFetched,
isLoading,
isSuccess,
};
};
Expand Down
22 changes: 12 additions & 10 deletions src/taxonomy/taxonomy-detail/TagListTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,33 @@ const TagListTable = ({ taxonomyId }) => {
});

const useTagListData = () => {
const { isError, isFetched } = useTagListDataStatus(taxonomyId, options);
const { isError, isFetched, isLoading } = useTagListDataStatus(taxonomyId, options);
const tagList = useTagListDataResponse(taxonomyId, options);
return { isError, isFetched, tagList };
return {
isError,
isFetched,
isLoading,
tagList,
};
};

const { tagList, isFetched } = useTagListData();
const { tagList, isLoading } = useTagListData();

const fetchData = (args) => {
if (!_.isEqual(args, options)) {
setOptions({ ...args });
}
};

if (!isFetched) {
return 'Loading...';
}

return (
<DataTable
isLoading={isLoading}
isPaginated
manualPagination
fetchData={fetchData}
data={tagList.results}
itemCount={tagList.count}
pageCount={tagList.numPages}
data={tagList?.results || []}
itemCount={tagList?.count}
pageCount={tagList?.numPages}
initialState={options}
columns={[
{
Expand Down

0 comments on commit 2a0244d

Please sign in to comment.