2021-05-26 17:24:54 +00:00
|
|
|
/* eslint-disable import/no-extraneous-dependencies, import/no-unresolved, import/extensions, react/prop-types, react/destructuring-assignment */
|
|
|
|
import React from 'react';
|
|
|
|
import { ScrollView } from 'react-native';
|
|
|
|
import { storiesOf } from '@storybook/react-native';
|
|
|
|
|
|
|
|
import { longText } from '../../../../storybook/utils';
|
|
|
|
import { ThemeContext } from '../../../theme';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { Message, MessageDecorator, StoryProvider } from '../../../../storybook/stories/Message';
|
2022-07-04 18:10:14 +00:00
|
|
|
import { MessageTypeLoad, themes } from '../../../lib/constants';
|
2021-09-13 20:41:05 +00:00
|
|
|
import LoadMore from './index';
|
2021-05-26 17:24:54 +00:00
|
|
|
|
|
|
|
const stories = storiesOf('LoadMore', module);
|
|
|
|
|
|
|
|
// FIXME: for some reason, this promise never resolves on Storybook (it works on the app, so maybe the issue isn't on the component)
|
|
|
|
const load = () => new Promise(res => setTimeout(res, 1000));
|
|
|
|
|
|
|
|
stories.add('basic', () => (
|
|
|
|
<>
|
|
|
|
<LoadMore load={load} />
|
|
|
|
<LoadMore load={load} runOnRender />
|
2022-03-03 20:25:03 +00:00
|
|
|
<LoadMore load={load} type={MessageTypeLoad.PREVIOUS_CHUNK} />
|
|
|
|
<LoadMore load={load} type={MessageTypeLoad.NEXT_CHUNK} />
|
2021-05-26 17:24:54 +00:00
|
|
|
</>
|
|
|
|
));
|
|
|
|
|
|
|
|
const ThemeStory = ({ theme }) => (
|
2022-07-04 18:10:14 +00:00
|
|
|
<ThemeContext.Provider value={{ theme }}>
|
2021-05-26 17:24:54 +00:00
|
|
|
<ScrollView style={{ backgroundColor: themes[theme].backgroundColor }}>
|
2022-03-03 20:25:03 +00:00
|
|
|
<LoadMore load={load} type={MessageTypeLoad.PREVIOUS_CHUNK} />
|
2021-05-26 17:24:54 +00:00
|
|
|
<Message msg='Hey!' theme={theme} />
|
|
|
|
<Message msg={longText} theme={theme} isHeader={false} />
|
|
|
|
<Message msg='Older message' theme={theme} isHeader={false} />
|
2022-03-03 20:25:03 +00:00
|
|
|
<LoadMore load={load} type={MessageTypeLoad.NEXT_CHUNK} />
|
|
|
|
<LoadMore load={load} type={MessageTypeLoad.MORE} />
|
2021-05-26 17:24:54 +00:00
|
|
|
<Message msg={longText} theme={theme} />
|
|
|
|
<Message msg='This is the third message' isHeader={false} theme={theme} />
|
|
|
|
<Message msg='This is the second message' isHeader={false} theme={theme} />
|
|
|
|
<Message msg='This is the first message' theme={theme} />
|
|
|
|
</ScrollView>
|
|
|
|
</ThemeContext.Provider>
|
|
|
|
);
|
|
|
|
|
|
|
|
stories
|
|
|
|
.addDecorator(StoryProvider)
|
|
|
|
.addDecorator(MessageDecorator)
|
|
|
|
.add('light theme', () => <ThemeStory theme='light' />);
|
|
|
|
|
|
|
|
stories
|
|
|
|
.addDecorator(StoryProvider)
|
|
|
|
.addDecorator(MessageDecorator)
|
|
|
|
.add('dark theme', () => <ThemeStory theme='dark' />);
|
|
|
|
|
|
|
|
stories
|
|
|
|
.addDecorator(StoryProvider)
|
|
|
|
.addDecorator(MessageDecorator)
|
|
|
|
.add('black theme', () => <ThemeStory theme='black' />);
|