Skip to content

Commit

Permalink
fixed type
Browse files Browse the repository at this point in the history
  • Loading branch information
doljko committed Mar 28, 2024
1 parent dc2ad44 commit 0577385
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 47 deletions.
54 changes: 9 additions & 45 deletions App.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { EventRegister } from 'react-native-event-listeners';
import tailwind from 'tailwind';
import { useDriver } from 'utils/Auth';
import { getString, setString } from 'utils/Storage';
import { config, isArray, capitalize } from './src/utils';
import { config, isArray, capitalize, logError } from './src/utils';
import { useNetInfo } from '@react-native-community/netinfo';
import CoreStack from './src/features/Core/CoreStack';

Expand All @@ -34,11 +34,11 @@ const App: () => Node = () => {
const navigationRef = useRef();
const [isLoading, setLoading] = useState(true);
const fleetbase = useFleetbase();
const { isConnected } = useNetInfo();
const { type, isConnected, isInternetReachable } = useNetInfo();

useEffect(() => {
const apiRequestQueue = JSON.parse(getString('apiRequestQueue'));
console.log('apiRequestQueue:::', JSON.stringify(apiRequestQueue));
console.log('#apiRequestQueue', JSON.stringify(apiRequestQueue));
if (!isConnected || !isArray(apiRequestQueue) || apiRequestQueue.length === 0) {
return;
}
Expand All @@ -50,15 +50,12 @@ const App: () => Node = () => {
});
}

console.log('apiRequestQueue initial:::::', JSON.stringify(apiRequestQueue));

const adapter = fleetbase.getAdapter();
const adapterMethods = ['get', 'put', 'patch', 'post', 'delete'];

const trackSuccess = response => {
console.log('#trackSuccess is it an order?', response instanceof Order);
if (response instanceof Order) {
emit('order.synced', order);
emit('order.synced', response);
}
};

Expand All @@ -69,12 +66,14 @@ const App: () => Node = () => {
adapter[method](endpoint, params).then(trackSuccess);
continue;
}
console.log(JSON.stringify({ method, resourceType, endpoint, params }));
console.log('#queuedApiRequest', JSON.stringify({ method, resourceType, endpoint, params }));
const resourceInstance = lookup('resource', capitalize(resourceType), resource, fleetbase.getAdapter());
console.log('#resourceInstance', resourceInstance);
console.log('#resourceInstance', JSON.stringify(resourceInstance));
if (resourceInstance) {
console.log('#resourceInstance ID', resourceInstance.id);
console.log('#resourceInstance method', method, typeof resourceInstance[method]);
if (typeof resourceInstance[method] === 'function') {
resourceInstance[method](params).then(trackSuccess);
resourceInstance[method](params).then(trackSuccess).catch(logError);
}
continue;
}
Expand All @@ -83,41 +82,6 @@ const App: () => Node = () => {
setString('apiRequestQueue', JSON.stringify([]));
}, [isConnected]);

const updateOrder = (order, index) => {
order
.updateActivity({ skipDispatch: true })
.then(res => {
Toast.show({
type: 'success',
text1: `Activity synced.`,
});
success.push(index);
console.log('Order updated------->', res);
})
.catch(err => {
console.error('Order update error------->', err);
});
};

const startOrder = (order, index) => {
order
.start({ skipDispatch: true })
.then(res => {
Toast.show({
type: 'success',
text1: `Activity synced.`,
});
success.push(index);
console.log('Sync sucess: ', res);
})
.catch(error => {
console.log('startOrder error----->', error);
if (error.message.includes('already started')) {
success.push(index);
}
});
};

const parseDeepLinkUrl = useCallback(url => {
const urlParts = url.split('?');
if (urlParts.length > 1) {
Expand Down
3 changes: 1 addition & 2 deletions src/features/Shared/OrderScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ const OrderScreen = ({ navigation, route }) => {

const addToRequestQueue = ({ method, params, resource, resourceType, endpoint }) => {
let apiRequestQueue = JSON.parse(getString('apiRequestQueue'));
console.log('Order::::', JSON.stringify(apiRequestQueue));
if (isArray(apiRequestQueue)) {
apiRequestQueue.push({ method, params, resource, resourceType, endpoint });
} else {
Expand Down Expand Up @@ -287,7 +286,7 @@ const OrderScreen = ({ navigation, route }) => {
setActionSheetAction('update_activity');

if (!isConnected) {
addToRequestQueue({ method: 'updateOrder', params: { skipDispatch: true }, resouce: order.serialize(), resourceType: 'Order' });
addToRequestQueue({ method: 'updateActivity', params: { skipDispatch: true }, resource: order.serialize(), resourceType: 'Order' });
setIsLoadingAction(false);
return;
}
Expand Down

0 comments on commit 0577385

Please sign in to comment.