add storybooks, update snapshots and DiscussionsView

This commit is contained in:
Gerzon Z 2022-01-17 15:55:33 -04:00
parent eb1712e5fb
commit 89ae4304c4
7 changed files with 2549 additions and 48 deletions

File diff suppressed because it is too large Load Diff

View File

@ -53,7 +53,9 @@ export type ChatsStackParamList = {
rid: string; rid: string;
room: ISubscription; room: ISubscription;
}; };
DiscussionsView: undefined; DiscussionsView: {
rid: string;
};
SearchMessagesView: { SearchMessagesView: {
rid: string; rid: string;
t: SubscriptionType; t: SubscriptionType;

View File

@ -0,0 +1,97 @@
/* eslint-disable import/no-extraneous-dependencies, import/no-unresolved, import/extensions, react/prop-types */
import React from 'react';
import { storiesOf } from '@storybook/react-native';
import { ScrollView } from 'react-native';
import { combineReducers, createStore } from 'redux';
import { Provider } from 'react-redux';
import * as List from '../../containers/List';
import { themes } from '../../constants/colors';
import { ThemeContext } from '../../theme';
import { store } from '../../../storybook/stories';
import Item from './Item';
const author = {
_id: 'userid',
username: 'rocket.cat',
name: 'Rocket Cat'
};
const baseUrl = 'https://open.rocket.chat';
const date = new Date(2020, 10, 10, 10);
const longText =
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.';
const defaultItem = {
msg: 'Message content',
tcount: 1,
replies: [1],
ts: date,
tlm: date,
u: author,
attachments: []
};
const BaseItem = ({ item, ...props }) => (
<Item
baseUrl={baseUrl}
item={{
...defaultItem,
...item
}}
onPress={() => alert('pressed')}
{...props}
/>
);
const listDecorator = story => (
<ScrollView>
<List.Separator />
{story()}
<List.Separator />
</ScrollView>
);
const stories = storiesOf('Discussions.Item', module)
.addDecorator(listDecorator)
.addDecorator(story => <Provider store={store}>{story()}</Provider>);
stories.add('content', () => (
<>
<BaseItem />
<List.Separator />
<BaseItem
item={{
msg: longText
}}
/>
<List.Separator />
<BaseItem
item={{
dcount: 1000,
replies: [...new Array(1000)]
}}
/>
<List.Separator />
<BaseItem
item={{
msg: '',
attachments: [{ title: 'Attachment title' }]
}}
/>
<List.Separator />
<BaseItem useRealName />
</>
));
const ThemeStory = ({ theme }) => (
<ThemeContext.Provider value={{ theme }}>
<BaseItem badgeColor={themes[theme].mentionMeColor} />
</ThemeContext.Provider>
);
stories.add('themes', () => (
<>
<ThemeStory theme='light' />
<ThemeStory theme='dark' />
<ThemeStory theme='black' />
</>
));

View File

@ -1,6 +1,7 @@
import React from 'react'; import React from 'react';
import { StyleSheet, Text, View } from 'react-native'; import { StyleSheet, Text, View } from 'react-native';
import Touchable from 'react-native-platform-touchable'; import Touchable from 'react-native-platform-touchable';
import moment from 'moment';
import { useTheme } from '../../theme'; import { useTheme } from '../../theme';
import Avatar from '../../containers/Avatar'; import Avatar from '../../containers/Avatar';
@ -65,7 +66,8 @@ interface IItem {
const Item = ({ item, baseUrl, user, onPress }: IItem): JSX.Element => { const Item = ({ item, baseUrl, user, onPress }: IItem): JSX.Element => {
const { theme } = useTheme(); const { theme } = useTheme();
const username = item?.u?.username; const username = item?.u?.username;
const date = formatDateThreads(item.ts); const messageTime = moment(item.ts).format('LT');
const messageDate = formatDateThreads(item.ts);
return ( return (
<Touchable <Touchable
@ -79,7 +81,7 @@ const Item = ({ item, baseUrl, user, onPress }: IItem): JSX.Element => {
<Text style={[styles.title, { color: themes[theme!].titleText }]} numberOfLines={1}> <Text style={[styles.title, { color: themes[theme!].titleText }]} numberOfLines={1}>
{username} {username}
</Text> </Text>
<Text style={[styles.time, { color: themes[theme!].auxiliaryText }]}>{date}</Text> <Text style={[styles.time, { color: themes[theme!].auxiliaryText }]}>{messageTime}</Text>
</View> </View>
<View style={styles.messageContainer}> <View style={styles.messageContainer}>
{/* @ts-ignore */} {/* @ts-ignore */}
@ -93,7 +95,7 @@ const Item = ({ item, baseUrl, user, onPress }: IItem): JSX.Element => {
preview preview
/> />
</View> </View>
<DiscussionDetails item={item} user={user} time={date} style={styles.discussionDetails} /> <DiscussionDetails item={item} user={user} time={messageDate} style={styles.discussionDetails} />
</View> </View>
</View> </View>
</Touchable> </Touchable>

View File

@ -5,6 +5,8 @@ import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { HeaderBackButton, StackNavigationOptions, StackNavigationProp } from '@react-navigation/stack'; import { HeaderBackButton, StackNavigationOptions, StackNavigationProp } from '@react-navigation/stack';
import { RouteProp } from '@react-navigation/core'; import { RouteProp } from '@react-navigation/core';
import { SubscriptionType } from '../../definitions';
import { ChatsStackParamList } from '../../stacks/types';
import ActivityIndicator from '../../containers/ActivityIndicator'; import ActivityIndicator from '../../containers/ActivityIndicator';
import I18n from '../../i18n'; import I18n from '../../i18n';
import StatusBar from '../../containers/StatusBar'; import StatusBar from '../../containers/StatusBar';
@ -20,29 +22,16 @@ import { getHeaderTitlePosition } from '../../containers/Header';
import { useTheme } from '../../theme'; import { useTheme } from '../../theme';
import RocketChat from '../../lib/rocketchat'; import RocketChat from '../../lib/rocketchat';
import SearchHeader from '../../containers/SearchHeader'; import SearchHeader from '../../containers/SearchHeader';
import { TThreadModel } from '../../definitions/IThread';
import Item from './Item'; import Item from './Item';
import styles from './styles'; import styles from './styles';
const API_FETCH_COUNT = 50; const API_FETCH_COUNT = 50;
interface IItem {
rid: string;
drid: string;
prid: string;
id: string;
u: {
username: string;
};
dcount: string | number;
replies?: any;
msg: string;
ts: string;
}
interface IDiscussionsViewProps { interface IDiscussionsViewProps {
navigation: StackNavigationProp<any, 'DiscussionsView'>; navigation: StackNavigationProp<ChatsStackParamList, 'DiscussionsView'>;
route: RouteProp<any, 'DiscussionsView'>; route: RouteProp<ChatsStackParamList, 'DiscussionsView'>;
item: IItem; item: TThreadModel;
} }
interface IDiscussionsViewState { interface IDiscussionsViewState {
@ -187,19 +176,19 @@ const DiscussionsView = ({ navigation, route }: IDiscussionsViewProps): JSX.Elem
}, [navigation, isSearching]); }, [navigation, isSearching]);
const onDiscussionPress = debounce( const onDiscussionPress = debounce(
(item: IItem) => { (item: TThreadModel) => {
navigation.push('RoomView', { navigation.push('RoomView', {
rid: item.drid, rid: item.drid!,
prid: item.rid, prid: item.rid,
name: item.msg, name: item.msg,
t: item.rid === 'GENERAL' ? 'c' : 'p' t: item.rid! === 'GENERAL' ? SubscriptionType.CHANNEL : SubscriptionType.GROUP
}); });
}, },
1000, 1000,
true true
); );
const renderItem = ({ item }: { item: IItem }) => ( const renderItem = ({ item }: { item: TThreadModel }) => (
<Item <Item
{...{ {...{
item, item,

View File

@ -8,6 +8,7 @@ import { Provider } from 'react-redux';
import * as List from '../../containers/List'; import * as List from '../../containers/List';
import { themes } from '../../constants/colors'; import { themes } from '../../constants/colors';
import { ThemeContext } from '../../theme'; import { ThemeContext } from '../../theme';
import { store } from '../../../storybook/stories';
import Item from './Item'; import Item from './Item';
const author = { const author = {
@ -38,7 +39,6 @@ const BaseItem = ({ item, ...props }) => (
}} }}
onPress={() => alert('pressed')} onPress={() => alert('pressed')}
{...props} {...props}
thread
/> />
); );
@ -50,28 +50,6 @@ const listDecorator = story => (
</ScrollView> </ScrollView>
); );
const reducers = combineReducers({
login: () => ({
user: {
id: 'abc',
username: 'rocket.cat',
name: 'Rocket Cat'
}
}),
server: () => ({
server: 'https://open.rocket.chat',
version: '3.7.0'
}),
share: () => ({
server: 'https://open.rocket.chat',
version: '3.7.0'
}),
settings: () => ({
blockUnauthenticatedAccess: false
})
});
const store = createStore(reducers);
const stories = storiesOf('Thread Messages.Item', module) const stories = storiesOf('Thread Messages.Item', module)
.addDecorator(listDecorator) .addDecorator(listDecorator)
.addDecorator(story => <Provider store={store}>{story()}</Provider>); .addDecorator(story => <Provider store={store}>{story()}</Provider>);

View File

@ -11,6 +11,7 @@ import './Markdown';
import './HeaderButtons'; import './HeaderButtons';
import './UnreadBadge'; import './UnreadBadge';
import '../../app/views/ThreadMessagesView/Item.stories.js'; import '../../app/views/ThreadMessagesView/Item.stories.js';
import '../../app/views/DiscussionsView/Item.stories.js';
import './Avatar'; import './Avatar';
import './NewMarkdown'; import './NewMarkdown';
import '../../app/containers/BackgroundContainer/index.stories.js'; import '../../app/containers/BackgroundContainer/index.stories.js';