Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
pmelab committed Nov 29, 2023
1 parent 616298d commit 0c6dff0
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/schema/src/operators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class OperatorRegistryError<OperationId extends AnyOperationId> extends Error {
export function createOperator<OperationId extends AnyOperationId>(
id: OperationId,
variables?: OperationVariables<OperationId>,
): () => OperationResult<OperationId> | Promise<OperationResult<OperationId>> {
) {
const op = getCandidates(id)
.filter((entry) => matchVariables(entry.variables, variables))
.pop();
Expand Down
42 changes: 41 additions & 1 deletion packages/ui/.storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,48 @@ const LocationDecorator: Decorator = (Story, ctx) => {
);
};

declare global {
interface Window {
__STORYBOOK_PREVIEW__: {
currentRender: {
id: string;
};
};
}
}

const SWRCacheDecorator: Decorator = (Story) => {
const { cache } = useSWRConfig();
for (const key of cache.keys()) {
cache.delete(key);
}
return (
<SWRConfig
value={{
use: [
(useSWR) => (key, fetcher, config) => {
return useSWR(
// Make sure SWR caches are unique per story.
[key, window.__STORYBOOK_PREVIEW__.currentRender.id],
fetcher,
config,
);
},
],
}}
>
<Story />
</SWRConfig>
);
};

export const parameters = {
chromatic: { viewports: [320, 840, 1440] },
};

export const decorators = [LocationDecorator, IntlDecorator, OperatorDecorator];
export const decorators = [
LocationDecorator,
IntlDecorator,
OperatorDecorator,
SWRCacheDecorator,
];
3 changes: 0 additions & 3 deletions packages/ui/src/components/Organisms/ContentHub.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ export const Empty = {
contentHub: { total: 0, items: [] },
})),
],
location: new URL('local:/content-hub?page=111'),
},
} satisfies StoryObj<typeof ContentHub>;

export const Loading = {
parameters: {
operators: [buildOperator(ContentHubQuery, () => new Promise(() => {}))],
location: new URL('local:/content-hub?page=222'),
},
} satisfies StoryObj<typeof ContentHub>;

Expand All @@ -40,7 +38,6 @@ export const Error = {
throw 'Error loading content hub.';
}),
],
location: new URL('local:/content-hub?page=333'),
},
} satisfies StoryObj<typeof ContentHub>;

Expand Down
1 change: 1 addition & 0 deletions packages/ui/src/components/Organisms/ContentHub.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function ContentHub({ pageSize = 10 }: { pageSize: number }) {
offset: currentPage * pageSize - pageSize,
},
});
console.log(error);
return (
<div className="mx-auto max-w-6xl">
<SearchForm />
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/utils/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function useOperation<TOperation extends AnyOperationId>(
) {
return useSwr<OperationResult<TOperation>>(
[operation, variables],
variables ? createOperator(operation, variables) : null,
createOperator(operation, variables),
{
suspense: false,
},
Expand Down

0 comments on commit 0c6dff0

Please sign in to comment.