Skip to content

Commit

Permalink
adding binary attachements to mobile app
Browse files Browse the repository at this point in the history
  • Loading branch information
balzack committed Aug 11, 2023
1 parent b2f1316 commit f3fc131
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 15 deletions.
47 changes: 34 additions & 13 deletions app/mobile/src/session/conversation/addTopic/AddTopic.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import ColorPicker from 'react-native-wheel-color-picker'
import { VideoFile } from './videoFile/VideoFile';
import { AudioFile } from './audioFile/AudioFile';
import { ImageFile } from './imageFile/ImageFile';
import { BinaryFile } from './binaryFile/BinaryFile';

export function AddTopic({ contentKey, shareIntent, setShareIntent }) {

Expand Down Expand Up @@ -80,15 +81,28 @@ export function AddTopic({ contentKey, shareIntent, setShareIntent }) {

const addAudio = async () => {
try {
const audio = await DocumentPicker.pickSingle({
presentationStyle: 'fullScreen',
copyTo: 'cachesDirectory',
type: DocumentPicker.types.audio,
})
actions.addAudio(audio.fileCopyUri, audio.name.replace(/\.[^/.]+$/, ""));
} catch (err) {
console.log(err);
}
const audio = await DocumentPicker.pickSingle({
presentationStyle: 'fullScreen',
copyTo: 'cachesDirectory',
type: DocumentPicker.types.audio,
})
actions.addAudio(audio.fileCopyUri, audio.name.replace(/\.[^/.]+$/, ""));
} catch (err) {
console.log(err);
}
}

const addBinary = async () => {
try {
const binary = await DocumentPicker.pickSingle({
presentationStyle: 'fullScreen',
copyTo: 'cachesDirectory',
type: DocumentPicker.types.allFiles,
})
actions.addBinary(binary.fileCopyUri, binary.name);
} catch (err) {
console.log(err);
}
}

const remove = (item) => {
Expand Down Expand Up @@ -123,7 +137,13 @@ export function AddTopic({ contentKey, shareIntent, setShareIntent }) {
if (item.type === 'audio') {
return (
<AudioFile path={item.data} label={item.label} remove={() => remove(item)}
setLabel={(label) => actions.setAudioLabel(item.key, label)} />
setLabel={(label) => actions.setLabel(item.key, label)} />
)
}
if (item.type === 'binary') {
return (
<BinaryFile path={item.data} label={item.label} extension={item.extension} remove={() => remove(item)}
setLabel={(label) => actions.setLabel(item.key, label)} />
)
}
else {
Expand Down Expand Up @@ -171,9 +191,10 @@ export function AddTopic({ contentKey, shareIntent, setShareIntent }) {
<MatIcons name="music-box-outline" size={20} color={Colors.text} />
</TouchableOpacity>
)}
{ (state.enableImage || state.enableVideo || state.enableAudio) && (
<View style={styles.divider} />
)}
<TouchableOpacity style={styles.addButton} onPress={addBinary}>
<MatIcons name="all-inclusive-box-outline" size={20} color={Colors.text} />
</TouchableOpacity>
<View style={styles.divider} />
<TouchableOpacity style={styles.addButton} onPress={actions.showFontSize}>
<MatIcons name="format-size" size={20} color={Colors.text} />
</TouchableOpacity>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Image, Text, View, TextInput, TouchableOpacity } from 'react-native';
import { styles } from './BinaryFile.styled';

export function BinaryFile({ path, remove, extension, label, setLabel }) {
return (
<TouchableOpacity style={styles.binary} onLongPress={remove}>
<TextInput style={ styles.input } value={ label } onChangeText={setLabel}
multiline={true} autoCapitalize={'none'} placeholder="Binary Label" />
<View style={styles.extension}>
<Text style={styles.label}>{ extension }</Text>
</View>
</TouchableOpacity>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { StyleSheet } from 'react-native';
import { Colors } from 'constants/Colors';

export const styles = StyleSheet.create({
binary: {
width: 92,
height: 92,
backgroundColor: '#888888',
borderRadius: 4,
marginRight: 16,
display: 'flex',
alignItems: 'center',
},
input: {
maxHeight: 50,
textAlign: 'center',
padding: 4,
color: 'white',
},
extension: {
flexGrow: 1,
display: 'flex',
alignItems: 'flex-end',
justifyContent: 'flex-end',
},
label: {
color: 'white',
fontSize: 24,
},
})
16 changes: 14 additions & 2 deletions app/mobile/src/session/conversation/addTopic/useAddTopic.hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,19 @@ export function useAddTopic(contentKey) {
asset.type = 'audio';
asset.label = label;
updateState({ assets: [ ...state.assets, asset ] });
},
},
addBinary: async (data, name) => {
assetId.current++;
const asset = await setAsset(data);
asset.key = assetId.current;
asset.type = 'binary';
asset.extension = name.split('.').pop().toUpperCase();
asset.label = name.slice(0, -1 * (asset.extension.length + 1));

console.log(asset);

updateState({ assets: [ ...state.assets, asset ] });
},
setVideoPosition: (key, position) => {
updateState({ assets: state.assets.map((item) => {
if(item.key === key) {
Expand All @@ -172,7 +184,7 @@ export function useAddTopic(contentKey) {
})
});
},
setAudioLabel: (key, label) => {
setLabel: (key, label) => {
updateState({ assets: state.assets.map((item) => {
if(item.key === key) {
return { ...item, label };
Expand Down

0 comments on commit f3fc131

Please sign in to comment.