Skip to content

Commit

Permalink
fixed update, create func
Browse files Browse the repository at this point in the history
  • Loading branch information
doljko committed Apr 16, 2024
1 parent 8206954 commit 1ef9e1e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 24 deletions.
27 changes: 16 additions & 11 deletions src/features/Core/screens/ChannelScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,27 @@ const ChannelScreen = ({ route }) => {
const [channelId, setChannelId] = useState();

useEffect(() => {
if (route?.params?.channel) {
const { channel } = route.params;
setChannelId(channel.id);
console.log('channel.id:::', channel.id);
setName(channel.name);
if (route?.params) {
const { data } = route.params;
setChannelId(data?.id);
setName(data?.name);
}
}, [route]);

const saveChannel = () => {
const adapter = fleetbase.getAdapter();
const data = { name };
if (channelId) {
return adapter
.put(`chat-channels/${channelId}`, name)
.put(`chat-channels/${channelId}`, data)
.then(res => {
navigation.navigate('ChatScreen', { data: res });
})
.catch(logError)
.finally(() => setIsLoading(false));
} else {
return adapter
.post('chat-channels', name)
.post('chat-channels', { name })
.then(res => {
navigation.navigate('ChatScreen', { data: res });
})
Expand All @@ -47,8 +48,8 @@ const ChannelScreen = ({ route }) => {
<View style={[tailwind('w-full h-full bg-gray-800')]}>
<Pressable onPress={Keyboard.dismiss} style={tailwind('w-full h-full relative')}>
<View style={tailwind('flex flex-row items-center justify-between p-4')}>
<Text style={tailwind('text-xl text-gray-50 font-semibold')}>{translate('Core.ChannelScreen.title')}</Text>
<TouchableOpacity onPress={() => navigation.goBack()} style={tailwind('mr-4')}>
<Text style={tailwind('text-xl text-gray-50 font-semibold')}>{channelId ? translate('Core.ChannelScreen.update-channel') : translate('Core.ChannelScreen.title')}</Text>
<TouchableOpacity onPress={() => navigation.navigate('ChatsScreen')} style={tailwind('mr-4')}>
<View style={tailwind('rounded-full bg-gray-900 w-10 h-10 flex items-center justify-center')}>
<FontAwesomeIcon icon={faTimes} style={tailwind('text-red-400')} />
</View>
Expand All @@ -57,7 +58,9 @@ const ChannelScreen = ({ route }) => {
<View style={tailwind('flex w-full h-full')}>
<KeyboardAvoidingView style={tailwind('p-4')}>
<View style={tailwind('mb-4')}>
<Text style={tailwind('font-semibold text-base text-gray-50 mb-2')}>{translate('Core.ChannelScreen.name')}</Text>
<Text style={tailwind('font-semibold text-base text-gray-50 mb-2')}>
{channelId ? translate('Core.ChannelScreen.update') : translate('Core.ChannelScreen.name')}
</Text>
<TextInput
value={name}
onChangeText={setName}
Expand All @@ -71,7 +74,9 @@ const ChannelScreen = ({ route }) => {
<TouchableOpacity onPress={saveChannel} disabled={isLoading}>
<View style={tailwind('btn bg-gray-900 border border-gray-700 mt-4')}>
{isLoading && <ActivityIndicator color={getColorCode('text-gray-50')} style={tailwind('mr-2')} />}
<Text style={tailwind('font-semibold text-lg text-gray-50 text-center')}>{translate('Core.ChannelScreen.title')}</Text>
<Text style={tailwind('font-semibold text-lg text-gray-50 text-center')}>
{channelId ? translate('Core.ChannelScreen.update-channel') : translate('Core.ChannelScreen.title')}
</Text>
</View>
</TouchableOpacity>
</KeyboardAvoidingView>
Expand Down
20 changes: 9 additions & 11 deletions src/features/Core/screens/ChatScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import { Actions, Bubble, GiftedChat, InputToolbar, Send } from 'react-native-gi
import { tailwind } from 'tailwind';

const ChatScreen = ({ route }) => {
const { data, channelData } = route.params;

const { data, itemData } = route.params;
const fleetbase = useFleetbase();
const getUser = useFleetbase('int/v1');
const navigation = useNavigation();
Expand All @@ -22,7 +21,6 @@ const ChatScreen = ({ route }) => {
try {
const adapter = getUser.getAdapter();
const response = await adapter.get('users');
console.log('user::::', JSON.stringify(response.users));
setUsers(response.users);
return response;
} catch (error) {
Expand All @@ -36,14 +34,14 @@ const ChatScreen = ({ route }) => {
}, []);

const toggleUserList = () => {
setShowUserList(!showUserList); // Toggle the user list visibility
setShowUserList(!showUserList);
};

const addParticipant = async id => {
const addParticipant = async participantId => {
try {
// const adapter = fleetbase.getAdapter();
// const res = await adapter.post(`chat-channels/${id}/add-participant`);
// console.log('res:::', JSON.stringify(res));
const adapter = fleetbase.getAdapter();
const res = await adapter.post(`chat-channels/${participantId}/add-participant`);
console.log('res:::', JSON.stringify(res));
setShowUserList(false);
} catch (error) {
console.error('Add participant:', error);
Expand Down Expand Up @@ -156,9 +154,9 @@ const ChatScreen = ({ route }) => {
</TouchableOpacity>
<View style={tailwind('flex flex-row items-center')}>
<Text style={tailwind('text-sm text-gray-600 w-72 text-center')}>
{'name '}
<TouchableOpacity style={tailwind('rounded-full')} onPress={() => navigation.navigate('ChannelScreen')}>
<FontAwesomeIcon size={15} icon={faEdit} style={tailwind('text-blue-500')} />
{itemData?.name || data.name}{' '}
<TouchableOpacity style={tailwind('rounded-full ')} onPress={() => navigation.navigate('ChannelScreen', { data: itemData })}>
<FontAwesomeIcon size={18} icon={faEdit} style={tailwind('text-blue-500 mt-1')} />
</TouchableOpacity>
</Text>
</View>
Expand Down
2 changes: 1 addition & 1 deletion src/features/Core/screens/ChatsScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const ChatsScreen = () => {
};

const renderItem = ({ item }) => (
<TouchableOpacity style={tailwind('flex flex-row bg-gray-900 mt-2 p-2 mx-2')} onPress={() => navigation.navigate('ChatScreen')}>
<TouchableOpacity style={tailwind('flex flex-row bg-gray-900 mt-2 p-2 mx-2')} onPress={() => navigation.navigate('ChatScreen', { itemData: item })}>
<View style={tailwind('p-2')}>
<FastImage
source={item.participants.avatar_url ? { uri: item.participants.avatar_url } : require('../../../../assets/icon.png')}
Expand Down
4 changes: 3 additions & 1 deletion translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@
},
"ChannelScreen": {
"name": "Name",
"title":"Create channel"
"title":"Create channel",
"update": "Update",
"update-channel":"Update channel"
}
},
"Exceptions": {
Expand Down

0 comments on commit 1ef9e1e

Please sign in to comment.