Skip to content

Commit

Permalink
fix: fix location fetching for investment and office
Browse files Browse the repository at this point in the history
  • Loading branch information
szarbartosz committed Nov 5, 2024
1 parent 691fd4f commit 4c6bc3a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 21 deletions.
26 changes: 16 additions & 10 deletions src/app/investments/details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ import retroMap from '@/utils/retro-map.json';

const InvestmentDetailsScreen: FC = () => {
const { id } = useLocalSearchParams<{ id: string }>();
const { data: investment } = useGetSingleInvestmentQuery(+id);
const {
data: investment,
isLoading: isFetchingInvestment,
isSuccess: isInvestmentFetched,
} = useGetSingleInvestmentQuery(+id);
const [updateInvestment] = useUpdateInvestmentMutation();

const [coords, setCoords] = useState<{ latitude: number; longitude: number } | null>(null);
Expand All @@ -45,16 +49,18 @@ const InvestmentDetailsScreen: FC = () => {
setCoords({ latitude: geoResult[0].latitude, longitude: geoResult[0].longitude });
};

fetchCoords().catch(_err => {
Toast.show({
type: 'warning',
props: {
text1: 'Wystąpił błąd!',
text2: 'Nie udało się pobrać lokalizacji inwestycji...',
},
if (!isFetchingInvestment && isInvestmentFetched) {
fetchCoords().catch(_err => {
Toast.show({
type: 'warning',
props: {
text1: 'Wystąpił błąd!',
text2: 'Nie udało się pobrać lokalizacji inwestycji...',
},
});
});
});
}, [investment]);
}
}, [investment, isFetchingInvestment, isInvestmentFetched]);

const statusSheetRef = useRef<BottomSheetModal>(null);

Expand Down
1 change: 0 additions & 1 deletion src/app/investors/details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const InvestorDetailsScreen: FC = () => {
const { data: investor } = useGetSingleInvestorQuery(+id);

const theme = useTheme();
console.log(investor?.locations[0].status);

return (
<ScrollView showsVerticalScrollIndicator={false} paddingHorizontal="$4">
Expand Down
26 changes: 16 additions & 10 deletions src/app/offices/details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ import retroMap from '@/utils/retro-map.json';

const InvestmentDetailsScreen: FC = () => {
const { id } = useLocalSearchParams<{ id: string }>();
const { data: office } = useGetSingleOfficeQuery(+id);
const {
data: office,
isLoading: isFetchingOffice,
isSuccess: isOfficeFetched,
} = useGetSingleOfficeQuery(+id);

const [coords, setCoords] = useState<{ latitude: number; longitude: number } | null>(null);
const [isMapCentered, setIsMapCentered] = useState(true);
Expand All @@ -43,16 +47,18 @@ const InvestmentDetailsScreen: FC = () => {
setCoords({ latitude: geoResult[0].latitude, longitude: geoResult[0].longitude });
};

fetchCoords().catch(_err => {
Toast.show({
type: 'warning',
props: {
text1: 'Wystąpił błąd!',
text2: 'Nie udało się pobrać lokalizacji urzędu...',
},
if (!isFetchingOffice && isOfficeFetched) {
fetchCoords().catch(_err => {
Toast.show({
type: 'warning',
props: {
text1: 'Wystąpił błąd!',
text2: 'Nie udało się pobrać lokalizacji urzędu...',
},
});
});
});
}, [office]);
}
}, [isFetchingOffice, isOfficeFetched, office]);

return (
<>
Expand Down

0 comments on commit 4c6bc3a

Please sign in to comment.