From 063c20e642848ec1dce9a90af0553adf9aba5187 Mon Sep 17 00:00:00 2001 From: siepra Date: Fri, 22 Sep 2023 13:45:31 +0200 Subject: [PATCH] Prettify chat loading view --- packages/mobile/.storybook/index.js | 2 + .../src/components/Chat/Chat.component.tsx | 115 +++++++++--------- .../CreateCommunity.component.tsx | 4 +- .../JoinCommunity/JoinCommunity.component.tsx | 5 +- .../Loading/Loading.component.test.tsx | 109 +++++++++++++++++ .../components/Loading/Loading.component.tsx | 50 ++++---- .../components/Loading/Loading.stories.tsx | 9 +- .../components/Splash/Splash.component.tsx | 45 +++++++ .../src/components/Splash/Splash.stories.tsx | 6 + .../src/screens/Splash/Splash.screen.tsx | 4 +- 10 files changed, 255 insertions(+), 94 deletions(-) create mode 100644 packages/mobile/src/components/Loading/Loading.component.test.tsx create mode 100644 packages/mobile/src/components/Splash/Splash.component.tsx create mode 100644 packages/mobile/src/components/Splash/Splash.stories.tsx diff --git a/packages/mobile/.storybook/index.js b/packages/mobile/.storybook/index.js index 8f98f01d65..7b079bea45 100644 --- a/packages/mobile/.storybook/index.js +++ b/packages/mobile/.storybook/index.js @@ -15,6 +15,7 @@ addDecorator(withNavigation) configure(() => { require('../src/components/JoinCommunity/JoinCommunity.stories') require('../src/components/LeaveCommunity/LeaveCommunity.stories') + require('../src/components/ConnectionProcess/ConnectionProcess.stories') require('../src/components/ContextMenu/ContextMenu.stories') require('../src/components/ConfirmationBox/ConfirmationBox.stories') require('../src/components/CreateCommunity/CreateCommunity.stories') @@ -34,6 +35,7 @@ configure(() => { require('../src/components/MessageSendButton/MessageSendButton.stories') require('../src/components/InitCheck/InitCheck.stories') require('../src/components/Loading/Loading.stories') + require('../src/components/Splash/Splash.stories') require('../src/components/Success/Success.stories') require('../src/components/Error/Error.stories') }, module) diff --git a/packages/mobile/src/components/Chat/Chat.component.tsx b/packages/mobile/src/components/Chat/Chat.component.tsx index ccabf7c5d4..22c90d4871 100644 --- a/packages/mobile/src/components/Chat/Chat.component.tsx +++ b/packages/mobile/src/components/Chat/Chat.component.tsx @@ -2,17 +2,17 @@ import React, { FC, useRef, useState, useEffect, useCallback } from 'react' import { Keyboard, View, FlatList, TextInput, KeyboardAvoidingView, Platform } from 'react-native' import { useSafeAreaInsets } from 'react-native-safe-area-context' import { Appbar } from '../../components/Appbar/Appbar.component' +import { Loading } from '../Loading/Loading.component' import { ImagePreviewModal } from '../../components/ImagePreview/ImagePreview.component' -import { Spinner } from '../Spinner/Spinner.component' import { Message } from '../Message/Message.component' import { Input } from '../Input/Input.component' import { MessageSendButton } from '../MessageSendButton/MessageSendButton.component' import { ChannelMessagesComponentProps, ChatProps } from './Chat.types' import { FileActionsProps } from '../UploadedFile/UploadedFile.types' -import { defaultTheme } from '../../styles/themes/default.theme' import { AttachmentButton } from '../AttachmentButton/AttachmentButton.component' import DocumentPicker, { DocumentPickerResponse, types } from 'react-native-document-picker' import UploadFilesPreviewsComponent from '../FileUploadingPreview/UploadingPreview.component' +import { defaultTheme } from '../../styles/themes/default.theme' export const Chat: FC = ({ contextMenu, @@ -145,73 +145,76 @@ export const Chat: FC = ({ }} > {messages.count === 0 ? ( - + ) : ( - item} - renderItem={item => { - return {renderItem(item)} - }} - onEndReached={() => { - loadMessagesAction(true) - }} - onEndReachedThreshold={0.7} - showsVerticalScrollIndicator={false} - /> - )} - - + <> + item} + renderItem={item => { + return {renderItem(item)} + }} + onEndReached={() => { + loadMessagesAction(true) + }} + onEndReachedThreshold={0.7} + showsVerticalScrollIndicator={false} + /> - - - {(didKeyboardShow || areFilesUploaded) && ( - + + + + + {(didKeyboardShow || areFilesUploaded) && ( + + )} + + + {uploadedFiles && ( + )} - - {uploadedFiles && } - - + + )} {imagePreview && setImagePreview && ( = ({ createCommunityAction, @@ -91,7 +91,7 @@ export const CreateCommunity: FC = ({ ) : ( - + )} ) diff --git a/packages/mobile/src/components/JoinCommunity/JoinCommunity.component.tsx b/packages/mobile/src/components/JoinCommunity/JoinCommunity.component.tsx index 9fcd084dbd..8aed5ac632 100644 --- a/packages/mobile/src/components/JoinCommunity/JoinCommunity.component.tsx +++ b/packages/mobile/src/components/JoinCommunity/JoinCommunity.component.tsx @@ -8,9 +8,8 @@ import { TextWithLink } from '../TextWithLink/TextWithLink.component' import { JoinCommunityProps } from './JoinCommunity.types' import { getInvitationCodes } from '@quiet/state-manager' -import { ONION_ADDRESS_REGEX } from '@quiet/common' -import { Loading } from '../Loading/Loading.component' +import { Splash } from '../Splash/Splash.component' export const JoinCommunity: FC = ({ joinCommunityAction, @@ -111,7 +110,7 @@ export const JoinCommunity: FC = ({ ) : ( - + )} ) diff --git a/packages/mobile/src/components/Loading/Loading.component.test.tsx b/packages/mobile/src/components/Loading/Loading.component.test.tsx new file mode 100644 index 0000000000..ddb936329b --- /dev/null +++ b/packages/mobile/src/components/Loading/Loading.component.test.tsx @@ -0,0 +1,109 @@ +import React from 'react' +import { renderComponent } from '../../utils/functions/renderComponent/renderComponent' + +import { Loading } from './Loading.component' + +describe('Loading component', () => { + it('should match inline snapshot', () => { + const { toJSON } = renderComponent( + + ) + + expect(toJSON()).toMatchInlineSnapshot(` + + + + + + + Creating community “Disco-fever” + + + + Additional info if needed can go here otherwise this is hidden. + + + + + `) + }) +}) diff --git a/packages/mobile/src/components/Loading/Loading.component.tsx b/packages/mobile/src/components/Loading/Loading.component.tsx index 0c2a6f957a..1088fc0a67 100644 --- a/packages/mobile/src/components/Loading/Loading.component.tsx +++ b/packages/mobile/src/components/Loading/Loading.component.tsx @@ -1,44 +1,36 @@ import React, { FC } from 'react' -import { Image, View } from 'react-native' -import deviceInfoModule from 'react-native-device-info' +import { View } from 'react-native' import { Typography } from '../Typography/Typography.component' -import { defaultTheme } from '../../styles/themes/default.theme' -import { appImages } from '../../assets' -export const Loading: FC = () => { +export interface LoadingProps { + title: string + caption?: string + progress?: number +} + +export const Loading: FC = ({ title, caption, progress = 220 }) => { return ( - - - - Starting backend - - - This can take some time - + + - - - {`v ${deviceInfoModule.getVersion()}`} + + + {title} + {caption && ( + + + {caption} + + + )} ) diff --git a/packages/mobile/src/components/Loading/Loading.stories.tsx b/packages/mobile/src/components/Loading/Loading.stories.tsx index d148245de0..f27ca84473 100644 --- a/packages/mobile/src/components/Loading/Loading.stories.tsx +++ b/packages/mobile/src/components/Loading/Loading.stories.tsx @@ -1,6 +1,11 @@ -import { storiesOf } from '@storybook/react-native' import React from 'react' +import { storiesOf } from '@storybook/react-native' import { Loading } from './Loading.component' -storiesOf('Loading', module).add('Default', () => ) +storiesOf('Loading', module).add('Default', () => ( + +)) diff --git a/packages/mobile/src/components/Splash/Splash.component.tsx b/packages/mobile/src/components/Splash/Splash.component.tsx new file mode 100644 index 0000000000..7b7b09ae84 --- /dev/null +++ b/packages/mobile/src/components/Splash/Splash.component.tsx @@ -0,0 +1,45 @@ +import React, { FC } from 'react' +import { Image, View } from 'react-native' +import deviceInfoModule from 'react-native-device-info' +import { Typography } from '../Typography/Typography.component' +import { defaultTheme } from '../../styles/themes/default.theme' +import { appImages } from '../../assets' + +export const Splash: FC = () => { + return ( + + + + + Starting backend + + + This can take some time + + + + + {`v ${deviceInfoModule.getVersion()}`} + + + + ) +} diff --git a/packages/mobile/src/components/Splash/Splash.stories.tsx b/packages/mobile/src/components/Splash/Splash.stories.tsx new file mode 100644 index 0000000000..eccea15446 --- /dev/null +++ b/packages/mobile/src/components/Splash/Splash.stories.tsx @@ -0,0 +1,6 @@ +import { storiesOf } from '@storybook/react-native' +import React from 'react' + +import { Splash } from './Splash.component' + +storiesOf('Splash', module).add('Default', () => ) diff --git a/packages/mobile/src/screens/Splash/Splash.screen.tsx b/packages/mobile/src/screens/Splash/Splash.screen.tsx index 94b97b11cf..4552e4def4 100644 --- a/packages/mobile/src/screens/Splash/Splash.screen.tsx +++ b/packages/mobile/src/screens/Splash/Splash.screen.tsx @@ -2,7 +2,7 @@ import React, { FC, useEffect } from 'react' import { useDispatch } from 'react-redux' import { initActions } from '../../store/init/init.slice' import { SplashScreenProps } from './Splash.types' -import { Loading } from '../../components/Loading/Loading.component' +import { Splash } from '../../components/Splash/Splash.component' export const SplashScreen: FC = ({ route }) => { const dispatch = useDispatch() @@ -16,5 +16,5 @@ export const SplashScreen: FC = ({ route }) => { dispatch(initActions.deepLink(code)) }, [route.params?.code]) - return + return }