mirror of
https://github.com/balzack/databag.git
synced 2025-02-15 21:19:16 +00:00
support topic message update
This commit is contained in:
parent
0eb48691ad
commit
6db15568f8
@ -370,6 +370,19 @@ export function useConversationContext() {
|
|||||||
sync();
|
sync();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
setTopicSubject: async (topicId, data) => {
|
||||||
|
if (conversationId.current) {
|
||||||
|
const { cardId, channelId } = conversationId.current;
|
||||||
|
if (cardId) {
|
||||||
|
return await card.actions.setChannelTopicSubject(cardId, channelId, topicId, data);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return await channel.actions.setTopicSubject(channelId, topicId, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
force.current = true;
|
||||||
|
sync();
|
||||||
|
},
|
||||||
setCard: async (id) => {
|
setCard: async (id) => {
|
||||||
if (conversationId.current) {
|
if (conversationId.current) {
|
||||||
const { cardId, channelId } = conversationId.current;
|
const { cardId, channelId } = conversationId.current;
|
||||||
|
@ -60,7 +60,7 @@ export function ConversationBody() {
|
|||||||
inverted={true}
|
inverted={true}
|
||||||
renderItem={({item}) => <TopicItem item={item} focused={item.topicId === state.focus}
|
renderItem={({item}) => <TopicItem item={item} focused={item.topicId === state.focus}
|
||||||
focus={() => actions.setFocus(item.topicId)} hosting={state.host == null}
|
focus={() => actions.setFocus(item.topicId)} hosting={state.host == null}
|
||||||
remove={actions.removeTopic} />}
|
remove={actions.removeTopic} update={actions.updateTopic} />}
|
||||||
keyExtractor={item => item.topicId}
|
keyExtractor={item => item.topicId}
|
||||||
/>
|
/>
|
||||||
<View>
|
<View>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { FlatList, View, Text, Modal, Image, Alert } from 'react-native';
|
import { KeyboardAvoidingView, FlatList, View, Text, TextInput, Modal, Image, Alert } from 'react-native';
|
||||||
import { TouchableOpacity } from 'react-native-gesture-handler';
|
import { TouchableOpacity } from 'react-native-gesture-handler';
|
||||||
import { useTopicItem } from './useTopicItem.hook';
|
import { useTopicItem } from './useTopicItem.hook';
|
||||||
import { styles } from './TopicItem.styled';
|
import { styles } from './TopicItem.styled';
|
||||||
@ -16,7 +16,7 @@ import Carousel from 'react-native-snap-carousel';
|
|||||||
import GestureRecognizer from 'react-native-swipe-gestures';
|
import GestureRecognizer from 'react-native-swipe-gestures';
|
||||||
import avatar from 'images/avatar.png';
|
import avatar from 'images/avatar.png';
|
||||||
|
|
||||||
export function TopicItem({ item, focused, focus, hosting, remove }) {
|
export function TopicItem({ item, focused, focus, hosting, remove, update }) {
|
||||||
|
|
||||||
const { state, actions } = useTopicItem(item, hosting);
|
const { state, actions } = useTopicItem(item, hosting);
|
||||||
|
|
||||||
@ -46,6 +46,20 @@ export function TopicItem({ item, focused, focus, hosting, remove }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const editMessage = async () => {
|
||||||
|
try {
|
||||||
|
await update(item.topicId, { ...state.editData, text: state.editMessage });
|
||||||
|
actions.hideEdit();
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
Alert.alert(
|
||||||
|
'Failed to Update Message',
|
||||||
|
'Please try again.',
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const block = () => {
|
const block = () => {
|
||||||
Alert.alert(
|
Alert.alert(
|
||||||
"Blocking Message",
|
"Blocking Message",
|
||||||
@ -173,11 +187,23 @@ export function TopicItem({ item, focused, focus, hosting, remove }) {
|
|||||||
supportedOrientations={['portrait', 'landscape']}
|
supportedOrientations={['portrait', 'landscape']}
|
||||||
onRequestClose={actions.hideEdit}
|
onRequestClose={actions.hideEdit}
|
||||||
>
|
>
|
||||||
<View style={styles.modal}>
|
<KeyboardAvoidingView behavior="height" style={styles.modal}>
|
||||||
<TouchableOpacity style={{ backgroundColor: 'white' }} onPress={actions.hideEdit}>
|
<View style={styles.editContainer}>
|
||||||
<Text>DONE</Text>
|
<Text style={styles.editHeader}>Edit Message Text:</Text>
|
||||||
</TouchableOpacity>
|
<View style={styles.inputField}>
|
||||||
</View>
|
<TextInput style={styles.input} value={state.editMessage} onChangeText={actions.setEditMessage}
|
||||||
|
autoCapitalize="sentences" placeholder="Message Text" multiline={true} />
|
||||||
|
</View>
|
||||||
|
<View style={styles.editControls}>
|
||||||
|
<TouchableOpacity style={styles.cancel} onPress={actions.hideEdit}>
|
||||||
|
<Text>Cancel</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
<TouchableOpacity style={styles.save} onPress={editMessage}>
|
||||||
|
<Text style={styles.saveText}>Save</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
</KeyboardAvoidingView>
|
||||||
</Modal>
|
</Modal>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
{ focused && (
|
{ focused && (
|
||||||
@ -195,7 +221,6 @@ export function TopicItem({ item, focused, focus, hosting, remove }) {
|
|||||||
<MatIcons name="delete-outline" size={24} color={Colors.white} />
|
<MatIcons name="delete-outline" size={24} color={Colors.white} />
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
</View>
|
</View>
|
||||||
|
@ -70,5 +70,74 @@ export const styles = StyleSheet.create({
|
|||||||
paddingLeft: 52,
|
paddingLeft: 52,
|
||||||
color: Colors.fontColor,
|
color: Colors.fontColor,
|
||||||
},
|
},
|
||||||
|
save: {
|
||||||
|
padding: 8,
|
||||||
|
borderRadius: 4,
|
||||||
|
backgroundColor: Colors.primary,
|
||||||
|
width: 72,
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
},
|
||||||
|
saveText: {
|
||||||
|
color: Colors.white,
|
||||||
|
},
|
||||||
|
cancel: {
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: Colors.lightgrey,
|
||||||
|
borderRadius: 4,
|
||||||
|
padding: 8,
|
||||||
|
marginRight: 8,
|
||||||
|
width: 72,
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
},
|
||||||
|
inputField: {
|
||||||
|
width: '100%',
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: Colors.lightgrey,
|
||||||
|
borderRadius: 4,
|
||||||
|
padding: 8,
|
||||||
|
marginBottom: 8,
|
||||||
|
maxHeight: 92,
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'row',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
},
|
||||||
|
input: {
|
||||||
|
fontSize: 14,
|
||||||
|
flexGrow: 1,
|
||||||
|
},
|
||||||
|
editControls: {
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'row',
|
||||||
|
justifyContent: 'flex-end',
|
||||||
|
},
|
||||||
|
editWrapper: {
|
||||||
|
display: 'flex',
|
||||||
|
width: '100%',
|
||||||
|
height: '100%',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
backgroundColor: 'rgba(52, 52, 52, 0.8)'
|
||||||
|
},
|
||||||
|
editContainer: {
|
||||||
|
backgroundColor: Colors.formBackground,
|
||||||
|
padding: 16,
|
||||||
|
width: '80%',
|
||||||
|
maxWidth: 400,
|
||||||
|
},
|
||||||
|
editHeader: {
|
||||||
|
fontSize: 18,
|
||||||
|
paddingBottom: 16,
|
||||||
|
},
|
||||||
|
editMembers: {
|
||||||
|
width: '100%',
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: Colors.lightgrey,
|
||||||
|
borderRadius: 4,
|
||||||
|
marginBottom: 8,
|
||||||
|
height: 250,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -23,6 +23,8 @@ export function useTopicItem(item, hosting, remove) {
|
|||||||
editable: false,
|
editable: false,
|
||||||
deletable: false,
|
deletable: false,
|
||||||
editing: false,
|
editing: false,
|
||||||
|
editMessage: null,
|
||||||
|
editData: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
const profile = useContext(ProfileContext);
|
const profile = useContext(ProfileContext);
|
||||||
@ -84,22 +86,22 @@ export function useTopicItem(item, hosting, remove) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let message, assets, fontSize, fontColor;
|
let prased, message, assets, fontSize, fontColor;
|
||||||
try {
|
try {
|
||||||
const data = JSON.parse(item.detail.data);
|
parsed = JSON.parse(data);
|
||||||
message = data.text;
|
message = parsed.text;
|
||||||
assets = data.assets;
|
assets = parsed.assets;
|
||||||
if (data.textSize === 'small') {
|
if (parsed.textSize === 'small') {
|
||||||
fontSize = 10;
|
fontSize = 10;
|
||||||
}
|
}
|
||||||
else if (data.textSize === 'large') {
|
else if (parsed.textSize === 'large') {
|
||||||
fontSize = 20;
|
fontSize = 20;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fontSize = 14;
|
fontSize = 14;
|
||||||
}
|
}
|
||||||
if (data.textColor) {
|
if (parsed.textColor) {
|
||||||
fontColor = data.textColor;
|
fontColor = parsed.textColor;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fontColor = Colors.text;
|
fontColor = Colors.text;
|
||||||
@ -124,10 +126,10 @@ export function useTopicItem(item, hosting, remove) {
|
|||||||
timestamp = moment(date).format('M/DD/YYYY');
|
timestamp = moment(date).format('M/DD/YYYY');
|
||||||
}
|
}
|
||||||
|
|
||||||
const editable = detail.guid === identity.guid;
|
const editable = detail.guid === identity.guid && parsed;
|
||||||
const deletable = editable || hosting;
|
const deletable = editable || hosting;
|
||||||
|
|
||||||
updateState({ logo, name, known, message, fontSize, fontColor, timestamp, transform, status, assets, deletable, editable });
|
updateState({ logo, name, known, message, fontSize, fontColor, timestamp, transform, status, assets, deletable, editable, editData: parsed, editMessage: message });
|
||||||
}, [card, item]);
|
}, [card, item]);
|
||||||
|
|
||||||
const actions = {
|
const actions = {
|
||||||
@ -148,6 +150,9 @@ export function useTopicItem(item, hosting, remove) {
|
|||||||
hideEdit: () => {
|
hideEdit: () => {
|
||||||
updateState({ editing: false });
|
updateState({ editing: false });
|
||||||
},
|
},
|
||||||
|
setEditMessage: (editMessage) => {
|
||||||
|
updateState({ editMessage });
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
return { state, actions };
|
return { state, actions };
|
||||||
|
@ -55,6 +55,9 @@ export function useConversation() {
|
|||||||
removeTopic: async (topicId) => {
|
removeTopic: async (topicId) => {
|
||||||
await conversation.actions.removeTopic(topicId);
|
await conversation.actions.removeTopic(topicId);
|
||||||
},
|
},
|
||||||
|
updateTopic: async (topicId, data) => {
|
||||||
|
await conversation.actions.setTopicSubject(topicId, data);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
return { state, actions };
|
return { state, actions };
|
||||||
|
Loading…
Reference in New Issue
Block a user