Skip to content

Commit

Permalink
fix(rn): contact details in chat
Browse files Browse the repository at this point in the history
Signed-off-by: Godefroy Ponsinet <godefroy.ponsinet@outlook.com>
  • Loading branch information
90dy committed Jun 11, 2019
1 parent d8d0c22 commit 36da6f8
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 46 deletions.
118 changes: 82 additions & 36 deletions client/react-native/app/container/container.gen.js
Expand Up @@ -2,87 +2,133 @@ import { observer } from 'mobx-react'
import { observe } from 'mobx'
import { Stream, StreamPagination } from './stream'
import { Unary } from './unary'
import { Entity } from './entity'
import { withStoreContext } from '@berty/store/context'
import { Component } from 'react'

@withStoreContext
@observer
export class ConfigEntity extends Component {
render () {
const { context, id, children } = this.props
return children(context.entity.config.get(id))
export class ConfigEntity extends Entity {
fetch = () => {
const { context, id } = this.props
return context.node.service.config({ id })
}

get entity () {
const { context, id } = this.props
return context.entity.config.get(id)
}
}

@withStoreContext
@observer
export class ContactEntity extends Component {
render () {
const { context, id, children } = this.props
return children(context.entity.contact.get(id))
export class ContactEntity extends Entity {
fetch = () => {
const { context, id } = this.props
return context.node.service.contact({ id })
}

get entity () {
const { context, id } = this.props
return context.entity.contact.get(id)
}
}

@withStoreContext
@observer
export class DeviceEntity extends Component {
render () {
const { context, id, children } = this.props
return children(context.entity.device.get(id))
export class DeviceEntity extends Entity {
fetch = () => {
const { context, id } = this.props
return context.node.service.device({ id })
}

get entity () {
const { context, id } = this.props
return context.entity.device.get(id)
}
}

@withStoreContext
@observer
export class ConversationEntity extends Component {
render () {
const { context, id, children } = this.props
return children(context.entity.conversation.get(id))
export class ConversationEntity extends Entity {
fetch = () => {
const { context, id } = this.props
return context.node.service.conversation({ id })
}

get entity () {
const { context, id } = this.props
return context.entity.conversation.get(id)
}
}

@withStoreContext
@observer
export class ConversationMemberEntity extends Component {
render () {
const { context, id, children } = this.props
return children(context.entity.conversationMember.get(id))
export class ConversationMemberEntity extends Entity {
fetch = () => {
const { context, id } = this.props
return context.node.service.conversationMember({ id })
}

get entity () {
const { context, id } = this.props
return context.entity.conversationMember.get(id)
}
}

@withStoreContext
@observer
export class EventEntity extends Component {
render () {
const { context, id, children } = this.props
return children(context.entity.event.get(id))
export class EventEntity extends Entity {
fetch = () => {
const { context, id } = this.props
return context.node.service.event({ id })
}

get entity () {
const { context, id } = this.props
return context.entity.event.get(id)
}
}

@withStoreContext
@observer
export class DevicePushConfigEntity extends Component {
render () {
const { context, id, children } = this.props
return children(context.entity.devicePushConfig.get(id))
export class DevicePushConfigEntity extends Entity {
fetch = () => {
const { context, id } = this.props
return context.node.service.devicePushConfig({ id })
}

get entity () {
const { context, id } = this.props
return context.entity.devicePushConfig.get(id)
}
}

@withStoreContext
@observer
export class DevicePushIdentifierEntity extends Component {
render () {
const { context, id, children } = this.props
return children(context.entity.devicePushIdentifier.get(id))
export class DevicePushIdentifierEntity extends Entity {
fetch = () => {
const { context, id } = this.props
return context.node.service.devicePushIdentifier({ id })
}

get entity () {
const { context, id } = this.props
return context.entity.devicePushIdentifier.get(id)
}
}

@withStoreContext
@observer
export class SenderAliasEntity extends Component {
render () {
const { context, id, children } = this.props
return children(context.entity.senderAlias.get(id))
export class SenderAliasEntity extends Entity {
fetch = () => {
const { context, id } = this.props
return context.node.service.senderAlias({ id })
}

get entity () {
const { context, id } = this.props
return context.entity.senderAlias.get(id)
}
}

Expand Down
14 changes: 14 additions & 0 deletions client/react-native/app/container/entity.js
@@ -0,0 +1,14 @@
import { Component } from 'react'

export class Entity extends Component {
render () {
const { children } = this.props
if (this.entity) {
return children(this.entity)
}
this.fetch()
return children()
}
}

export default Entity
14 changes: 10 additions & 4 deletions client/react-native/app/template/container/container.gen.js.hbs
Expand Up @@ -4,6 +4,7 @@ import { observer } from 'mobx-react'
import { observe } from 'mobx'
import { Stream, StreamPagination } from './stream'
import { Unary } from './unary'
import { Entity } from './entity'
import { withStoreContext } from '@berty/store/context'
import { Component } from 'react'

Expand All @@ -15,10 +16,15 @@ import { Component } from 'react'

@withStoreContext
@observer
export class {{name}}Entity extends Component {
render () {
const { context, id, children } = this.props
return children(context.entity.{{case 'camel' name}}.get(id))
export class {{name}}Entity extends Entity {
fetch = () => {
const { context, id } = this.props
return context.node.service.{{case 'camel' name}}({ id })
}

get entity () {
const { context, id } = this.props
return context.entity.{{case 'camel' name}}.get(id)
}
}
{{/if}}
Expand Down
12 changes: 9 additions & 3 deletions client/react-native/app/view/screen/Chats/Settings/List.js
Expand Up @@ -137,12 +137,18 @@ class SettingsScreenBase extends PureComponent {
<Menu.Item
icon='user'
title={t('contacts.details')}
onPress={() =>
onPress={() => {
navigation.navigate('chats/contact/detail/list', {
contact: oneToOneContact,
id: contactUtils.getCoreID(
members.find(
_ =>
_.contact.status !==
enums.BertyEntityContactInputStatus.Myself
).contactId
),
editRoute: 'chats/contact/detail/edit',
})
}
}}
/>
</Menu.Section>
) : (
Expand Down
9 changes: 6 additions & 3 deletions client/react-native/app/view/screen/Contacts/Detail/Detail.js
Expand Up @@ -20,9 +20,12 @@ class Details extends PureComponent {
title={I18n.t('contacts.details')}
rightBtnIcon={'edit-2'}
onPressRightBtn={() => {
navigation.navigate('contact/detail/edit', {
id: navigation.getParam('id'),
})
navigation.navigate(
navigation.getParam('editRoute', 'contact/detail/edit'),
{
id: navigation.getParam('id'),
}
)
}}
backBtn
/>
Expand Down

0 comments on commit 36da6f8

Please sign in to comment.