-
Notifications
You must be signed in to change notification settings - Fork 2
feature/BA-26-26-Single chat components #296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gabrieleandro
wants to merge
13
commits into
feature/BA-2626-rooms-list
Choose a base branch
from
feature/BA-2626-single-chat-creation
base: feature/BA-2626-rooms-list
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b009cd8
Single chat components
gabrieleandro 82e839b
Merge remote-tracking branch 'origin/feature/BA-2626-rooms-list' into…
gabrieleandro 13e7f48
Merge branch 'feature/BA-2626-rooms-list' into feature/BA-2626-single…
gabrieleandro bc23f27
Merge branch 'feature/BA-2626-rooms-list' into feature/BA-2626-single…
gabrieleandro 939807a
fix-comment
gabrieleandro 216a975
Merge branch 'feature/BA-2626-rooms-list' into feature/BA-2626-single…
gabrieleandro 97106e4
Merge branch 'feature/BA-2626-rooms-list' into feature/BA-2626-single…
gabrieleandro 3e141f0
change flatList to infiniteScrollView
gabrieleandro f20832f
Merge branch 'feature/BA-2626-rooms-list' into feature/BA-2626-single…
gabrieleandro ee38f80
fix-comments
gabrieleandro fc434b5
Merge branch 'feature/BA-2626-rooms-list' into feature/BA-2626-single…
gabrieleandro 53af6c7
Merge branch 'feature/BA-2626-rooms-list' into feature/BA-2626-single…
gabrieleandro 7cecd52
Merge branch 'feature/BA-2626-rooms-list' into feature/BA-2626-single…
gabrieleandro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
...ents/modules/messages/native/SingleChatCreate/CreateRoomList/CreateRoomListItem/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import { useCurrentProfile } from '@baseapp-frontend/authentication' | ||
| import { AvatarWithPlaceholder } from '@baseapp-frontend/design-system/components/native/avatars' | ||
| import { Text } from '@baseapp-frontend/design-system/components/native/typographies' | ||
| import { View } from '@baseapp-frontend/design-system/components/native/views' | ||
| import { useTheme } from '@baseapp-frontend/design-system/providers/native' | ||
|
|
||
| import { router } from 'expo-router' | ||
| import { Pressable } from 'react-native' | ||
| import { ConnectionHandler, useFragment } from 'react-relay' | ||
|
|
||
| import { ProfileItemFragment$key } from '../../../../../../__generated__/ProfileItemFragment.graphql' | ||
| import { ProfileItemFragment } from '../../../../../profiles/common' | ||
| import { useCreateChatRoomMutation } from '../../../../common' | ||
| import { createStyles } from './styles' | ||
|
|
||
| const ChatRoomListItem = ({ profile: profileRef }: { profile: ProfileItemFragment$key }) => { | ||
| const theme = useTheme() | ||
| const styles = createStyles(theme) | ||
|
|
||
| const node = useFragment(ProfileItemFragment, profileRef) | ||
| const [commit] = useCreateChatRoomMutation() | ||
|
|
||
| const { currentProfile } = useCurrentProfile() | ||
|
|
||
| const handleRoomCompleted = (roomRef: string) => { | ||
| router.push(`/rooms/${roomRef}`) | ||
| } | ||
|
|
||
| const handleRoomCreation = () => { | ||
| if (currentProfile?.id) { | ||
| commit({ | ||
| variables: { | ||
| input: { profileId: currentProfile.id, participants: [node?.id] }, | ||
| connections: [ | ||
| ConnectionHandler.getConnectionID(currentProfile.id, 'roomsList_chatRooms', { | ||
| unreadMessages: false, | ||
| archived: false, | ||
| q: '', | ||
| }), | ||
| ], | ||
| }, | ||
| onCompleted: (response) => { | ||
| const roomId = response?.chatRoomCreate?.room?.node?.id | ||
| if (roomId) { | ||
| handleRoomCompleted(roomId) | ||
| } | ||
| }, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| return ( | ||
| <Pressable key={`chat-room-item-${node?.id}`} onPress={handleRoomCreation}> | ||
| <View style={styles.cardContainer}> | ||
| <View> | ||
| <AvatarWithPlaceholder imgSource={node?.image?.url} /> | ||
| </View> | ||
| <View> | ||
| <Text variant="subtitle2">{node?.name}</Text> | ||
| <Text variant="caption"> | ||
| {node?.urlPath?.path && `@${node?.urlPath.path?.replace('/', '')}`} | ||
| </Text> | ||
| </View> | ||
| </View> | ||
| </Pressable> | ||
| ) | ||
| } | ||
|
|
||
| export default ChatRoomListItem | ||
15 changes: 15 additions & 0 deletions
15
...ents/modules/messages/native/SingleChatCreate/CreateRoomList/CreateRoomListItem/styles.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { Theme } from '@baseapp-frontend/design-system/styles/native' | ||
|
|
||
| import { StyleSheet } from 'react-native' | ||
|
|
||
| export const createStyles = (theme: Theme) => | ||
| StyleSheet.create({ | ||
| cardContainer: { | ||
| flexDirection: 'row', | ||
| alignItems: 'center', | ||
| gap: 12, | ||
| paddingVertical: 12, | ||
| flex: 1, | ||
| backgroundColor: theme.colors.surface.background, | ||
| }, | ||
| }) |
76 changes: 76 additions & 0 deletions
76
packages/components/modules/messages/native/SingleChatCreate/CreateRoomList/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import React, { Suspense, useEffect, useRef, useTransition } from 'react' | ||
|
|
||
| import { View } from '@baseapp-frontend/design-system/components/native/views' | ||
| import { useTheme } from '@baseapp-frontend/design-system/providers/native' | ||
|
|
||
| import { Dimensions } from 'react-native' | ||
| import { FlatList } from 'react-native-gesture-handler' | ||
|
|
||
| import { useAllProfilesList } from '../../../../profiles/common' | ||
| import { withChatRoomProvider } from '../../../common' | ||
| import SearchNotFoundState from '../../SearchNotFoundState' | ||
| import ChatRoomListItem from './CreateRoomListItem' | ||
| import { createStyles } from './styles' | ||
| import { CreateRoomListProps } from './types' | ||
|
|
||
| const CreateRoomList = ({ targetRef, searchParam }: CreateRoomListProps) => { | ||
| const theme = useTheme() | ||
| const styles = createStyles(theme) | ||
|
|
||
| const [isPending, startTransition] = useTransition() | ||
| const { data, refetch, loadNext, hasNext } = useAllProfilesList(targetRef) | ||
|
|
||
| const profiles = data?.allProfiles?.edges ?? [] | ||
| const layoutTriggeredRef = useRef(false) | ||
| const screenHeight = Dimensions.get('window').height | ||
|
|
||
| const loadNextBasedOnHeight = (height: number) => { | ||
| if (!layoutTriggeredRef.current && hasNext && height < screenHeight) { | ||
| layoutTriggeredRef.current = true | ||
| loadNext(10) | ||
| } | ||
| } | ||
|
|
||
| const handleEmptySearch = () => { | ||
| if (searchParam && !isPending && !profiles.length) { | ||
| return <SearchNotFoundState /> | ||
| } | ||
| return null | ||
| } | ||
|
|
||
| useEffect(() => { | ||
| layoutTriggeredRef.current = false | ||
| startTransition(() => { | ||
| refetch({ q: searchParam }) | ||
| }) | ||
| }, [refetch, searchParam]) | ||
|
|
||
| return ( | ||
| <View style={styles.flatListWrapper}> | ||
| <FlatList | ||
gabrieleandro marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| data={profiles} | ||
| keyExtractor={(item, i) => (item && item.node?.id) || i.toString()} | ||
| renderItem={({ item }) => (item?.node ? <ChatRoomListItem profile={item.node} /> : null)} | ||
| onEndReached={() => { | ||
| if (hasNext) loadNext(10) | ||
| }} | ||
| onEndReachedThreshold={0.8} | ||
| onContentSizeChange={(width, height) => loadNextBasedOnHeight(height)} | ||
| contentContainerStyle={styles.contentContainer} | ||
| style={styles.flatList} | ||
| keyboardShouldPersistTaps="handled" | ||
| ListEmptyComponent={handleEmptySearch} | ||
| /> | ||
| </View> | ||
| ) | ||
| } | ||
|
|
||
| const CreateRoomListWithProvider = withChatRoomProvider(CreateRoomList) | ||
|
|
||
| const SuspendedCreateRoomList = (props: CreateRoomListProps) => ( | ||
| <Suspense> | ||
| <CreateRoomListWithProvider {...props} /> | ||
| </Suspense> | ||
| ) | ||
|
|
||
| export default SuspendedCreateRoomList | ||
19 changes: 19 additions & 0 deletions
19
packages/components/modules/messages/native/SingleChatCreate/CreateRoomList/styles.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { Theme } from '@baseapp-frontend/design-system/styles/native' | ||
|
|
||
| import { StyleSheet } from 'react-native' | ||
|
|
||
| export const createStyles = (theme: Theme) => | ||
| StyleSheet.create({ | ||
| flatListWrapper: { | ||
| flex: 1, | ||
| }, | ||
| contentContainer: { | ||
| paddingBottom: 16, | ||
| width: '100%', | ||
| }, | ||
| flatList: { | ||
| flex: 1, | ||
| width: '100%', | ||
| backgroundColor: theme.colors.surface.background, | ||
| }, | ||
| }) |
6 changes: 6 additions & 0 deletions
6
packages/components/modules/messages/native/SingleChatCreate/CreateRoomList/types.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| // import { CreateRoomPageQuery$data } from '__generated__/CreateRoomPageQuery.graphql' | ||
|
|
||
| export interface CreateRoomListProps { | ||
| targetRef: any // CreateRoomPageQuery$data | ||
| searchParam: string | ||
| } |
Empty file.
13 changes: 13 additions & 0 deletions
13
packages/components/modules/messages/native/SingleChatCreate/styles.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { Theme } from '@baseapp-frontend/design-system/styles/native' | ||
|
|
||
| import { StyleSheet } from 'react-native' | ||
|
|
||
| export const createStyles = (theme: Theme) => | ||
| StyleSheet.create({ | ||
| container: { | ||
| backgroundColor: theme.colors.surface.background, | ||
| flex: 1, | ||
| flexGrow: 1, | ||
| paddingHorizontal: 12, | ||
| }, | ||
| }) |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.