diff --git a/client/react-native/app/view/component/ContactIdentityActions/ActionsAdd.js b/client/react-native/app/view/component/ContactIdentityActions/ActionsAdd.js index 19121ad720..eebc808f24 100644 --- a/client/react-native/app/view/component/ContactIdentityActions/ActionsAdd.js +++ b/client/react-native/app/view/component/ContactIdentityActions/ActionsAdd.js @@ -3,32 +3,29 @@ import { withNavigation } from 'react-navigation' import React from 'react' import ActionList from './ActionList' -import { withStoreContext } from '@berty/store/context' -const ActionsAdd = withStoreContext( - ({ data, self, context, navigation, inModal, t }) => ( - - { - await context.node.service.contactRequest({ - contactId: data.id, - contactOverrideDisplayName: - data.overrideDisplayName || data.displayName || '', - introText: '', - }) +const ActionsAdd = ({ data, self, context, navigation, inModal, t }) => ( + + { + await context.node.service.contactRequest({ + contactId: data.id, + contactOverrideDisplayName: + data.overrideDisplayName || data.displayName || '', + introText: '', + }) - const beforeDismiss = navigation.getParam('beforeDismiss') - if (beforeDismiss) { - beforeDismiss() - } - }} - successMessage={t('contacts.add-action-feedback')} - /> - - ) + const beforeDismiss = navigation.getParam('beforeDismiss') + if (beforeDismiss) { + beforeDismiss() + } + }} + successMessage={t('contacts.add-action-feedback')} + /> + ) export default withNamespaces()(withNavigation(ActionsAdd)) diff --git a/client/react-native/app/view/component/ContactIdentityActions/ActionsReceived.js b/client/react-native/app/view/component/ContactIdentityActions/ActionsReceived.js index 77ee2074b1..c52467d73a 100644 --- a/client/react-native/app/view/component/ContactIdentityActions/ActionsReceived.js +++ b/client/react-native/app/view/component/ContactIdentityActions/ActionsReceived.js @@ -2,29 +2,26 @@ import React from 'react' import { colors } from '@berty/common/constants' import ActionList from './ActionList' import { withNamespaces } from 'react-i18next' -import { withStoreContext } from '@berty/store/context' -const ReceivedActions = withStoreContext( - ({ data: { id }, inModal, t, context }) => ( - - - context.node.service.contactAcceptRequest({ contactId: id }) - } - successMessage={t('contacts.accept-action-feedback')} - /> - context.node.service.contactRemove({ id })} - successMessage={t('contacts.decline-action-feedback')} - /> - - ) +const ReceivedActions = ({ data: { id }, inModal, t, context }) => ( + + + context.node.service.contactAcceptRequest({ contactId: id }) + } + successMessage={t('contacts.accept-action-feedback')} + /> + context.node.service.contactRemove({ id })} + successMessage={t('contacts.decline-action-feedback')} + /> + ) export default withNamespaces()(ReceivedActions) diff --git a/client/react-native/app/view/component/ContactIdentityActions/ActionsSent.js b/client/react-native/app/view/component/ContactIdentityActions/ActionsSent.js index e11ef74cb9..7d31fbdd64 100644 --- a/client/react-native/app/view/component/ContactIdentityActions/ActionsSent.js +++ b/client/react-native/app/view/component/ContactIdentityActions/ActionsSent.js @@ -2,9 +2,8 @@ import React from 'react' import { colors } from '@berty/common/constants' import ActionList from './ActionList' import { withNamespaces } from 'react-i18next' -import { withStoreContext } from '@berty/store/context' -const ActionsSent = withStoreContext(({ data, context, inModal, t }) => ( +const ActionsSent = ({ data, context, inModal, t }) => ( ( successMessage={t('contacts.cancel-request-action-feedback')} /> -)) +) export default withNamespaces()(ActionsSent) diff --git a/client/react-native/app/view/component/ContactIdentityActions/ActionsUnknown.js b/client/react-native/app/view/component/ContactIdentityActions/ActionsUnknown.js index dab36198f0..698d5015b6 100644 --- a/client/react-native/app/view/component/ContactIdentityActions/ActionsUnknown.js +++ b/client/react-native/app/view/component/ContactIdentityActions/ActionsUnknown.js @@ -2,9 +2,8 @@ import React from 'react' import { colors } from '@berty/common/constants' import ActionList from './ActionList' import { withNamespaces } from 'react-i18next' -import { withStoreContext } from '@berty/store/context' -const ActionsUnknown = withStoreContext(({ data, inModal, t, context }) => ( +const ActionsUnknown = ({ data, inModal, t, context }) => ( ( successMessage={t('contacts.cancel-request-action-feedback')} /> -)) +) export default withNamespaces()(ActionsUnknown) diff --git a/client/react-native/app/view/component/ContactIdentityActions/index.js b/client/react-native/app/view/component/ContactIdentityActions/index.js index 32e452a035..3015db4433 100644 --- a/client/react-native/app/view/component/ContactIdentityActions/index.js +++ b/client/react-native/app/view/component/ContactIdentityActions/index.js @@ -7,11 +7,18 @@ import ActionsShare from './ActionsShare' import ReceivedActions from './ActionsReceived' import ActionsSent from './ActionsSent' -const Actions = ({ data, navigation }) => { +const Actions = ({ data, context, navigation }) => { switch (data.status) { case null: case undefined: - return + return ( + + ) case enums.BertyEntityContactInputStatus.Myself: return @@ -21,10 +28,10 @@ const Actions = ({ data, navigation }) => { return case enums.BertyEntityContactInputStatus.IsRequested: - return + return case enums.BertyEntityContactInputStatus.RequestedMe: - return + return case enums.BertyEntityContactInputStatus.IsBlocked: return Is blocked diff --git a/client/react-native/app/view/component/DebugStateBar.js b/client/react-native/app/view/component/DebugStateBar.js index 3b6b7e1a55..6fbbd86598 100644 --- a/client/react-native/app/view/component/DebugStateBar.js +++ b/client/react-native/app/view/component/DebugStateBar.js @@ -5,7 +5,6 @@ import Text from './Text' import { View, Platform } from 'react-native' import Icon from './Icon' import NavigationService from '@berty/common/helpers/NavigationService' -import { withStoreContext } from '@berty/store/context' import promiseWithTimeout from '@berty/common/helpers/promiseWithTimeout' const daemonStateValues = { @@ -14,7 +13,6 @@ const daemonStateValues = { connected: 2, } -@withStoreContext class DebugStateBar extends PureComponent { constructor(props) { super(props) diff --git a/client/react-native/app/view/component/Notifications.js b/client/react-native/app/view/component/Notifications.js deleted file mode 100644 index aa42d96f4d..0000000000 --- a/client/react-native/app/view/component/Notifications.js +++ /dev/null @@ -1,141 +0,0 @@ -import React, { PureComponent } from 'react' -import { withStoreContext } from '@berty/store/context' -import { Store } from '@berty/container' -import { deepFilterEqual } from '@berty/container/helper' -import Kind from '@berty/bridge/service/entity/kind' -import Event from '@berty/bridge/service/entity/event' -import Case from 'case' -import { Mutex } from 'async-mutex' -import { debounce } from 'throttle-debounce' -import tDate from '@berty/common/helpers/timestampDate' -import { conversation } from '@berty/common/helpers/entity' - -@withStoreContext -export class Notifications extends PureComponent { - static defaultProps = { - target: null, // id of specific target - entity: null, // 'contact' or 'conversation' - kind: null, // event kind name - reduce: (queue, data) => [...queue, data], - children: () => null, - } - - queue = [] - - smartForceUpdateMutex = new Mutex() - smartForceUpdate = async () => { - if (this.smartForceUpdateMutex.isLocked()) { - return - } - const release = await this.smartForceUpdateMutex.acquire() - this.forceUpdateDebounced(release) - } - forceUpdateDebounced = debounce(16, this.forceUpdate) - - update = (_, data) => { - this.queue = this.props.reduce(this.queue, data) - this.smartForceUpdate() - } - - render() { - const { children, target, entity, kind } = this.props - - const filter = { - direction: Event.Direction.Incoming, - targetAddr: target, - targetType: entity - ? Event.TargetType[`ToSpecific${Case.pascal(entity)}`] - : null, - kind: Kind.values[kind], - } - return ( - <> - - { - data = data.entity.event - if ( - data && - this.queue.length !== 99 && - deepFilterEqual(filter, data) - ) { - this.update(_, data) - } - return _ - }} - /> - {children(this.queue, this.queue.length)} - - ) - } -} - -@withStoreContext -export class ContactsNotifications extends PureComponent { - static defaultProps = { - kind: null, - children: () => null, - } - - render() { - const { children, kind } = this.props - return ( - { - // remove duplicates - queue = queue.filter( - _ => - _.sourceContactID !== data.sourceContactID && _.kind !== data.kind - ) - queue.push(data) - return queue - }} - > - {children} - - ) - } -} -Notifications.Contacts = ContactsNotifications - -@withStoreContext -export class ConversationsNotifications extends PureComponent { - static defaultProps = { - children: () => null, - } - - render() { - const { children } = this.props - return ( - ({ - first: 1000, - after: cursor - ? tDate(cursor).toISOString() - : new Date(Date.now()).toISOString(), - orderBy: 'wrote_at', - orderDesc: true, - })} - cursorExtractor={item => tDate(item.wroteAt).getTime()} - > - {({ queue, paginate }) => { - const notifications = queue.filter(_ => !conversation.isReadByMe(_)) - return children(notifications, notifications.length) - }} - - ) - } -} -Notifications.Conversations = ConversationsNotifications - -export default Notifications diff --git a/client/react-native/app/view/component/SelfAvatarIcon.js b/client/react-native/app/view/component/SelfAvatarIcon.js deleted file mode 100644 index 8411aa4b30..0000000000 --- a/client/react-native/app/view/component/SelfAvatarIcon.js +++ /dev/null @@ -1,33 +0,0 @@ -import React, { PureComponent } from 'react' - -import Loader from './Loader' -import { TouchableOpacity } from 'react-native' -import { withNavigation } from 'react-navigation' - -import Avatar from './Avatar' -import { Store } from '@berty/container' - -@withNavigation -class SelfAvatarLink extends PureComponent { - onPress = data => { - this.props.navigation.navigate('modal/contacts/card', data) - } - - render() { - return ( - - {data => - data ? ( - this.onPress(data)}> - - - ) : ( - - ) - } - - ) - } -} - -export default SelfAvatarLink diff --git a/client/react-native/app/view/component/index.js b/client/react-native/app/view/component/index.js index 56304ba088..d08673ec66 100644 --- a/client/react-native/app/view/component/index.js +++ b/client/react-native/app/view/component/index.js @@ -17,11 +17,9 @@ export Loader from './Loader' export Avatar from './Avatar' export ContactIdentity from './ContactIdentity' export ContactIdentityActions from './ContactIdentityActions' -export SelfAvatarIcon from './SelfAvatarIcon' export EmptyList from './EmptyList' export Animation from './Animation' export MovableView from './MovableView' export DebugStateBar from './DebugStateBar' export Markdown from './Markdown' export OptimizedFlatList from './OptimizedFlatList' -export Notifications from './Notifications' diff --git a/client/react-native/app/view/component/package.json b/client/react-native/app/view/component/package.json index 527b2165f5..4d46057c13 100644 --- a/client/react-native/app/view/component/package.json +++ b/client/react-native/app/view/component/package.json @@ -9,8 +9,6 @@ "private": true, "dependencies": { "@berty/common": "^0.0.1", - "@berty/container": "^0.0.1", - "@berty/store": "^0.0.1", "@berty/update": "^0.0.1", "async-mutex": "^0.1.3", "react": "16.8.3", diff --git a/client/react-native/app/view/navigation/ContactNavigator.js b/client/react-native/app/view/navigation/ContactNavigator.js index 613cfddfe4..6a670579dc 100644 --- a/client/react-native/app/view/navigation/ContactNavigator.js +++ b/client/react-native/app/view/navigation/ContactNavigator.js @@ -1,11 +1,14 @@ import React from 'react' +import { TouchableOpacity } from 'react-native' import { createStackNavigator, createSwitchNavigator } from 'react-navigation' -import { Header, SelfAvatarIcon } from '@berty/component' +import { Header } from '@berty/component' import ContactTopNavigator from './ContactTopNavigator' import AddContactMaterialNavigator from './ModalMaterialNavigator' import List from '@berty/screen/Contacts/Detail/Detail' import Edit from '@berty/screen/Contacts/Detail/Edit' import I18n from 'i18next' +import { Avatar, Loader } from '@berty/component' +import { Store } from '@berty/container' export const SplitSideContactNavigator = createStackNavigator( { @@ -53,7 +56,23 @@ export const SubviewsContactAddNavigator = createStackNavigator(
} + rightBtn={ + + {data => + data ? ( + + navigation.navigate('modal/contacts/card', data) + } + > + + + ) : ( + + ) + } + + } backBtn /> ), diff --git a/client/react-native/app/view/screen/App.js b/client/react-native/app/view/screen/App.js index 4e76947936..0778e87439 100644 --- a/client/react-native/app/view/screen/App.js +++ b/client/react-native/app/view/screen/App.js @@ -39,9 +39,10 @@ export default class App extends PureComponent { service: null, }, setContext: bridge => { + const store = new Store(bridge) this.setState({ - store: new Store(bridge), - debugBar: , + store, + debugBar: , }) }, }), diff --git a/client/react-native/app/view/screen/Contacts/ContactCardModal.js b/client/react-native/app/view/screen/Contacts/ContactCardModal.js index c862fa9203..255a1dc8e0 100644 --- a/client/react-native/app/view/screen/Contacts/ContactCardModal.js +++ b/client/react-native/app/view/screen/Contacts/ContactCardModal.js @@ -8,15 +8,17 @@ import { } from '@berty/component' import { withNavigation } from 'react-navigation' import { Store } from '@berty/container' +import { withStoreContext } from '@berty/store/context' const modalWidth = 320 +@withStoreContext @withNavigation class ContactCardModal extends React.Component { static router = ContactIdentity.router render() { - const { navigation } = this.props + const { context, navigation } = this.props const navigationData = { id: navigation.getParam('id'), displayName: navigation.getParam('displayName'), @@ -36,7 +38,7 @@ class ContactCardModal extends React.Component { } > - + )} diff --git a/client/react-native/app/view/screen/Contacts/List/Item.js b/client/react-native/app/view/screen/Contacts/List/Item.js index 46e04b9eb9..1a9925f1a7 100644 --- a/client/react-native/app/view/screen/Contacts/List/Item.js +++ b/client/react-native/app/view/screen/Contacts/List/Item.js @@ -8,7 +8,9 @@ import ActionsUnknown from '@berty/component/ContactIdentityActions/ActionsUnkno import ActionsReceived from '@berty/component/ContactIdentityActions/ActionsReceived' import ActionsSent from '@berty/component/ContactIdentityActions/ActionsSent' import { withNamespaces } from 'react-i18next' +import { withStoreContext } from '@berty/store/context' +@withStoreContext @withNamespaces() @withNavigation export class Item extends PureComponent { @@ -26,7 +28,7 @@ export class Item extends PureComponent { } render() { - const { data, ignoreMyself, t } = this.props + const { context, data, ignoreMyself, t } = this.props const { overrideDisplayName, displayName, status } = data if (ignoreMyself && status === enums.BertyEntityContactInputStatus.Myself) { @@ -55,13 +57,13 @@ export class Item extends PureComponent { {status === enums.BertyEntityContactInputStatus.Unknown && ( - + )} {status === enums.BertyEntityContactInputStatus.RequestedMe && ( - + )} {status === enums.BertyEntityContactInputStatus.IsRequested && ( - + )} )