mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
supporting message delete
This commit is contained in:
parent
3ce3711bd4
commit
267a54e782
@ -357,6 +357,19 @@ export function useConversationContext() {
|
|||||||
await remove(cardId, channelId);
|
await remove(cardId, channelId);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
removeTopic: async (topicId) => {
|
||||||
|
if (conversationId.current) {
|
||||||
|
const { cardId, channelId } = conversationId.current;
|
||||||
|
if (cardId) {
|
||||||
|
await card.actions.removeChannelTopic(cardId, channelId, topicId);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
await channel.actions.removeTopic(channelId, topicId);
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
@ -59,7 +59,8 @@ export function ConversationBody() {
|
|||||||
maintainVisibleContentPosition={ state.latched ? null : { minIndexForVisibile: 2, } }
|
maintainVisibleContentPosition={ state.latched ? null : { minIndexForVisibile: 2, } }
|
||||||
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} />}
|
||||||
keyExtractor={item => item.topicId}
|
keyExtractor={item => item.topicId}
|
||||||
/>
|
/>
|
||||||
<View>
|
<View>
|
||||||
|
@ -50,7 +50,6 @@ export const styles = StyleSheet.create({
|
|||||||
},
|
},
|
||||||
topics: {
|
topics: {
|
||||||
paddingBottom: 32,
|
paddingBottom: 32,
|
||||||
paddingTop: 8,
|
|
||||||
},
|
},
|
||||||
conversation: {
|
conversation: {
|
||||||
flexShrink: 1,
|
flexShrink: 1,
|
||||||
|
@ -7,6 +7,7 @@ export const styles = StyleSheet.create({
|
|||||||
borderColor: Colors.divider,
|
borderColor: Colors.divider,
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
flexDirection: 'column',
|
flexDirection: 'column',
|
||||||
|
marginTop: 8,
|
||||||
},
|
},
|
||||||
addButtons: {
|
addButtons: {
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { FlatList, View, Text, Modal, Image } from 'react-native';
|
import { FlatList, View, Text, 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,10 +16,63 @@ 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 }) {
|
export function TopicItem({ item, focused, focus, hosting, remove }) {
|
||||||
|
|
||||||
const { state, actions } = useTopicItem(item, hosting);
|
const { state, actions } = useTopicItem(item, hosting);
|
||||||
|
|
||||||
|
const erase = () => {
|
||||||
|
Alert.alert(
|
||||||
|
"Removing Message",
|
||||||
|
"Confirm?",
|
||||||
|
[
|
||||||
|
{ text: "Cancel",
|
||||||
|
onPress: () => {},
|
||||||
|
},
|
||||||
|
{ text: "Remove",
|
||||||
|
onPress: async () => {
|
||||||
|
try {
|
||||||
|
await remove(item.topicId);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
Alert.alert(
|
||||||
|
'Failed to Remove Message',
|
||||||
|
'Please try again.'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const block = () => {
|
||||||
|
Alert.alert(
|
||||||
|
"Blocking Message",
|
||||||
|
"Confirm?",
|
||||||
|
[
|
||||||
|
{ text: "Cancel",
|
||||||
|
onPress: () => {},
|
||||||
|
},
|
||||||
|
{ text: "Block",
|
||||||
|
onPress: async () => {
|
||||||
|
try {
|
||||||
|
await actions.block();
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
Alert.alert(
|
||||||
|
'Failed to Block Message',
|
||||||
|
'Please try again.'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const renderAsset = (asset) => {
|
const renderAsset = (asset) => {
|
||||||
return (
|
return (
|
||||||
<View style={styles.frame}>
|
<View style={styles.frame}>
|
||||||
@ -113,22 +166,36 @@ export function TopicItem({ item, focused, focus, hosting }) {
|
|||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
<Modal
|
||||||
|
animationType="fade"
|
||||||
|
transparent={true}
|
||||||
|
visible={state.editing}
|
||||||
|
supportedOrientations={['portrait', 'landscape']}
|
||||||
|
onRequestClose={actions.hideEdit}
|
||||||
|
>
|
||||||
|
<View style={styles.modal}>
|
||||||
|
<TouchableOpacity style={{ backgroundColor: 'white' }} onPress={actions.hideEdit}>
|
||||||
|
<Text>DONE</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
</View>
|
||||||
|
</Modal>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
{ focused && (
|
{ focused && (
|
||||||
<View style={styles.focused}>
|
<View style={styles.focused}>
|
||||||
{ state.deletable && (
|
|
||||||
<TouchableOpacity style={styles.icon}>
|
|
||||||
<MatIcons name="delete-outline" size={20} color={Colors.white} />
|
|
||||||
</TouchableOpacity>
|
|
||||||
)}
|
|
||||||
{ state.editable && (
|
{ state.editable && (
|
||||||
<TouchableOpacity style={styles.icon}>
|
<TouchableOpacity style={styles.icon} onPress={actions.showEdit}>
|
||||||
<MatIcons name="pencil-outline" size={20} color={Colors.white} />
|
<AntIcons name="edit" size={24} color={Colors.white} />
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
)}
|
)}
|
||||||
<TouchableOpacity style={styles.icon}>
|
<TouchableOpacity style={styles.icon} onPress={block}>
|
||||||
<MatIcons name="block-helper" size={18} color={Colors.white} />
|
<MatIcons name="block-helper" size={18} color={Colors.white} />
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
|
{ state.deletable && (
|
||||||
|
<TouchableOpacity style={styles.icon} onPress={erase}>
|
||||||
|
<MatIcons name="delete-outline" size={24} color={Colors.white} />
|
||||||
|
</TouchableOpacity>
|
||||||
|
)}
|
||||||
|
|
||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
</View>
|
</View>
|
||||||
|
@ -33,6 +33,9 @@ export const styles = StyleSheet.create({
|
|||||||
width: '100%',
|
width: '100%',
|
||||||
height: '100%',
|
height: '100%',
|
||||||
backgroundColor: 'rgba(0, 0, 0, 0.9)',
|
backgroundColor: 'rgba(0, 0, 0, 0.9)',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
},
|
},
|
||||||
frame: {
|
frame: {
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
@ -56,6 +59,7 @@ export const styles = StyleSheet.create({
|
|||||||
borderRadius: 4,
|
borderRadius: 4,
|
||||||
paddingLeft: 8,
|
paddingLeft: 8,
|
||||||
paddingRight: 8,
|
paddingRight: 8,
|
||||||
|
alignItems: 'center',
|
||||||
},
|
},
|
||||||
icon: {
|
icon: {
|
||||||
paddingLeft: 8,
|
paddingLeft: 8,
|
||||||
|
@ -5,7 +5,7 @@ import moment from 'moment';
|
|||||||
import { useWindowDimensions } from 'react-native';
|
import { useWindowDimensions } from 'react-native';
|
||||||
import Colors from 'constants/Colors';
|
import Colors from 'constants/Colors';
|
||||||
|
|
||||||
export function useTopicItem(item, hosting) {
|
export function useTopicItem(item, hosting, remove) {
|
||||||
|
|
||||||
const [state, setState] = useState({
|
const [state, setState] = useState({
|
||||||
name: null,
|
name: null,
|
||||||
@ -22,6 +22,7 @@ export function useTopicItem(item, hosting) {
|
|||||||
fontColor: Colors.text,
|
fontColor: Colors.text,
|
||||||
editable: false,
|
editable: false,
|
||||||
deletable: false,
|
deletable: false,
|
||||||
|
editing: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const profile = useContext(ProfileContext);
|
const profile = useContext(ProfileContext);
|
||||||
@ -139,6 +140,14 @@ export function useTopicItem(item, hosting) {
|
|||||||
setActive: (activeId) => {
|
setActive: (activeId) => {
|
||||||
updateState({ activeId });
|
updateState({ activeId });
|
||||||
},
|
},
|
||||||
|
block: async () => {
|
||||||
|
},
|
||||||
|
showEdit: () => {
|
||||||
|
updateState({ editing: true });
|
||||||
|
},
|
||||||
|
hideEdit: () => {
|
||||||
|
updateState({ editing: false });
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
return { state, actions };
|
return { state, actions };
|
||||||
|
@ -52,6 +52,9 @@ export function useConversation() {
|
|||||||
setFocus: (focus) => {
|
setFocus: (focus) => {
|
||||||
updateState({ focus });
|
updateState({ focus });
|
||||||
},
|
},
|
||||||
|
removeTopic: async (topicId) => {
|
||||||
|
await conversation.actions.removeTopic(topicId);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
return { state, actions };
|
return { state, actions };
|
||||||
|
Loading…
Reference in New Issue
Block a user