Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Chat list, chat API, functionalities to chat page and bug fixes #99

Merged
merged 31 commits into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
33d752f
Refactored text themes into textDark
AndreLaranjeira Apr 25, 2021
ef850c6
Changed adoption API to add owner reference to interests collection
AndreLaranjeira Apr 26, 2021
b80d311
ConcatenateNames extraction and minor refactoring to theme
AndreLaranjeira Apr 27, 2021
f2909c1
Chat list page (with mocks and without testing backend)
AndreLaranjeira Apr 27, 2021
2ac3539
🚧 Add first methods to chatAPI
Hugo-NF May 3, 2021
597f1df
🚧 Add loadMessages and latestMessageOnChat
Hugo-NF May 3, 2021
33097b3
🚧 Add loadMessages and latestMessageOnChat
Hugo-NF May 3, 2021
2ec79bb
Merge branch '091_chat_api' of github.com:Hugo-NF/meau-app into 091_c…
Hugo-NF May 3, 2021
87a5a92
🚧 Add orderBy on getOwnChats method
Hugo-NF May 3, 2021
b38644a
Merge branch '091_chat_api' of github.com:Hugo-NF/meau-app into 093_c…
Hugo-NF May 4, 2021
a358350
🚧 Add chatUID to chat screen params
Hugo-NF May 5, 2021
c162f25
🚧 Replaces mocks on chatList screen
Hugo-NF May 5, 2021
263655c
🚧 Loads first page of messages
Hugo-NF May 5, 2021
5ba6975
🚧 Chat page has a bug on timestamp
Hugo-NF May 5, 2021
7afb80b
Chat working with ChatAPI
labm1997 May 5, 2021
1ba7110
Linter fix
labm1997 May 5, 2021
1bcb996
Function to format chat date into text
AndreLaranjeira May 5, 2021
a5208e5
Fix Chat page corner case when there's no chat yet
labm1997 May 6, 2021
9fb16be
Merge branch '093_chat_list' of https://github.com/Hugo-NF/meau-app i…
labm1997 May 6, 2021
b82ccf9
InfiniteScroll now reloads data whenever the screen is focused
AndreLaranjeira May 6, 2021
833159c
Chats and chat list now register when the user sees a message in chat
AndreLaranjeira May 6, 2021
a51e623
Fixed bug that caused infiniteScroll focus effect to crash app on logout
AndreLaranjeira May 6, 2021
c22ee31
Minor refactoring in type files
AndreLaranjeira May 6, 2021
2e49b3e
Minor refactoring in chatList page and styles
AndreLaranjeira May 6, 2021
88a287e
InfiniteScroll - Added mount checks to prevent memory leaks
AndreLaranjeira May 6, 2021
1a736df
Naming fixes
labm1997 May 6, 2021
c1c699b
More naming fixes
labm1997 May 6, 2021
6154524
Removed not needed comments
labm1997 May 6, 2021
b53aafa
Updated package-lock
AndreLaranjeira May 6, 2021
30f087c
Merge branch '093_chat_list' of https://github.com/Hugo-NF/meau-app i…
labm1997 May 6, 2021
3896ac1
Refactor getChatByTarget
labm1997 May 6, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8,574 changes: 5,520 additions & 3,054 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/components/AnimalCard/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const CardTitle = styled.Text<TextProps>`
text-align-vertical: center;
font-family: Roboto_500Medium;
font-size: 16px;
color: ${Theme.elements.headerText};
color: ${Theme.elements.textDark};
`;

export const CardOptions = styled.View<ViewProps>`
Expand Down
3 changes: 2 additions & 1 deletion src/components/DrawerContent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ const DrawerContent = ({ parentDrawerOpen, setParentDrawerOpen } : IDrawerProps)
/>
<List.Item
title="Chat"
titleStyle={styles.ListItemTextDisabled}
onPress={() => navigateTo('ChatList')}
titleStyle={styles.ListItemText}
/>
</List.Accordion>
</List.Section>
Expand Down
6 changes: 3 additions & 3 deletions src/components/DrawerContent/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const styledComponents = {
font-family: 'Roboto_400Medium';
font-size: 14px;
text-transform: uppercase;
color: ${Theme.elements.buttonText};
color: ${Theme.elements.textDark};
`,
};

Expand All @@ -62,12 +62,12 @@ export const styles = {
SectionTitle: {
fontFamily: 'Roboto_400Medium',
fontSize: 14,
color: Theme.elements.buttonText,
color: Theme.elements.textDark,
},
ListItemText: {
fontFamily: 'Roboto_400Regular',
fontSize: 14,
color: Theme.elements.buttonText,
color: Theme.elements.textDark,
},
ListItemTextDisabled: {
fontFamily: 'Roboto_400Regular',
Expand Down
113 changes: 62 additions & 51 deletions src/components/InfiniteScroll/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Component to implement an infinite scroll for any type of content.

// Package imports.
import React, { useCallback, useEffect, useState } from 'react';
import React, { useCallback, useState } from 'react';
import useIsMounted from 'ismounted';
import { ActivityIndicator, FlatList } from 'react-native';
import { useFocusEffect } from '@react-navigation/native';

// Style imports.
import { defaultProps, styledComponents } from './styles';
Expand All @@ -26,6 +28,7 @@ interface IInfiniteScroll<T> {
formatContent: (queryResponseData : T) => JSX.Element,
keyExtractorFunction: (item: T) => string,
loadingContainerStyles?: Record<string, unknown>,
noDataFoundContainerStyles?: Record<string, unknown>,
numColumns: number,
}

Expand All @@ -47,9 +50,11 @@ const InfiniteScroll = <T, _>({
formatContent,
keyExtractorFunction,
loadingContainerStyles,
noDataFoundContainerStyles,
numColumns,
}: IInfiniteScroll<T>): JSX.Element => {
// Variable declaration.
const isMounted = useIsMounted();
const [infiniteScrollState, setInfiniteScrollState] = useState<InfiniteScrollState<T>>({
allDataFetched: false,
data: [],
Expand All @@ -64,48 +69,50 @@ const InfiniteScroll = <T, _>({
.then((response) => {
const contentReceived = response;

if (contentReceived.length === 0) {
if (isMounted.current) {
if (contentReceived.length === 0) {
setInfiniteScrollState({
allDataFetched: true,
data: [],
error: null,
loadingMore: false,
page: 1,
});
} else {
setInfiniteScrollState({
allDataFetched: false,
data: contentReceived,
error: null,
loadingMore: false,
page: 2,
});
}
}
})
.catch((err) => {
if (isMounted.current) {
setInfiniteScrollState({
allDataFetched: true,
data: [],
error: null,
error: err,
loadingMore: false,
page: 1,
});
} else {
setInfiniteScrollState({
allDataFetched: false,
data: contentReceived,
error: null,
loadingMore: false,
page: 2,
});
}
})
.catch((err) => {
setInfiniteScrollState({
allDataFetched: true,
data: [],
error: err,
loadingMore: false,
page: 1,
});
});
}, [contentBatchSize, dataFetchQuery]);
}, [contentBatchSize, dataFetchQuery, isMounted]);

// Function declarations.
function componentDidMount() : () => void {
let mounted = true;

if (mounted) fetchInitialData();

return function cleanUp() : void {
mounted = false;
};
}
const onComponentFocus = useCallback(() : void => {
fetchInitialData();
}, [fetchInitialData]);

function fetchMoreData() : void {
if (!infiniteScrollState.loadingMore && !infiniteScrollState.allDataFetched) {
if (
!infiniteScrollState.loadingMore
&& !infiniteScrollState.allDataFetched
&& isMounted.current
) {
setInfiniteScrollState({
...infiniteScrollState,
loadingMore: true,
Expand All @@ -118,30 +125,34 @@ const InfiniteScroll = <T, _>({
.then((response) => {
const contentReceived = response;

if (contentReceived.length === 0) {
if (isMounted.current) {
if (contentReceived.length === 0) {
setInfiniteScrollState({
...infiniteScrollState,
allDataFetched: true,
loadingMore: false,
error: null,
});
} else {
setInfiniteScrollState({
...infiniteScrollState,
data: infiniteScrollState.data.concat(contentReceived),
error: null,
loadingMore: false,
page: infiniteScrollState.page + 1,
});
}
}
})
.catch((err) => {
if (isMounted.current) {
setInfiniteScrollState({
...infiniteScrollState,
allDataFetched: true,
error: err,
loadingMore: false,
error: null,
});
} else {
setInfiniteScrollState({
...infiniteScrollState,
data: infiniteScrollState.data.concat(contentReceived),
error: null,
loadingMore: false,
page: infiniteScrollState.page + 1,
});
}
})
.catch((err) => {
setInfiniteScrollState({
...infiniteScrollState,
allDataFetched: true,
error: err,
loadingMore: false,
});
});
}
}
Expand All @@ -163,7 +174,7 @@ const InfiniteScroll = <T, _>({
function renderLoading() : JSX.Element {
if (infiniteScrollState.allDataFetched) {
return (
<TextContainer>
<TextContainer style={{ ...noDataFoundContainerStyles }}>
<NoDataFoundMessage>Não há dados para exibir!</NoDataFoundMessage>
</TextContainer>
);
Expand All @@ -183,7 +194,7 @@ const InfiniteScroll = <T, _>({
}

// Component effects.
useEffect(componentDidMount, [fetchInitialData]);
useFocusEffect(onComponentFocus);

// JSX returned.
return (
Expand Down
4 changes: 4 additions & 0 deletions src/components/InfiniteScroll/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export const defaultProps = {

},

noDataFoundContainerStyles: {

},

numColumns: 1,
};

Expand Down
11 changes: 5 additions & 6 deletions src/constants/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ const Theme = {
},
elements: {
text: '#757575',
buttonText: '#434343',
textDark: '#434343',
textFaded: '#BDBDBD',
buttonTextDisabled: '#999',
invalidText: '#BDBDBD',
placeholderText: '#BDBDBD',
fieldText: '#575756',
labelPrimary: '#589B9B',
labelSecondary: '#F7A800',
Expand All @@ -27,7 +26,6 @@ const Theme = {
headerPrimaryDark: '#88C9BF',
headerSecondary: '#FEE29B',
headerSecondaryDark: '#FFD358',
headerText: '#434343',
headerLeftIcon: '#434343',
muted: '#ADB5BD',
active: '#FFD358',
Expand All @@ -43,12 +41,13 @@ const Theme = {
animalPhotosInputBackground: '#F1F2F2',
icon: '#757575',
iconBackground: '#E6E7E7',
cardText: '#434343',
titleText: '#434343',
sectionBreak: '#E0E0E0',
adoptionButton: '#FDCF58',
floatingButton: '#FAFAFA',
notificationCounter: '#D55',
chatListEntrySeparator: '#E6E7E8',
chatListEntryTitle: '#589B9B',
chatListEntryTitleFaded: '#88C9BF',
chatTextInput: '#FFFFFF',
chatBackground: '#F1F2F2',
chatSendIcon: '#FFFFFF',
Expand Down
2 changes: 1 addition & 1 deletion src/layouts/HeaderLayout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ HeaderLayout.defaultProps = {
titleStyles: {
fontFamily: 'Roboto_500Medium',
fontSize: '20px',
color: Theme.elements.headerText,
color: Theme.elements.textDark,
},
drawerRoutes: [],
drawerUser: true,
Expand Down
8 changes: 2 additions & 6 deletions src/pages/Animal/Details/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import * as CarouselTypes from '../../../types/carousel';
import * as RouteTypes from '../../../types/routes';

// Utils imports.
import { concatenateNames } from '../../../utils/concatenateNames';
import { formatLocation } from '../../../utils/formatTexts';

// Component export.
Expand Down Expand Up @@ -100,10 +101,6 @@ export default function AnimalDetails() : JSX.Element {
return 'Não';
}

function concatenateNames(names : Array<string>) : string {
return names.length === 2 ? names.join(' e ') : names.join(', ');
}

function determinePageBehavior() : void {
function describeAnimalAdoptionRequirements(
adoptionRequirements : AnimalTypes.AdoptionRequirements,
Expand Down Expand Up @@ -316,8 +313,7 @@ export default function AnimalDetails() : JSX.Element {
callback={() => navigation.navigate('Chat', {
/* eslint-disable camelcase */
title: owner.data()?.full_name,
targetUserUID: animalData.owner.id,
animalUID: animal.id,
targetUserUID: ownerID,
})}
>
<ButtonTextStrong>Chat</ButtonTextStrong>
Expand Down
6 changes: 3 additions & 3 deletions src/pages/Animal/Details/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const styledComponents = {
`,

ButtonTextStrong: styled.Text<TextProps>`
color: ${Theme.elements.buttonText};
color: ${Theme.elements.textDark};
font-family: 'Roboto_500Medium';
font-size: 12px;
text-transform: uppercase;
Expand Down Expand Up @@ -130,7 +130,7 @@ export const styledComponents = {
`,

TitleText: styled.Text<TextProps>`
color: ${Theme.elements.titleText}
color: ${Theme.elements.textDark}
font-family: 'Roboto_500Medium';
font-size: 16px;
margin-top: 16px;
Expand All @@ -150,7 +150,7 @@ export const styles = {
},

floatingButtonIcon: {
color: Theme.elements.buttonText,
color: Theme.elements.textDark,
},

headerLayoutHeaderPrimaryStyles: {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Animal/Feed/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const FeedPets = (): JSX.Element => {
<MaterialCommunityIcons
name="heart-outline"
size={24}
color={Theme.elements.headerText}
color={Theme.elements.textDark}
/>
)}
headerBackground={Theme.elements.headerSecondary}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Animal/Feed/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import styled from 'styled-components/native';
import { Theme } from '../../../constants';

export const CardText = styled.Text<TextProps>`
color: ${Theme.elements.cardText};
color: ${Theme.elements.textDark};
font-family: 'Roboto_400Regular';
font-size: 12px;
text-transform: uppercase;
Expand Down
Loading