Skip to content

Commit

Permalink
fix: 🐛 fix lib and update onRefresh func
Browse files Browse the repository at this point in the history
  • Loading branch information
yeukfei02 committed Jul 9, 2022
1 parent af878ae commit 85365cd
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 65 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"expo-constants": "~13.1.1",
"expo-file-system": "~14.0.0",
"expo-location": "~14.2.2",
"expo-updates": "~0.13.2",
"expo-updates": "~0.13.3",
"graphql": "^15.4.0",
"lodash": "^4.17.20",
"moment": "^2.29.1",
Expand Down
6 changes: 3 additions & 3 deletions src/components/busArrivalDetails/BusArrivalDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ function BusArrivalDetails(props: any): JSX.Element {
}, []);

useEffect(() => {
if (route.params) {
if (!responseData && route.params) {
const busStopCode = (route.params as any).busStopCode;
getBusArrival({
variables: { busStopCode: busStopCode },
});
}
}, [route.params]);
}, [responseData, route.params]);

useEffect(() => {
if (data) {
Expand Down Expand Up @@ -329,7 +329,7 @@ function BusArrivalDetails(props: any): JSX.Element {
});
}

if (!loading) {
if (data) {
setRefreshing(false);
}
};
Expand Down
6 changes: 3 additions & 3 deletions src/components/busServiceRoutes/BusServiceRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ function BusServiceRoutes(props: any): JSX.Element {
}, []);

useEffect(() => {
if (route.params) {
if (!responseData && route.params) {
const busServiceNo = (route.params as any).busServiceNo;
getBusRouteByBusServiceNo({
variables: { busServiceNo: busServiceNo },
});
}
}, [route.params]);
}, [responseData, route.params]);

useEffect(() => {
if (data) {
Expand Down Expand Up @@ -130,7 +130,7 @@ function BusServiceRoutes(props: any): JSX.Element {
});
}

if (!loading) {
if (data) {
setRefreshing(false);
}
};
Expand Down
90 changes: 43 additions & 47 deletions src/components/favourites/Favourites.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ function Favourites(props: any): JSX.Element {
}, []);

useEffect(() => {
if (Constants.installationId) {
if (!responseData && Constants.installationId) {
getFavouritesByInstallationId({
variables: {
installationId: Constants.installationId,
},
});
}
}, [Constants.installationId]);
}, [responseData, Constants.installationId]);

useEffect(() => {
if (data) {
Expand All @@ -123,16 +123,14 @@ function Favourites(props: any): JSX.Element {
}, [data]);

useEffect(() => {
if (deleteFavouritesResult.data) {
if (deleteFavouritesResult.data.deleteFavouritesById.status) {
setResponseData(null);
deleteFavouritesResult.client.clearStore();
getFavouritesByInstallationId({
variables: {
installationId: Constants.installationId,
},
});
}
if (deleteFavouritesResult.data && deleteFavouritesResult.data.deleteFavouritesById.status) {
setResponseData(null);
deleteFavouritesResult.client.clearStore();
getFavouritesByInstallationId({
variables: {
installationId: Constants.installationId,
},
});
}
}, [deleteFavouritesResult.data]);

Expand Down Expand Up @@ -164,44 +162,42 @@ function Favourites(props: any): JSX.Element {
</View>
);
} else {
if (responseData) {
if (responseData.getFavouritesByInstallationId) {
favouritesListDiv = responseData.getFavouritesByInstallationId.map((element: any, i: number) => {
const item = element.item;

return (
<View key={i} style={styles.favouritesResultContainer}>
<View style={{ alignSelf: 'flex-end' }}>
<TouchableOpacity onPress={() => handleDeleteButtonClick(element.id)}>
<MaterialIcons name="delete" size={30} color="black" />
</TouchableOpacity>
</View>

<Text style={styles.favouritesResultDescriptionText}>{item.description}</Text>
<Text style={styles.favouritesResultRoadNameText}>{item.road_name}</Text>

<TouchableOpacity
style={{ marginVertical: 5 }}
onPress={() => handleBusStopCodeClick(item.bus_stop_code)}
>
<Text style={{ fontSize: 22, color: 'red', textDecorationLine: 'underline' }}>
{item.bus_stop_code}
</Text>
if (responseData && responseData.getFavouritesByInstallationId) {
favouritesListDiv = responseData.getFavouritesByInstallationId.map((element: any, i: number) => {
const item = element.item;

return (
<View key={i} style={styles.favouritesResultContainer}>
<View style={{ alignSelf: 'flex-end' }}>
<TouchableOpacity onPress={() => handleDeleteButtonClick(element.id)}>
<MaterialIcons name="delete" size={30} color="black" />
</TouchableOpacity>
</View>

<View style={{ alignSelf: 'flex-start', marginVertical: 10 }}>
<TouchableOpacity onPress={() => handleOpenInMap(item.latitude, item.longitude)}>
<Text style={{ color: 'blue', textDecorationLine: 'underline' }}>Open in map</Text>
</TouchableOpacity>
</View>
<Text style={styles.favouritesResultDescriptionText}>{item.description}</Text>
<Text style={styles.favouritesResultRoadNameText}>{item.road_name}</Text>

<TouchableOpacity
style={{ marginVertical: 5 }}
onPress={() => handleBusStopCodeClick(item.bus_stop_code)}
>
<Text style={{ fontSize: 22, color: 'red', textDecorationLine: 'underline' }}>
{item.bus_stop_code}
</Text>
</TouchableOpacity>

<View style={{ alignSelf: 'flex-start', marginVertical: 10 }}>
<TouchableOpacity onPress={() => handleOpenInMap(item.latitude, item.longitude)}>
<Text style={{ color: 'blue', textDecorationLine: 'underline' }}>Open in map</Text>
</TouchableOpacity>
</View>

<View style={{ alignSelf: 'flex-start', marginTop: 5 }}>
<MaterialIcons name="favorite" size={30} color="tomato" />
</View>
<View style={{ alignSelf: 'flex-start', marginTop: 5 }}>
<MaterialIcons name="favorite" size={30} color="tomato" />
</View>
);
});
}
</View>
);
});
}
}
}
Expand Down Expand Up @@ -247,7 +243,7 @@ function Favourites(props: any): JSX.Element {
},
});

if (!loading) {
if (data) {
setRefreshing(false);
}
};
Expand Down
5 changes: 1 addition & 4 deletions src/components/nearMe/NearMe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,8 @@ function NearMe(props: any): JSX.Element {
setPageNumber(1);
client?.clearStore();
setResponseData(null);
// getBusStopByLatLong({
// variables: { latitude: latitude, longitude: longitude, pageNumber: pageNumber },
// });

if (!loading) {
if (data) {
setRefreshing(false);
}
};
Expand Down
11 changes: 8 additions & 3 deletions src/components/search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ function Search(props: any): JSX.Element {
setRecordData(null);
setRecord2Data(null);
setRecord3Data(null);
setRecord4Data(null);

setRoadName(text);
};
Expand All @@ -256,6 +257,7 @@ function Search(props: any): JSX.Element {
setRecordData(null);
setRecord2Data(null);
setRecord3Data(null);
setRecord4Data(null);

setPlaceName(text);
};
Expand All @@ -264,6 +266,7 @@ function Search(props: any): JSX.Element {
setRecordData(null);
setRecord2Data(null);
setRecord3Data(null);
setRecord4Data(null);

setBusStopCode(text);
};
Expand Down Expand Up @@ -517,11 +520,13 @@ function Search(props: any): JSX.Element {
setRecordData(null);
setRecord2Data(null);
setRecord3Data(null);
setRecord4Data(null);

if (
!getBusStopByRoadNameResult.loading &&
!getBusStopByDescriptionResult.loading &&
!getBusStopByBusStopCodeResult.loading
!getBusStopByRoadNameResult.loading ||
!getBusStopByDescriptionResult.loading ||
!getBusStopByBusStopCodeResult.loading ||
!getAllBusServiceResult.loading
) {
setRefreshing(false);
}
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4784,10 +4784,10 @@ expo-updates-interface@~0.6.0:
resolved "https://registry.yarnpkg.com/expo-updates-interface/-/expo-updates-interface-0.6.0.tgz#cef5250106e59572afdfcf245c534754c8c844ba"
integrity sha512-oQcGTsE8mSkSxENPlWjZPGoJpt3RFDNPuO5d8shBDxBb4ZNH/W2ojavSFQMaLbNMoS0bYQQhzbRNEIBd306QMg==

expo-updates@~0.13.2:
version "0.13.2"
resolved "https://registry.yarnpkg.com/expo-updates/-/expo-updates-0.13.2.tgz#c96d664d8a97eb3af6841e46a137962b8bf06361"
integrity sha512-2ZthmyxYuN/c71y2oLNz9fdVXLf7ggxAw3Tfy+kwtGOTKNyOf/YoG+SwX7a0v+jZTJnuorEj5FuNf3wrniQ7+w==
expo-updates@~0.13.3:
version "0.13.3"
resolved "https://registry.yarnpkg.com/expo-updates/-/expo-updates-0.13.3.tgz#1e55ba2682de4633f2d1d0424078873868821361"
integrity sha512-aVO3Ha+vRGnkJbqlJMNoQn/p31DMnhZSGUs977ixhb0ff2xs530vf4/zVi4s635lkwuCd23++oga44Z4quKV/w==
dependencies:
"@expo/code-signing-certificates" "0.0.1"
"@expo/config" "^6.0.14"
Expand Down

0 comments on commit 85365cd

Please sign in to comment.