Skip to content

Commit

Permalink
Fix block adding (esp w index)
Browse files Browse the repository at this point in the history
  • Loading branch information
KaWaite committed Aug 9, 2023
1 parent 1533c67 commit ca63014
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const StyledIcon = styled(Icon)`
padding: 2px;
cursor: pointer;
transition: opacity 0.4s;
z-index: 100;
`;

const Line = styled.div`
Expand Down
3 changes: 2 additions & 1 deletion web/src/beta/features/Editor/StoryPanel/Page/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ export default ({
});

const handleStoryBlockCreate = useCallback(
async (extensionId?: string, pluginId?: string) => {
(index?: number) => async (extensionId?: string, pluginId?: string) => {
if (!extensionId || !pluginId || !storyId || !pageId) return;
await useCreateStoryBlock({
pluginId,
extensionId,
storyId,
pageId,
index,
});
},
[storyId, pageId, useCreateStoryBlock],
Expand Down
21 changes: 10 additions & 11 deletions web/src/beta/features/Editor/StoryPanel/Page/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,14 @@ const StoryPage: React.FC<Props> = ({
<Text size="h2" customColor>
{pageTitle ?? "No Title"}
</Text>
{installedStoryBlocks && installedStoryBlocks.length > 0 ? (
<BlockAddBar
openBlocks={openBlocksIndex === -1}
installableStoryBlocks={installableStoryBlocks}
onBlockOpen={() => handleBlockOpen(-1)}
onBlockAdd={handleStoryBlockCreate(0)}
/>
{installedStoryBlocks &&
installedStoryBlocks.length > 0 &&
installedStoryBlocks?.map((b, idx) => (
<Fragment key={idx}>
<StoryBlock
Expand All @@ -65,18 +72,10 @@ const StoryPage: React.FC<Props> = ({
openBlocks={openBlocksIndex === idx}
installableStoryBlocks={installableStoryBlocks}
onBlockOpen={() => handleBlockOpen(idx)}
onBlockAdd={handleStoryBlockCreate}
onBlockAdd={handleStoryBlockCreate(idx + 1)}
/>
</Fragment>
))
) : (
<BlockAddBar
openBlocks={openBlocksIndex === -1}
installableStoryBlocks={installableStoryBlocks}
onBlockOpen={() => handleBlockOpen(-1)}
onBlockAdd={handleStoryBlockCreate}
/>
)}
))}
</Wrapper>
);
};
Expand Down

0 comments on commit ca63014

Please sign in to comment.