Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed issue, chat flickering #49

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions src/features/Core/screens/ChatsScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const ChatsScreen = () => {
const isMounted = useMountedState();
const fleetbase = useFleetbase();
const [channels, setChannels] = useState([]);
const [isCreatingChat, setIsCreatingChat] = useState(false);
const [isLoading, setIsLoading] = useState(false);

useEffect(() => {
Expand Down Expand Up @@ -91,25 +92,20 @@ const ChatsScreen = () => {
</View>
);

if (isLoading) {
return (
<View style={[tailwind('flex flex-1 items-center justify-center bg-gray-800')]}>
<ActivityIndicator size="large" color="#FFFFFF" />
</View>
);
}
return (
<View style={tailwind('w-full h-full bg-gray-800')}>
<View style={tailwind('p-4')}>
<View style={tailwind('flex flex-row items-center justify-center')}>
<TouchableOpacity style={tailwind('flex-1')} onPress={() => navigation.navigate('ChannelScreen')}>
<View style={tailwind('btn bg-gray-900 border border-gray-700')}>
<Text style={tailwind('font-semibold text-gray-50 text-base')}>{translate('Core.ChatsScreen.create-channel')}</Text>
</View>
</TouchableOpacity>
<>
<View style={tailwind('p-4')}>
<View style={tailwind('flex flex-row items-center justify-center')}>
<TouchableOpacity style={tailwind('flex-1')} onPress={() => navigation.navigate('ChannelScreen')}>
<View style={tailwind('btn bg-gray-900 border border-gray-700')}>
<Text style={tailwind('font-semibold text-gray-50 text-base')}>{translate('Core.ChatsScreen.create-channel')}</Text>
</View>
</TouchableOpacity>
</View>
</View>
</View>
<SwipeListView data={channels} renderItem={renderItem} renderHiddenItem={renderHiddenItem} rightOpenValue={-75} />
<SwipeListView data={channels} renderItem={renderItem} renderHiddenItem={renderHiddenItem} rightOpenValue={-75} />
</>
</View>
);
};
Expand Down
6 changes: 3 additions & 3 deletions src/features/Core/screens/IssueScreen.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { faTimes } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-native-fontawesome';
import { IssuePriority, IssueType, Status } from 'constant/Enum';
import { IssuePriority, IssueType, Status, IssueCategory } from 'constant/Enum';
import { useDriver, useFleetbase } from 'hooks';
import React, { useEffect, useState } from 'react';
import { ActivityIndicator, Alert, Keyboard, KeyboardAvoidingView, Pressable, Text, TextInput, TouchableOpacity, View } from 'react-native';
Expand All @@ -19,7 +19,7 @@ const IssueScreen = ({ navigation, route }) => {
const [driverId] = useState(driver.getAttribute('id'));

const [type, setType] = useState(issue.type);
const [categories, setCategories] = useState([]);
const [categories, setCategories] = useState(getIssueCategories('VEHICLE'));
const [category, setCategory] = useState();
const [priority, setPriority] = useState();
const [status, setStatus] = useState();
Expand Down Expand Up @@ -130,7 +130,7 @@ const IssueScreen = ({ navigation, route }) => {
};

const validateInputs = () => {
if (!type || !category || !priority || !status ||!report?.trim()) {
if (!type || !category || !priority || !status || !report?.trim()) {
setError('Please enter a required value.');
return false;
} else if (report.trim().length === 0) {
Expand Down
64 changes: 34 additions & 30 deletions src/features/Core/screens/IssuesScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useEffect, useState } from 'react';
import { FlatList, RefreshControl, Text, TouchableOpacity, View, ActivityIndicator } from 'react-native';
import tailwind from 'tailwind';
import { useNavigation } from '@react-navigation/native';
import { format } from 'date-fns';
import { useDriver, useFleetbase, useMountedState } from 'hooks';
import { getColorCode, translate } from 'utils';

Expand All @@ -12,17 +13,19 @@ const IssuesScreen = () => {
const fleetbase = useFleetbase();
const [issues, setIssueList] = useState([]);
const [isRefreshing, setIsRefreshing] = useState(false);
const [isLoading, setIsLoading] = useState(true);
const [isCreatingIssue, setIsCreatingIssue] = useState(false);
const [isLoading, setIsLoading] = useState(true);

const fetchIssues = async () => {
setIsLoading(true);
setIsLoading(true);
try {
const adapter = fleetbase.getAdapter();
const response = await adapter.get('issues');
setIssueList(response);
const sortedIssues = response.sort((a, b) => new Date(b.created_at) - new Date(a.created_at));
setIssueList(sortedIssues);
} catch (error) {
console.error('Error fetching issue:', error);
setIssueList([]);
setIssueList([]);
} finally {
setIsLoading(false);
}
Expand Down Expand Up @@ -55,6 +58,12 @@ const IssuesScreen = () => {
</Text>
</View>
</View>
<View style={tailwind('flex flex-row items-center justify-between mb-2')}>
<View style={tailwind('flex-1')}>
<Text style={tailwind('text-gray-100 font-semibold')}>{translate('Core.IssueScreen.createdAt')}:</Text>
</View>
<Text style={tailwind('text-gray-100')}>{format(new Date(item.created_at), 'MM/dd/yyyy HH:mm')}</Text>
</View>
<View style={tailwind('flex flex-row items-center justify-between mb-2')}>
<View style={tailwind('flex-1')}>
<Text style={tailwind('text-gray-100 font-semibold')}>{translate('Core.IssueScreen.driverName')}:</Text>
Expand All @@ -75,14 +84,6 @@ const IssuesScreen = () => {
</View>
);

if (isLoading) {
return (
<View style={[tailwind('flex flex-1 items-center justify-center bg-gray-800')]}>
<ActivityIndicator size="large" color="#FFFFFF" />
</View>
);
}

return (
<View style={tailwind('w-full h-full bg-gray-800 flex-grow')}>
<View style={tailwind('flex flex-row items-center justify-between px-4 py-2')}>
Expand All @@ -91,25 +92,28 @@ const IssuesScreen = () => {
</View>
</View>

<FlatList
refreshControl={<RefreshControl refreshing={isRefreshing} onRefresh={fetchIssues} tintColor={getColorCode('text-blue-200')} />}
data={issues}
keyExtractor={item => item.id}
renderItem={renderItem}
/>
<View style={tailwind('p-4')}>
<View style={tailwind('flex flex-row items-center justify-center')}>
<TouchableOpacity
style={tailwind('flex-1')}
onPress={() => {
navigation.navigate('IssueScreen');
}}>
<View style={tailwind('btn bg-gray-900 border border-gray-700')}>
<Text style={tailwind('font-semibold text-gray-50 text-base')}>{translate('Core.IssueScreen.createIssue')}</Text>
</View>
</TouchableOpacity>
<>
<FlatList
refreshControl={<RefreshControl refreshing={isRefreshing} onRefresh={fetchIssues} tintColor={getColorCode('text-blue-200')} />}
data={issues}
keyExtractor={item => item.id}
renderItem={renderItem}
/>
<View style={tailwind('p-4')}>
<View style={tailwind('flex flex-row items-center justify-center')}>
<TouchableOpacity
style={tailwind('flex-1')}
onPress={() => {
setIsCreatingIssue(true);
navigation.navigate('IssueScreen');
}}>
<View style={tailwind('btn bg-gray-900 border border-gray-700')}>
<Text style={tailwind('font-semibold text-gray-50 text-base')}>{translate('Core.IssueScreen.createIssue')}</Text>
</View>
</TouchableOpacity>
</View>
</View>
</View>
</>
</View>
);
};
Expand Down
3 changes: 2 additions & 1 deletion translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
"updateIssue": "Update Issue",
"report": "Report",
"driverName": "Driver Name",
"vehicleName": "Vehicle Name"
"vehicleName": "Vehicle Name",
"createdAt": "Created Date"
},
"ChannelScreen": {
"name": "Name",
Expand Down
Loading