Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Guillaume Louvigny
committed
Dec 18, 2018
1 parent
494b4a6
commit 5f9c014
Showing
55 changed files
with
1,367 additions
and
725 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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,36 @@ | ||
import React from 'react' | ||
import { Image } from 'react-native' | ||
import { fingerprint } from '../../helpers/fingerprint' | ||
import { extractPublicKeyFromId } from '../../helpers/contacts' | ||
|
||
const Avatar = ({ data, size = 40, margin = 4, uri = null, style = [] }) => { | ||
if (uri !== null) { | ||
return <Image | ||
style={[{ width: size, height: size, borderRadius: size / 2, margin: margin }, ...style]} | ||
source={{ | ||
uri: uri, | ||
}} | ||
/> | ||
} | ||
|
||
if (!(style instanceof Array)) { | ||
style = [style] | ||
} | ||
|
||
if (!data || !data.id) { | ||
console.error(['No id provided', data]) | ||
} | ||
|
||
const id = extractPublicKeyFromId(data.id) || data.id | ||
const hexCode = fingerprint(id).substring(0, 16) | ||
const retinaMode = 2 | ||
|
||
return <Image | ||
style={[{ width: size, height: size, borderRadius: size / 2, margin: margin }, ...style]} | ||
source={{ | ||
uri: `https://api.adorable.io/avatars/${size * retinaMode}/${hexCode}.png`, | ||
}} | ||
/> | ||
} | ||
|
||
export default Avatar |
This file contains 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
12 changes: 12 additions & 0 deletions
12
client/react-native/common/components/Library/ContactIdentityActions/ActionButton.js
This file contains 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,12 @@ | ||
import React from 'react' | ||
import { Text, TouchableOpacity } from 'react-native' | ||
import { Button, Icon } from '..' | ||
import colors from '../../../constants/colors' | ||
|
||
const ActionButton = ({ icon, title, onPress }) => <TouchableOpacity style={{ flex: 1 }} onPress={onPress}> | ||
<Button rounded={'circle'} background={colors.blue} color={colors.white} | ||
icon={<Icon name={icon} color={colors.white} />} /> | ||
<Text style={{ color: colors.white }}>{title}</Text> | ||
</TouchableOpacity> | ||
|
||
export default ActionButton |
48 changes: 48 additions & 0 deletions
48
client/react-native/common/components/Library/ContactIdentityActions/ActionsAdd.js
This file contains 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,48 @@ | ||
import React from 'react' | ||
import { withNavigation } from 'react-navigation' | ||
import RelayContext from '../../../relay/RelayContext' | ||
import defaultValuesContact from '../../../utils/contact' | ||
import ActionButton from './ActionButton' | ||
import { showMessage } from 'react-native-flash-message' | ||
import { btoa } from 'b64-lite' | ||
|
||
const ActionsAdd = ({ data, self, navigation }) => <> | ||
<RelayContext.Consumer>{({ mutations }) => | ||
<ActionButton icon={'plus'} title={'Add contact'} | ||
onPress={async () => { | ||
const input = { | ||
contact: { | ||
...defaultValuesContact, | ||
...data, | ||
id: btoa(`contact:${data.id}`), | ||
}, | ||
introText: '', | ||
} | ||
|
||
try { | ||
await mutations.contactRequest(input) | ||
|
||
showMessage({ | ||
message: 'A request has been sent to this contact', | ||
type: 'info', | ||
position: 'center', | ||
}) | ||
|
||
const beforeDismiss = navigation.getParam('beforeDismiss') | ||
beforeDismiss() | ||
|
||
navigation.goBack(null) | ||
} catch (err) { | ||
showMessage({ | ||
message: 'An error occurred while sending a request to this contact', | ||
type: 'danger', | ||
icon: 'danger', | ||
position: 'center', | ||
}) | ||
} | ||
}} | ||
/> | ||
}</RelayContext.Consumer> | ||
</> | ||
|
||
export default withNavigation(ActionsAdd) |
46 changes: 46 additions & 0 deletions
46
client/react-native/common/components/Library/ContactIdentityActions/ActionsShare.js
This file contains 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,46 @@ | ||
import React from 'react' | ||
import { withNavigation } from 'react-navigation' | ||
import { Clipboard } from 'react-native' | ||
import { makeShareableUrl, shareLinkOther, shareLinkSelf } from '../../../helpers/contacts' | ||
import saveViewToCamera from '../../../helpers/saveViewToCamera' | ||
import QRCodeExport from '../QRExport' | ||
import ActionButton from './ActionButton' | ||
import { showMessage } from 'react-native-flash-message' | ||
|
||
const ActionsShare = ({ data, self, navigation }) => { | ||
const { id, displayName } = data | ||
|
||
return <> | ||
<ActionButton icon={'share'} title={'Share'} | ||
onPress={() => | ||
self | ||
? shareLinkSelf({ id, displayName }) | ||
: shareLinkOther({ id, displayName }) | ||
} | ||
/> | ||
<ActionButton icon={'image'} title={'Save QR code'} | ||
onPress={async () => { | ||
try { | ||
await saveViewToCamera({ view: <QRCodeExport data={data} />, navigation }) | ||
showMessage({ | ||
message: 'The QR Code has been added to your Camera Roll', | ||
type: 'info', | ||
icon: 'info', | ||
position: 'center', | ||
}) | ||
} catch (e) { | ||
showMessage({ | ||
message: String(e), | ||
type: 'danger', | ||
icon: 'danger', | ||
position: 'center', | ||
}) | ||
} | ||
}} /> | ||
<ActionButton icon={'link'} title={'Copy link'} | ||
onPress={() => Clipboard.setString(makeShareableUrl({ id, displayName }))} /> | ||
<ActionButton icon={'copy'} title={'Copy public key'} onPress={() => Clipboard.setString(id)} /> | ||
</> | ||
} | ||
|
||
export default withNavigation(ActionsShare) |
42 changes: 42 additions & 0 deletions
42
client/react-native/common/components/Library/ContactIdentityActions/index.js
This file contains 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,42 @@ | ||
import React from 'react' | ||
import { WithContact } from '../../../utils/contact' | ||
import { enums } from '../../../graphql' | ||
import { Text, View } from 'react-native' | ||
import { withNavigation } from 'react-navigation' | ||
import ActionsAdd from './ActionsAdd' | ||
import ActionsShare from './ActionsShare' | ||
|
||
const ContactIdentityActions = ({ data, navigation, modalWidth }) => <View | ||
style={{ width: modalWidth, flexDirection: 'row', marginTop: 12 }}> | ||
<WithContact id={data.id}>{(user, state) => { | ||
if (state.type === state.success && (user === null || user.status === enums.BertyEntityContactInputStatus.Unknown)) { | ||
return <ActionsAdd data={data} navigation={navigation} /> | ||
} else if (user === null) { | ||
return <View><Text>LOADING (or error)</Text></View> | ||
} else { | ||
switch (user.status) { | ||
case enums.BertyEntityContactInputStatus.Myself: | ||
return <ActionsShare data={data} self navigation={navigation} /> | ||
|
||
case enums.BertyEntityContactInputStatus.IsFriend: | ||
case enums.BertyEntityContactInputStatus.IsTrustedFriend: | ||
return <ActionsShare data={data} navigation={navigation} /> | ||
|
||
case enums.BertyEntityContactInputStatus.IsRequested: | ||
return <Text>Is requested</Text> | ||
|
||
case enums.BertyEntityContactInputStatus.RequestedMe: | ||
return <Text>Requested me</Text> | ||
|
||
case enums.BertyEntityContactInputStatus.IsBlocked: | ||
return <Text>Is blocked</Text> | ||
|
||
case enums.BertyEntityContactInputStatus.Unknown: | ||
default: | ||
return <Text>Unknown state</Text> | ||
} | ||
} | ||
}}</WithContact> | ||
</View> | ||
|
||
export default withNavigation(ContactIdentityActions) |
This file contains 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.