firestore changes (#32)
* fixes * fixes * firestore * cases list refresh added
This commit is contained in:
committed by
GitHub Enterprise
parent
d3dec01a2b
commit
bbbf565132
@@ -33,7 +33,7 @@ const ProtectedRouter = () => {
|
||||
const dispatch = useAppDispatch();
|
||||
|
||||
// Firestore listener hook
|
||||
// useFirestoreUpdates();
|
||||
useFirestoreUpdates();
|
||||
|
||||
if (!deviceId) {
|
||||
getUniqueId().then(id => dispatch(setDeviceId(id)));
|
||||
|
||||
@@ -12,15 +12,19 @@ import {
|
||||
import {ICaseItem} from '../screens/allCases/interface';
|
||||
import {AppDispatch} from '../store/store';
|
||||
|
||||
export const getAllCases = () => (dispatch: AppDispatch) => {
|
||||
export const getAllCases = (stopRefresh?: () => void) => (dispatch: AppDispatch) => {
|
||||
const url = getApiUrl(ApiKeys.ALL_CASES);
|
||||
dispatch(setLoading(true));
|
||||
axiosInstance.get(url).then(response => {
|
||||
dispatch(
|
||||
setCasesListData({allCases: response.data}),
|
||||
);
|
||||
stopRefresh && stopRefresh();
|
||||
dispatch(getAllCaseDetails(response.data));
|
||||
dispatch(getFilters());
|
||||
}).catch(err => {
|
||||
stopRefresh && stopRefresh();
|
||||
console.log(err)
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -24,6 +24,10 @@ const useFirestoreUpdates = () => {
|
||||
const handleCasesUpdate = (
|
||||
querySnapshot: FirebaseFirestoreTypes.QuerySnapshot,
|
||||
) => {
|
||||
// stale data, no pending writes
|
||||
if(querySnapshot.metadata.fromCache) {
|
||||
return;
|
||||
}
|
||||
let newlyAddedCases = 0;
|
||||
const caseUpdates: CaseUpdates[] = [];
|
||||
querySnapshot
|
||||
@@ -41,10 +45,11 @@ const useFirestoreUpdates = () => {
|
||||
if (updateType === FirestoreUpdateTypes.ADDED) {
|
||||
newlyAddedCases++;
|
||||
}
|
||||
console.log(newlyAddedCases)
|
||||
caseUpdates.push({updateType, updatedCaseDetail});
|
||||
},
|
||||
);
|
||||
// dispatch(updateCaseDetailsFirestore({}));
|
||||
dispatch(updateCaseDetailsFirestore({caseUpdates}));
|
||||
if (newlyAddedCases > 0) {
|
||||
toast({
|
||||
type: 'success',
|
||||
@@ -77,7 +82,7 @@ const useFirestoreUpdates = () => {
|
||||
'c495d1db-ee11-4235-84bd-6ab7e9b70e27',
|
||||
currentTask: 'CALLING_TASK',
|
||||
customerInfo: {
|
||||
customerName: 'Tyrion Lannister',
|
||||
customerName: 'Herik',
|
||||
customerReferenceId:
|
||||
'e6d122cb-ca9c-4a16-85c9-7c354efe8c8e',
|
||||
geoLocation:
|
||||
@@ -109,13 +114,13 @@ const useFirestoreUpdates = () => {
|
||||
updatedAt: 1672736996727,
|
||||
});
|
||||
}, 10000);
|
||||
};
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (!isLoggedIn) {
|
||||
return;
|
||||
}
|
||||
// fakeAddCase();
|
||||
fakeAddCase();
|
||||
const casesSubscriber = firestore()
|
||||
.collection('case')
|
||||
// .collection(`users/${user?.referenceId}/case`)
|
||||
|
||||
@@ -215,7 +215,7 @@ const allCasesSlice = createSlice({
|
||||
const {caseUpdates} = action.payload as {
|
||||
caseUpdates: CaseUpdates[];
|
||||
};
|
||||
console.table('firestore case updates', caseUpdates);
|
||||
console.log('firestore case updates', caseUpdates);
|
||||
caseUpdates.forEach(({updateType, updatedCaseDetail}) => {
|
||||
const {
|
||||
updatedAt,
|
||||
@@ -233,15 +233,11 @@ const allCasesSlice = createSlice({
|
||||
if (index !== -1) {
|
||||
state.casesList[index] = {
|
||||
...state.casesList[index],
|
||||
updatedAt,
|
||||
allocatedAt,
|
||||
caseStatus,
|
||||
currentTask,
|
||||
customerInfo,
|
||||
caseReferenceId: id,
|
||||
pinRank: updatedCaseDetail.pinRank || null
|
||||
};
|
||||
}
|
||||
state.caseDetails[id] = updatedCaseDetail;
|
||||
state.caseDetails[id] = {...updatedCaseDetail, isSynced: true};
|
||||
break;
|
||||
}
|
||||
case FirestoreUpdateTypes.ADDED: {
|
||||
@@ -252,10 +248,10 @@ const allCasesSlice = createSlice({
|
||||
caseStatus,
|
||||
currentTask,
|
||||
customerInfo,
|
||||
pinRank: null,
|
||||
pinRank: updatedCaseDetail.pinRank || null
|
||||
};
|
||||
state.casesList.push(caseListItem);
|
||||
state.caseDetails[id] = updatedCaseDetail;
|
||||
state.caseDetails[id] = {...updatedCaseDetail, isSynced: true};
|
||||
toast({type: 'success', text1: ''});
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import React, {useEffect, useMemo, useState} from 'react';
|
||||
import {
|
||||
Modal,
|
||||
RefreshControl,
|
||||
StyleSheet,
|
||||
TouchableOpacity,
|
||||
View,
|
||||
VirtualizedList,
|
||||
} from 'react-native';
|
||||
import {useDispatch, useSelector} from 'react-redux';
|
||||
import Text from '../../../RN-UI-LIB/src/components/Text';
|
||||
import {useSelector} from 'react-redux';
|
||||
import {GenericStyles} from '../../../RN-UI-LIB/src/styles';
|
||||
import {COLORS} from '../../../RN-UI-LIB/src/styles/colors';
|
||||
import {RootState} from '../../store/store';
|
||||
@@ -29,6 +29,8 @@ import TextInput from '../../../RN-UI-LIB/src/components/TextInput';
|
||||
import SearchIcon from '../../../RN-UI-LIB/src/Icons/SearchIcon';
|
||||
import FilterIcon from '../../assets/icons/FilterIcon';
|
||||
import EmptyList from './EmptyList';
|
||||
import {getAllCases} from '../../action/dataActions';
|
||||
import {useAppDispatch} from '../../hooks';
|
||||
|
||||
export const Separator = () => <View style={styles.separator} />;
|
||||
|
||||
@@ -44,8 +46,9 @@ const AllCases = () => {
|
||||
searchQuery,
|
||||
caseDetails,
|
||||
} = useSelector((state: RootState) => state.allCases);
|
||||
const dispatch = useDispatch();
|
||||
const dispatch = useAppDispatch();
|
||||
const [pendingCases, setPendingCases] = useState([]);
|
||||
const [casesListRefreshing, setCasesListRefreshing] = React.useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const filteredList = casesList.filter(caseItem => {
|
||||
@@ -137,6 +140,10 @@ const AllCases = () => {
|
||||
const [showFilterModal, setShowFilterModal] =
|
||||
React.useState<boolean>(false);
|
||||
|
||||
const handleCasesListRefresh = () => {
|
||||
dispatch(getAllCases(() => setCasesListRefreshing(false)));
|
||||
};
|
||||
|
||||
return (
|
||||
<View style={[GenericStyles.fill, GenericStyles.whiteBackground]}>
|
||||
{casesList.length ? (
|
||||
@@ -165,8 +172,14 @@ const AllCases = () => {
|
||||
) : null}
|
||||
<VirtualizedList
|
||||
data={compiledList}
|
||||
contentContainerStyle={{paddingBottom : 48}}
|
||||
contentContainerStyle={{paddingBottom: 48}}
|
||||
initialNumToRender={4}
|
||||
refreshControl={
|
||||
<RefreshControl
|
||||
refreshing={casesListRefreshing}
|
||||
onRefresh={handleCasesListRefresh}
|
||||
/>
|
||||
}
|
||||
renderItem={row => (
|
||||
<CaseItem
|
||||
data={row}
|
||||
|
||||
@@ -1,12 +1,21 @@
|
||||
import React, {useEffect, useMemo} from 'react';
|
||||
import {Modal, SafeAreaView, StyleSheet, TouchableOpacity, View} from 'react-native';
|
||||
import {
|
||||
Modal,
|
||||
StyleSheet,
|
||||
TouchableOpacity,
|
||||
View,
|
||||
} from 'react-native';
|
||||
import Heading from '../../../RN-UI-LIB/src/components/Heading';
|
||||
import Tabs from '../../../RN-UI-LIB/src/components/tabs/Tabs';
|
||||
import Text from '../../../RN-UI-LIB/src/components/Text';
|
||||
import ArrowBackSmallIcon from '../../../RN-UI-LIB/src/Icons/ArrowBackSmallIcon';
|
||||
import AvatarIcon from '../../../RN-UI-LIB/src/Icons/AvatarIcon';
|
||||
import NaviLogoIcon from '../../../RN-UI-LIB/src/Icons/NaviLogoIcon';
|
||||
import {GenericStyles, SCREEN_HEIGHT, SCREEN_WIDTH} from '../../../RN-UI-LIB/src/styles';
|
||||
import {
|
||||
GenericStyles,
|
||||
SCREEN_HEIGHT,
|
||||
SCREEN_WIDTH,
|
||||
} from '../../../RN-UI-LIB/src/styles';
|
||||
import {COLORS} from '../../../RN-UI-LIB/src/styles/colors';
|
||||
import {getAllCases, getFilters} from '../../action/dataActions';
|
||||
import {navigateToScreen} from '../../components/utlis/navigationUtlis';
|
||||
@@ -50,19 +59,24 @@ const LogoActions = () => {
|
||||
};
|
||||
|
||||
const AllCasesMain = () => {
|
||||
const {casesList, newlyPinnedCases, selectedTodoListCount, caseDetails, isOnboarded} = useAppSelector(
|
||||
state => state.allCases,
|
||||
);
|
||||
const completed = casesList.filter(
|
||||
caseData =>{
|
||||
const detail = caseDetails[caseData.caseReferenceId]
|
||||
const {caseStatus} = detail;
|
||||
if(caseStatus === CaseStatuses.CLOSED || caseStatus === CaseStatuses.EXPIRED){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
const {
|
||||
casesList,
|
||||
newlyPinnedCases,
|
||||
selectedTodoListCount,
|
||||
caseDetails,
|
||||
isOnboarded,
|
||||
} = useAppSelector(state => state.allCases);
|
||||
const completed = casesList.filter(caseData => {
|
||||
const detail = caseDetails[caseData.caseReferenceId];
|
||||
const {caseStatus} = detail;
|
||||
if (
|
||||
caseStatus === CaseStatuses.CLOSED ||
|
||||
caseStatus === CaseStatuses.EXPIRED
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
);
|
||||
return false;
|
||||
});
|
||||
const dispatch = useAppDispatch();
|
||||
const tabItems = useMemo(
|
||||
() => [
|
||||
@@ -81,8 +95,7 @@ const AllCasesMain = () => {
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
dispatch(getAllCases());
|
||||
if(!casesList.length){
|
||||
if (!casesList.length) {
|
||||
dispatch(getAllCases());
|
||||
}
|
||||
}, []);
|
||||
@@ -94,7 +107,7 @@ const AllCasesMain = () => {
|
||||
dispatch(updateTemplateData(RealJson));
|
||||
}, []);
|
||||
|
||||
const understand = () => dispatch(setOnboarding())
|
||||
const understand = () => dispatch(setOnboarding());
|
||||
|
||||
return (
|
||||
<View style={GenericStyles.fill}>
|
||||
|
||||
@@ -135,6 +135,7 @@ export interface CaseDetail {
|
||||
context: Context;
|
||||
isSynced: boolean;
|
||||
currentTask: CurrentTask;
|
||||
pinRank?: number | null;
|
||||
caseVerdict: CaseStatuses;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user