support removing channel

This commit is contained in:
balzack 2022-10-09 23:55:08 -07:00
parent 1c05a8487c
commit f95265e688
6 changed files with 43 additions and 11 deletions

View File

@ -494,7 +494,7 @@ export function useCardContext() {
}, },
removeChannel: async (cardId, channelId) => { removeChannel: async (cardId, channelId) => {
const { detail, profile } = getCard(cardId); const { detail, profile } = getCard(cardId);
return await removeChannel(profile.node, `${profile.guid}.${detail.token}`, channelId); return await removeContactChannel(profile.node, `${profile.guid}.${detail.token}`, channelId);
}, },
removeChannelTopic: async (cardId, channelId, topicId) => { removeChannelTopic: async (cardId, channelId, topicId) => {
const { detail, profile } = getCard(cardId); const { detail, profile } = getCard(cardId);

View File

@ -94,7 +94,6 @@ export function useChannelContext() {
const { server, appToken, guid } = session.current; const { server, appToken, guid } = session.current;
const delta = await getChannels(server, appToken, setRevision.current); const delta = await getChannels(server, appToken, setRevision.current);
console.log("DELTA", delta);
for (let channel of delta) { for (let channel of delta) {
if (channel.data) { if (channel.data) {
if (channel.data.channelDetail && channel.data.channelSummary) { if (channel.data.channelDetail && channel.data.channelSummary) {

View File

@ -351,6 +351,12 @@ export function useConversationContext() {
await channel.actions.setSubject(channelId, subject); await channel.actions.setSubject(channelId, subject);
} }
}, },
remove: async () => {
if (conversationId.current) {
const { cardId, channelId } = conversationId.current;
await remove(cardId, channelId);
}
},
} }
return { state, actions } return { state, actions }

View File

@ -28,13 +28,27 @@ export function DetailsBody({ channel, clearConversation }) {
} }
} }
const remove = async () => {
try {
await actions.remove();
clearConversation();
}
catch (err) {
console.log(err);
Alert.alert(
'Failed to Delete Topic',
'Please try again.'
)
}
}
return ( return (
<View style={styles.body}> <View style={styles.body}>
<View style={styles.details}> <View style={styles.details}>
<Logo src={state.logo} width={72} height={72} radius={8} /> <Logo src={state.logo} width={72} height={72} radius={8} />
<View style={styles.info}> <View style={styles.info}>
<TouchableOpacity style={styles.subject} onPress={actions.showEditSubject}> <TouchableOpacity style={styles.subject} onPress={actions.showEditSubject}>
<Text style={styles.subject}>{ state.subject }</Text> <Text style={styles.subjectText} numberOfLines={1} ellipsizeMode={'tail'}>{ state.subject }</Text>
{ !state.hostId && ( { !state.hostId && (
<Ionicons name="edit" size={16} color={Colors.text} /> <Ionicons name="edit" size={16} color={Colors.text} />
)} )}
@ -46,7 +60,7 @@ export function DetailsBody({ channel, clearConversation }) {
<View style={styles.controls}> <View style={styles.controls}>
{ !state.hostId && ( { !state.hostId && (
<TouchableOpacity style={styles.button}> <TouchableOpacity style={styles.button} onPress={remove}>
<Text style={styles.buttonText}>Delete Topic</Text> <Text style={styles.buttonText}>Delete Topic</Text>
</TouchableOpacity> </TouchableOpacity>
)} )}
@ -56,7 +70,7 @@ export function DetailsBody({ channel, clearConversation }) {
</TouchableOpacity> </TouchableOpacity>
)} )}
{ state.hostId && ( { state.hostId && (
<TouchableOpacity style={styles.button}> <TouchableOpacity style={styles.button} onPress={remove}>
<Text style={styles.buttonText}>Leave Topic</Text> <Text style={styles.buttonText}>Leave Topic</Text>
</TouchableOpacity> </TouchableOpacity>
)} )}
@ -108,7 +122,6 @@ export function DetailsBody({ channel, clearConversation }) {
export function Details({ channel, clearConversation }) { export function Details({ channel, clearConversation }) {
return ( return (
<View> <View>
<Text>DETAILS</Text>
<DetailsBody channel={channel} clearConversation={clearConversation} /> <DetailsBody channel={channel} clearConversation={clearConversation} />
</View> </View>
) )

View File

@ -2,16 +2,25 @@ import { StyleSheet } from 'react-native';
import { Colors } from 'constants/Colors'; import { Colors } from 'constants/Colors';
export const styles = StyleSheet.create({ export const styles = StyleSheet.create({
body: {
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
},
details: { details: {
display: 'flex', display: 'flex',
flexDirection: 'row', flexDirection: 'row',
justifyContent: 'center', justifyContent: 'center',
paddingTop: 16, paddingTop: 16,
flexShrink: 1,
minWidth: 0,
}, },
info: { info: {
paddingLeft: 8, paddingLeft: 8,
display: 'flex', display: 'flex',
flexDirection: 'column', flexDirection: 'column',
minWidth: 0,
flexShrink: 1,
}, },
subject: { subject: {
fontSize: 18, fontSize: 18,
@ -20,6 +29,13 @@ export const styles = StyleSheet.create({
paddingRight: 8, paddingRight: 8,
color: Colors.text, color: Colors.text,
alignItems: 'center', alignItems: 'center',
minWidth: 0,
flexShrink: 1,
},
subjectText: {
fontSize: 18,
flexShrink: 1,
minWidth: 0,
}, },
created: { created: {
fontSize: 16, fontSize: 16,
@ -32,11 +48,6 @@ export const styles = StyleSheet.create({
title: { title: {
fontSize: 20, fontSize: 20,
}, },
body: {
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
},
controls: { controls: {
paddingTop: 16, paddingTop: 16,
}, },

View File

@ -40,6 +40,9 @@ export function useDetails() {
saveSubject: async () => { saveSubject: async () => {
await conversation.actions.setSubject(state.subjectUpdate); await conversation.actions.setSubject(state.subjectUpdate);
}, },
remove: async () => {
await conversation.actions.remove();
},
}; };
return { state, actions }; return { state, actions };