From deb165325d22b46ee2ee0c0eae8c037f0f5e389b Mon Sep 17 00:00:00 2001 From: atanasster Date: Sun, 30 Aug 2020 01:28:01 +0300 Subject: [PATCH] fix: missing component check --- core/store/src/state/context/components.ts | 7 ++++--- core/store/src/state/recoil/components.ts | 9 ++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/core/store/src/state/context/components.ts b/core/store/src/state/context/components.ts index 2a7db5a86..85403934d 100644 --- a/core/store/src/state/context/components.ts +++ b/core/store/src/state/context/components.ts @@ -6,7 +6,7 @@ import { } from '@component-controls/core'; import { useStore } from './store'; -import { useStory } from './story'; +import { useStory, useCurrentStory } from './story'; import { useCurrentDocument } from './document'; export interface ComponentInputProps { @@ -134,13 +134,14 @@ export const useComponent = ({ */ export const useCurrentPropsCount = (): number => { - const components = useComponents({ of: '.' }); const store = useStore(); + const story = useCurrentStory(); + const components = useComponents({ name: story?.id }); const doc = useCurrentDocument(); return components && doc ? Object.keys(components).reduce((acc, key) => { const component = store.components[doc.componentsLookup[key]]; - return acc + Object.keys(component.info?.props || {}).length; + return acc + Object.keys(component?.info?.props || {}).length; }, 0) : 0; }; diff --git a/core/store/src/state/recoil/components.ts b/core/store/src/state/recoil/components.ts index ac0892890..294dd2429 100644 --- a/core/store/src/state/recoil/components.ts +++ b/core/store/src/state/recoil/components.ts @@ -6,7 +6,7 @@ import { } from '@component-controls/core'; import { useStore } from './store'; -import { useStory } from './story'; +import { useStory, useCurrentStory } from './story'; import { useCurrentDocument } from './document'; export interface ComponentInputProps { @@ -32,7 +32,9 @@ export const useComponents = ({ name, }: ComponentInputProps): Components => { const store = useStore(); - const story = useStory({ id: name }); + const story = + of === CURRENT_STORY ? useCurrentStory() : useStory({ id: name }); + const { component: storyComponentName } = story || {}; const storyComponent = getComponentName(storyComponentName); const doc = story && story.doc ? store.docs[story.doc] : undefined; @@ -133,8 +135,9 @@ export const useComponent = ({ */ export const useCurrentPropsCount = (): number => { - const components = useComponents({ of: '.' }); const store = useStore(); + const story = useCurrentStory(); + const components = useComponents({ name: story?.id }); const doc = useCurrentDocument(); return components && doc ? Object.keys(components).reduce((acc, key) => {