Skip to content

Commit

Permalink
chore: add loading states for root resolveData
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvxd committed Oct 31, 2023
1 parent 7593584 commit c61cfa4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/core/components/Puck/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -604,8 +604,9 @@ export function Puck({
showBreadcrumbs
title={selectedItem ? selectedItem.type : "Page"}
isLoading={
selectedItem &&
componentState[selectedItem?.props.id]?.loading
selectedItem
? componentState[selectedItem?.props.id]?.loading
: componentState["puck-root"]?.loading
}
>
{Object.keys(fields).map((fieldName) => {
Expand Down
10 changes: 10 additions & 0 deletions packages/core/lib/use-resolved-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,18 @@ export const useResolvedData = (
}));
}
).then(async (dynamicContent) => {
setComponentState((prev) => ({
...prev,
"puck-root": { ...prev["puck-root"], loading: true },
}));

const dynamicRoot = await resolveRootData(data, config);

setComponentState((prev) => ({
...prev,
"puck-root": { ...prev["puck-root"], loading: false },
}));

const newDynamicProps = dynamicContent.reduce<Record<string, any>>(
(acc, item) => {
return { ...acc, [item.props.id]: item };
Expand Down

0 comments on commit c61cfa4

Please sign in to comment.