Skip to content

Commit

Permalink
[App]: change loading flow of documents page
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekseyManetov committed Jun 7, 2024
1 parent 5385312 commit 16271f8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions app/src/common/sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ export interface SidebarProps<TItem extends TreeListItem = TreeListItem> {
}

function getItemParents<TItem extends TreeListItem>(allItems: TItem[], itemId: string): string[] {
const { parentId } = allItems.find((i) => i.id === itemId);
const item = allItems.find((i) => i.id === itemId);
const parents = [];
if (parentId) {
parents.push(parentId);
const otherParents = getItemParents(allItems, parentId);
if (item?.parentId) {
parents.push(item.parentId);
const otherParents = getItemParents(allItems, item.parentId);
parents.push(...otherParents);
}
return parents;
Expand Down
16 changes: 8 additions & 8 deletions app/src/documents/DocumentsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ async function loadApiReferenceStructure(): Promise<DocItem[]> {
}, [root]);
}

function useItems(selectedId: string): { items: DocItem[], PageComponent: any } {
function useItems(selectedId: string) {
const [apiRefItems, setApiRefItems] = useState<DocItem[]>();

useEffect(() => {
loadApiReferenceStructure().then((res) => {
setApiRefItems(res);
});
}, []);

return useMemo(() => {
if (apiRefItems) {
const items = itemsStructure.concat(apiRefItems);
Expand Down Expand Up @@ -75,11 +77,6 @@ export function DocumentsPage() {
return () => codesandboxService.clearFiles();
}, []);

if (!itemsInfo?.PageComponent) {
return null;
}
const { items, PageComponent } = itemsInfo;

const onChange = (row: DataRowProps<TreeListItem, string>) => {
if (row.parentId === 'components') {
redirectTo({
Expand All @@ -93,13 +90,16 @@ export function DocumentsPage() {
redirectTo({ id: row.id, category: row.parentId });
}
};

const PageComponent = itemsInfo?.PageComponent;

return (
<Page renderHeader={ () => <AppHeader /> }>
<FlexRow alignItems="stretch">
<Sidebar<DocItem>
value={ queryParamId }
onValueChange={ onChange }
items={ items }
items={ itemsInfo?.items }
getSearchFields={ (i) => [i.name, ...(i.tags || [])] }
getItemLink={ (row) =>
!row.isFoldable && {
Expand All @@ -112,7 +112,7 @@ export function DocumentsPage() {
},
} }
/>
<PageComponent />
{ PageComponent && <PageComponent /> }
</FlexRow>
</Page>
);
Expand Down

0 comments on commit 16271f8

Please sign in to comment.