Skip to content

Commit

Permalink
feat: add GeneralView sample story
Browse files Browse the repository at this point in the history
  • Loading branch information
martapanc-resourcify committed Jul 27, 2023
1 parent b025bfe commit 259c8de
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 5 deletions.
34 changes: 34 additions & 0 deletions src/components/molecules/RandomFacts/GeneralView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use client';

import * as React from 'react';

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

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

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

export interface QuizAnswer {
headline: string;
key?: string;
}

export interface GeneralViewProps {
facts: RandomFact[];
}

const GeneralView = ({ facts }: GeneralViewProps) => {
const randomFact = shuffleArray(facts)[0];

return (
<div className='p4 rounded dark:bg-slate-900'>
<div className='mb-5'>{randomFact.description}</div>

<div className='flex justify-center'>
<Button>Load another random fact</Button>
</div>
</div>
);
};

export default GeneralView;
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Meta } from '@storybook/react';

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

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

const meta: Meta<typeof GeneralView> = {
title: 'Components/Random Facts/General View',
component: GeneralView,
tags: ['autodocs'],
};

export default meta;

const facts: RandomFact[] = [
{
_id: 'a',
name: 'name',
headline: '',
description:
'I have been officially excommunicated by the Roman Catholic Church ⛪',
trueFact: true,
explanation: '',
},
];

export const SampleStory = (args: GeneralViewProps) => (
<GeneralView {...args} />
);
SampleStory.args = {
facts,
};
11 changes: 6 additions & 5 deletions src/components/organisms/about-free-time/RandomFacts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as React from 'react';
import { useState } from 'react';

import Quiz, { QuizData } from '@/components/molecules/RandomFacts/Quiz';
import QuizAnswers from '@/components/molecules/RandomFacts/QuizAnswers';

const localStorageKey = 'alreadyPlayed';

Expand Down Expand Up @@ -47,11 +48,11 @@ const RandomFacts = ({ options, falseOption }: QuizData) => {
/>
)}
{submitted && alreadyPlayed && (
<div className='rounded bg-gray-200 p-4'>
<p className='text-gray-800'>
You're {answerCorrect ? `correct` : `wrong`}!
</p>
</div>
<QuizAnswers
answers={options}
falseOption={falseOption}
answeredCorrectly={answerCorrect}
/>
)}
{!submitted && alreadyPlayed && <div>Already played :)</div>}
</div>
Expand Down

0 comments on commit 259c8de

Please sign in to comment.