Skip to content
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

[#157929923] add-badge-messages #979

Merged
merged 20 commits into from
May 20, 2019
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
4fa82d7
[#157929923] add-badge-messages
matgentili Apr 24, 2019
2c986b9
[#157929923]-add-badge-messages
matgentili Apr 24, 2019
1f775c1
[#157929923]-add-badge-messages
matgentili Apr 24, 2019
4f7653e
[#157929923] add-badge-messages
matgentili Apr 29, 2019
cc4db3a
[#157929923]-add-badge-message-tab
matgentili May 3, 2019
740cf3d
[#157929923]-add-badge-message-tab
matgentili May 13, 2019
3c3eee9
Merge branch 'master' into #157929923]-add-badge-message-tab
matgentili May 13, 2019
c6076fa
[#157929923]-add-badge-message-tab
matgentili May 13, 2019
d6c5379
Merge branch '#157929923]-add-badge-message-tab' of https://github.co…
matgentili May 13, 2019
c1c8ff7
[#157929923] add badge message tab
matgentili May 15, 2019
1e29f4f
[#157929923] add badge message tab
matgentili May 15, 2019
b5163eb
Merge branch 'master' into #157929923]-add-badge-message-tab
matgentili May 16, 2019
1715e8d
[#157929923] Add badge messages
matgentili May 20, 2019
99c794d
Merge branch 'master' into #157929923]-add-badge-message-tab
matgentili May 20, 2019
571cefb
[#157929923] Add badge messages tab
matgentili May 20, 2019
0e75fd4
Merge branch 'master' into #157929923]-add-badge-message-tab
matgentili May 20, 2019
31e64be
[#157929923] Add badge messages tab
matgentili May 20, 2019
cb0706a
Merge branch '#157929923]-add-badge-message-tab' of https://github.co…
matgentili May 20, 2019
c6c1a47
Merge branch 'master' into #157929923]-add-badge-message-tab
matgentili May 20, 2019
15f204f
Merge branch 'master' into #157929923]-add-badge-message-tab
francescopersico May 20, 2019
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
75 changes: 75 additions & 0 deletions ts/components/MessagesTabIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { Badge, View } from "native-base";
import React from "react";
import { Platform, StyleSheet, Text } from "react-native";
import { connect } from "react-redux";
import { messagesUnreadSelector } from "../store/reducers/entities/messages";
import { GlobalState } from "../store/reducers/types";
import variables from "../theme/variables";
import IconFont from "./ui/IconFont";

type OwnProps = {
color?: string;
};
const MAX_BADGE_VALUE = 99;
const styles = StyleSheet.create({
textBadgeStyle: {
fontSize: 10,
fontFamily: "Titillium Web",
fontWeight: "bold",
color: "white",
flex: 1,
position: "absolute",
height: 19,
width: 19,
textAlign: "center",
paddingRight: 3,
top: Platform.OS === "ios" ? 0 : undefined
},
badgeStyle: {
backgroundColor: variables.brandPrimary,
borderColor: "white",
borderWidth: 2,
position: "absolute",
elevation: 0.1,
shadowColor: "white",
height: 19,
width: 19,
left: 12,
bottom: 10
}
});

type Props = OwnProps & ReturnType<typeof mapStateToProps>;

/**
* Message icon add badge.
*/
class MessagesTabIcon extends React.PureComponent<Props> {
public render() {
const { color, badgeValue } = this.props;
return (
<View>
<IconFont
name={"io-messaggi"}
size={variables.iconSize3}
color={color}
/>
{badgeValue > 0 ? (
<Badge style={styles.badgeStyle}>
<Text style={[styles.textBadgeStyle]}>{badgeValue}</Text>
</Badge>
) : null}
</View>
);
}
}

function mapStateToProps(state: GlobalState) {
const messagesUnread = messagesUnreadSelector(state);
return {
badgeValue:
messagesUnread < MAX_BADGE_VALUE ? messagesUnread : MAX_BADGE_VALUE
};
}

export default connect(mapStateToProps)(MessagesTabIcon);
3 changes: 0 additions & 3 deletions ts/components/messages/MessageListComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
StyleSheet,
View
} from "react-native";

import { NavigationEvents } from "react-navigation";
import { MessageState } from "../../store/reducers/entities/messages/messagesById";
import { PaymentByRptIdState } from "../../store/reducers/entities/payments";
Expand Down Expand Up @@ -42,7 +41,6 @@ const keyExtractor = (_: MessageState) => _.meta.id;
class MessageListComponent extends React.Component<Props> {
private renderItem = (info: ListRenderItemInfo<MessageState>) => {
const { meta } = info.item;

const service = this.props.servicesById[meta.sender_service_id];

return (
Expand Down Expand Up @@ -76,7 +74,6 @@ class MessageListComponent extends React.Component<Props> {
paymentByRptId,
ListEmptyComponent
} = this.props;

const refreshControl = (
<RefreshControl refreshing={refreshing} onRefresh={onRefresh} />
);
Expand Down
27 changes: 16 additions & 11 deletions ts/navigation/MainNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
NavigationState,
StackActions
} from "react-navigation";

import MessagesTabIcon from "../components/MessagesTabIcon";
import ProfileTabIcon from "../components/ProfileTabIcon";
import IconFont from "../components/ui/IconFont";
import I18n from "../i18n";
Expand All @@ -25,7 +25,6 @@ import PreferencesNavigator from "./PreferencesNavigator";
import ProfileNavigator from "./ProfileNavigator";
import ROUTES from "./routes";
import WalletNavigator from "./WalletNavigator";

type Routes = keyof typeof ROUTES;

type RouteLabelMap = { [key in Routes]?: string };
Expand Down Expand Up @@ -113,7 +112,6 @@ const getTabBarVisibility = (
if (NoTabBarRoutes.indexOf(routeName) !== -1) {
return false;
}

return true;
};

Expand Down Expand Up @@ -166,22 +164,29 @@ const navigation = createBottomTabNavigator(
tabBarIcon: (options: { tintColor: string | null; focused: boolean }) => {
const { routeName } = nav.state;
const iconName: string = getIcon(routeName);

if (routeName === ROUTES.MESSAGES_NAVIGATOR) {
return (
<MessagesTabIcon
color={options.tintColor === null ? undefined : options.tintColor}
/>
);
}
if (iconName === ROUTE_ICON.PROFILE_NAVIGATOR) {
return (
<ProfileTabIcon
size={variables.iconSize3}
color={options.tintColor === null ? undefined : options.tintColor}
/>
);
} else {
return (
<IconFont
name={iconName}
size={variables.iconSize3}
color={options.tintColor === null ? undefined : options.tintColor}
/>
);
}
return (
<IconFont
name={iconName}
size={variables.iconSize3}
color={options.tintColor === null ? undefined : options.tintColor}
/>
);
},
tabBarOnPress: options => {
if (options.navigation.state.index > 0) {
Expand Down
2 changes: 0 additions & 2 deletions ts/screens/messages/MessageDetailScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import * as React from "react";
import { ActivityIndicator, Image, StyleSheet } from "react-native";
import { NavigationScreenProps } from "react-navigation";
import { connect } from "react-redux";

import { CreatedMessageWithoutContent } from "../../../definitions/backend/CreatedMessageWithoutContent";
import { ServiceId } from "../../../definitions/backend/ServiceId";
import { ServicePublic } from "../../../definitions/backend/ServicePublic";
Expand Down Expand Up @@ -281,7 +280,6 @@ export class MessageDetailScreen extends React.PureComponent<Props, never> {

const mapStateToProps = (state: GlobalState, ownProps: OwnProps) => {
const messageId = ownProps.navigation.getParam("messageId");

const maybeMessageState = fromNullable(
messageStateByIdSelector(messageId)(state)
);
Expand Down
7 changes: 3 additions & 4 deletions ts/screens/messages/MessagesHomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import * as React from "react";
import { StyleSheet } from "react-native";
import { NavigationScreenProps } from "react-navigation";
import { connect } from "react-redux";

import MessagesArchive from "../../components/messages/MessagesArchive";
import MessagesDeadlines from "../../components/messages/MessagesDeadlines";
import MessagesInbox from "../../components/messages/MessagesInbox";
Expand All @@ -37,7 +36,6 @@ import customVariables from "../../theme/variables";

// Used to disable the Deadlines tab
const DEADLINES_TAB_ENABLED = false;

type Props = NavigationScreenProps &
ReturnType<typeof mapStateToProps> &
ReturnType<typeof mapDispatchToProps>;
Expand Down Expand Up @@ -108,7 +106,6 @@ class MessagesHomeScreen extends React.Component<Props, State> {
public componentDidMount() {
this.props.refreshMessages();
}

public render() {
const { searchText } = this.state;

Expand Down Expand Up @@ -275,7 +272,9 @@ const mapStateToProps = (state: GlobalState) => ({
});

const mapDispatchToProps = (dispatch: Dispatch) => ({
refreshMessages: () => dispatch(loadMessages.request()),
refreshMessages: () => {
dispatch(loadMessages.request());
},
navigateToMessageDetail: (messageId: string) =>
dispatch(navigateToMessageDetailScreenAction({ messageId })),
updateMessagesArchivedState: (
Expand Down
14 changes: 13 additions & 1 deletion ts/store/reducers/entities/messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import messagesAllIdsReducer, {
messagesAllIdsSelector,
MessagesAllIdsState
} from "./messagesAllIds";

import messagesByIdReducer, {
messagesStateByIdSelector,
MessageStateById
Expand All @@ -34,7 +35,7 @@ const reducer = combineReducers<MessagesState, Action>({

// Selectors

/**
/**-
* Returns array of messages IDs inversely lexically ordered.
*/
export const lexicallyOrderedMessagesIds = createSelector(
Expand All @@ -59,4 +60,15 @@ export const lexicallyOrderedMessagesStateSelector = createSelector(
)
);

export const messagesUnreadSelector = createSelector(
lexicallyOrderedMessagesStateSelector,
potMessagesState =>
pot.getOrElse(
pot.map(potMessagesState, _ =>
_.filter(messageState => !messageState.isRead)
),
[]
).length
);

export default reducer;
60 changes: 59 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,13 @@
version "2.0.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since you didn't add any package, yarn.lock must not change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matgentili please check this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fpersico Can i remove yarn.lock ? I don't add any package

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just revert the changes.

resolved "https://registry.yarnpkg.com/@types/react-native-background-timer/-/react-native-background-timer-2.0.0.tgz#c44c57f8fbca9d9d5521fdd72a8f55232b79381e"

"@types/react-native-elements@^0.18.0":
version "0.18.0"
resolved "https://registry.yarnpkg.com/@types/react-native-elements/-/react-native-elements-0.18.0.tgz#81cf92d75a5d9ed73599761da37bd2b05b107a91"
integrity sha512-Tt0aq6HlN31Wexica9MwTwxnt46fLyx6yzMFJWPx2hqACrvBZfFTlwCoWMRa6ArR/kX3XJbAe6vKEBuZ08Zvtw==
dependencies:
react-native-elements "*"

"@types/react-native-i18n@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@types/react-native-i18n/-/react-native-i18n-2.0.0.tgz#2df92b3392d813b39530bd126aad429eedc9c3de"
Expand Down Expand Up @@ -2634,6 +2641,14 @@ color@^3.0.0:
color-convert "^1.9.1"
color-string "^1.5.2"

color@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/color/-/color-3.1.0.tgz#d8e9fb096732875774c84bf922815df0308d0ffc"
integrity sha512-CwyopLkuRYO5ei2EpzpIh6LqJMt6Mt+jZhO5VI5f/wJLZriXQE32/SSqzmrh+QB+AZT81Cj8yv+7zwToW8ahZg==
dependencies:
color-convert "^1.9.1"
color-string "^1.5.2"

color@~1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/color/-/color-1.0.3.tgz#e48e832d85f14ef694fb468811c2d5cfe729b55d"
Expand Down Expand Up @@ -2997,6 +3012,11 @@ deep-is@~0.1.3:
version "0.1.3"
resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34"

deepmerge@^3.1.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-3.2.0.tgz#58ef463a57c08d376547f8869fdc5bcee957f44e"
integrity sha512-6+LuZGU7QCNUnAJyX8cIrlzoEgggTM6B7mm+znKOX4t5ltluT9KLjN6g61ECMS0LTsLW7yDpNoxhix5FZcrIow==

default-require-extensions@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/default-require-extensions/-/default-require-extensions-2.0.0.tgz#f5f8fbb18a7d6d50b21f641f649ebb522cfe24f7"
Expand Down Expand Up @@ -4200,6 +4220,13 @@ hoist-non-react-statics@^3.0.1:
dependencies:
react-is "^16.3.2"

hoist-non-react-statics@^3.1.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-3.3.0.tgz#b09178f0122184fb95acf525daaecb4d8f45958b"
integrity sha512-0XsbTXxgiaCDYDIWFcwkmerZPSwywfUqYmwT4jzewKTQSWoE6FCMoUVOeBJWK3E/CrWbxRG3m5GzY4lnIwGRBA==
dependencies:
react-is "^16.7.0"

hoist-non-react-statics@^3.2.1:
version "3.2.1"
resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-3.2.1.tgz#c09c0555c84b38a7ede6912b61efddafd6e75e1e"
Expand Down Expand Up @@ -6692,6 +6719,11 @@ ono@^4.0.3, ono@^4.0.5:
dependencies:
format-util "^1.0.3"

opencollective-postinstall@^2.0.0:
version "2.0.2"
resolved "https://registry.yarnpkg.com/opencollective-postinstall/-/opencollective-postinstall-2.0.2.tgz#5657f1bede69b6e33a45939b061eb53d3c6c3a89"
integrity sha512-pVOEP16TrAO2/fjej1IdOyupJY8KDUM1CvsaScRbw6oddvpQoOfGk4ywha0HKKVAD6RkW4x6Q+tNBwhf3Bgpuw==

opn@^3.0.2:
version "3.0.3"
resolved "https://registry.yarnpkg.com/opn/-/opn-3.0.3.tgz#b6d99e7399f78d65c3baaffef1fb288e9b85243a"
Expand Down Expand Up @@ -7286,7 +7318,7 @@ react-is@^16.6.3:
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.7.0.tgz#c1bd21c64f1f1364c6f70695ec02d69392f41bfa"
integrity sha512-Z0VRQdF4NPDoI0tsXVMLkJLiwEBa+RP66g0xDHxgxysxSoCUccSten4RTF/UFvZF1dZvZ9Zu1sx+MDXwcOR34g==

react-is@^16.8.3, react-is@^16.8.4:
react-is@^16.7.0, react-is@^16.8.3, react-is@^16.8.4:
version "16.8.6"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.8.6.tgz#5bbc1e2d29141c9fbdfed456343fe2bc430a6a16"
integrity sha512-aUk3bHfZ2bRSVFFbbeVS4i+lNPZr3/WM5jT2J5omUVV1zzcs1nAaf3l51ctA5FFvCRbhrH0bdAsRRQddFJZPtA==
Expand Down Expand Up @@ -7343,6 +7375,19 @@ [email protected]:
dependencies:
lodash "4.17.11"

react-native-elements@*:
version "1.1.0"
resolved "https://registry.yarnpkg.com/react-native-elements/-/react-native-elements-1.1.0.tgz#f99bcda4459a886f3ab4591c684c099d37aedf2b"
integrity sha512-n1eOL0kUdlH01zX7bn1p7qhYXn7kquqxYQ0oWlxoAck9t5Db/KeK5ViOsAk8seYSvAG6Pe7OxgzRFnMfFhng0Q==
dependencies:
color "^3.1.0"
deepmerge "^3.1.0"
hoist-non-react-statics "^3.1.0"
opencollective-postinstall "^2.0.0"
prop-types "^15.5.8"
react-native-ratings "^6.3.0"
react-native-status-bar-height "^2.2.0"

[email protected]:
version "2.10.0"
resolved "https://registry.yarnpkg.com/react-native-exception-handler/-/react-native-exception-handler-2.10.0.tgz#0d828a4f2c7c4469a2929fa46d20535def726903"
Expand Down Expand Up @@ -7433,6 +7478,14 @@ react-native-qrcode-scanner@^1.1.0:
prop-types "^15.5.10"
react-native-permissions "^1.1.1"

react-native-ratings@^6.3.0:
version "6.3.1"
resolved "https://registry.yarnpkg.com/react-native-ratings/-/react-native-ratings-6.3.1.tgz#4e4bd87f376423dc62c933f570fc1932c78adaa4"
integrity sha512-+WEtk4wPvnoN5YbfWcmyM4LpKOlvkrFlpQe0KrqeWBAOkN6OXOZYBtiCh97dCIb8Ovpm7goOEcTf3T1MGCi2LA==
dependencies:
lodash "^4.17.4"
prop-types "^15.5.10"

react-native-safe-area-view@^0.12.0:
version "0.12.0"
resolved "https://registry.yarnpkg.com/react-native-safe-area-view/-/react-native-safe-area-view-0.12.0.tgz#5c312f087300ecf82e8541c3eac25d560e147f22"
Expand All @@ -7455,6 +7508,11 @@ react-native-splash-screen@^3.2.0:
resolved "https://registry.yarnpkg.com/react-native-splash-screen/-/react-native-splash-screen-3.2.0.tgz#d47ec8557b1ba988ee3ea98d01463081b60fff45"
integrity sha512-Ls9qiNZzW/OLFoI25wfjjAcrf2DZ975hn2vr6U9gyuxi2nooVbzQeFoQS5vQcbCt9QX5NY8ASEEAtlLdIa6KVg==

react-native-status-bar-height@^2.2.0:
version "2.3.1"
resolved "https://registry.yarnpkg.com/react-native-status-bar-height/-/react-native-status-bar-height-2.3.1.tgz#b92ce9112c2367290847ac11284d9d84a6330169"
integrity sha512-m9nGKYfFn6ljF1abafzF5cFaD9JCzXwj7kNE9CuF+g0TgtItH70eY2uHaCV9moENTftqd5XIS3Cx0mf4WfistA==

react-native-svg@^6.5.3:
version "6.5.3"
resolved "https://registry.yarnpkg.com/react-native-svg/-/react-native-svg-6.5.3.tgz#44004c4cdc4a289acb613d718eda6f80e0c5a026"
Expand Down