Skip to content

Commit

Permalink
fix: fix SB story
Browse files Browse the repository at this point in the history
  • Loading branch information
martapanc committed Aug 23, 2023
1 parent b07c634 commit 680f814
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/components/molecules/RandomFacts/GeneralView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ReactMarkdown from 'react-markdown';

import Button from '@/components/buttons/Button';

import { RandomFact } from '@/sanityTypes/RandomFact';
import { RandomFact } from '@/types/RandomFact';

export interface GeneralViewProps {
randomFacts: RandomFact[];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { Meta } from '@storybook/react';
import { DocumentNode } from 'graphql/language';
import { useEffect, useState } from 'react';

import { flattenToArray } from '@/lib/graphqlUtils';
import { shuffleArray } from '@/lib/helper';

import GeneralView, {
GeneralViewProps,
} from '@/components/molecules/RandomFacts/GeneralView';

import { trueRandomFactsQuery } from '@/queries/random-facts';
import { RandomFact } from '@/sanityTypes/RandomFact';
import { trueRandomFactsQueryQL } from '@/queries/random-facts';

import { sanityClient } from '../../../../../sanity/lib/client';
import apolloClient from '../../../../../apollo/apollo-client';

import { RandomFact } from '@/types/RandomFact';

const meta: Meta<typeof GeneralView> = {
title: 'Components/Random Facts/General View',
Expand All @@ -26,7 +29,7 @@ export const SampleStory = (args: GeneralViewProps) => {
useEffect(() => {
const fetchFacts = async () => {
try {
const randomFactsData = await sanityClient.fetch(trueRandomFactsQuery);
const randomFactsData = await queryRandomFacts(trueRandomFactsQueryQL);

setRandomFacts(shuffleArray(randomFactsData));
} catch (error) {
Expand All @@ -46,3 +49,9 @@ export const SampleStory = (args: GeneralViewProps) => {
</>
);
};

async function queryRandomFacts(query: DocumentNode) {
const { data } = await apolloClient.query({ query });

return flattenToArray<RandomFact>(data.randomFacts);
}

0 comments on commit 680f814

Please sign in to comment.