Skip to content

Commit

Permalink
add message when nothing found on map
Browse files Browse the repository at this point in the history
  • Loading branch information
Prabhat Pal committed Feb 15, 2021
1 parent 033002d commit 0a39329
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 67 deletions.
2 changes: 1 addition & 1 deletion pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const Home = () => {
places={lastData && lastData.places ? lastData.places : []}
focusedPlaceId={focusedPlaceId}
setFocusedPlaceId={setFocusedPlaceId}
searchedCoordiantes={({ latitude, longitude }) =>
searchedCoordinates={({ latitude, longitude }) =>
setSearchedViewport((viewport) => {
return { ...viewport, latitude, longitude, zoom: 11 };
})
Expand Down
2 changes: 1 addition & 1 deletion pages/places/[id]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ const PlaceId: PlaceIdFC = () => {
refetch();
setEditMode(false);
}}
searchedCoordiantes={({ latitude, longitude }) =>
searchedCoordinates={({ latitude, longitude }) =>
setSearchedViewport((viewport) => {
return { ...viewport, latitude, longitude };
})
Expand Down
2 changes: 1 addition & 1 deletion pages/places/add.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const Add = () => {
onSubmitted={(id) => {
router.push(`${urls.places}/${id}`);
}}
searchedCoordiantes={({ latitude, longitude }) =>
searchedCoordinates={({ latitude, longitude }) =>
setSearchedViewport((viewport) => {
return { ...viewport, latitude, longitude };
})
Expand Down
122 changes: 61 additions & 61 deletions src/components/PlaceForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ interface IPlace {
interface IPlaceFormProps {
place?: IPlace;
onSubmitted: (id: string) => void;
searchedCoordiantes: ({
searchedCoordinates: ({
latitude,
longitude,
}: {
Expand Down Expand Up @@ -147,7 +147,7 @@ const uploadImage = async (
const PlaceForm: FC<IPlaceFormProps> = ({
place,
onSubmitted,
searchedCoordiantes,
searchedCoordinates,
}) => {
const { addToast } = useToasts();
const [previewImage, setPreviewImage] = useState<string>("");
Expand Down Expand Up @@ -314,78 +314,78 @@ const PlaceForm: FC<IPlaceFormProps> = ({
const handleUpdatePlace = async (data: IFormData) => {
setSubmitting(true);
try {
if (place) {
let image = place.image;
if (!place) {
throw new Error("Something went wrong! Please try again later");
}

if (!watch("publicId")) {
const {
data: signatureData,
errors: signatureErrors,
} = await createSignature();
let image = place.image;

if (signatureErrors && signatureErrors.length) {
signatureErrors.map((error) => {
throw new Error(
error.message ?? "Something went wrong! Please try again later"
);
});
}
if (!watch("publicId")) {
const {
data: signatureData,
errors: signatureErrors,
} = await createSignature();

if (signatureData) {
const { signature, timestamp } = signatureData.createImageSignature;
const imageData = await uploadImage(
data.image[0] as File,
signature,
timestamp
);
if (signatureErrors && signatureErrors.length) {
const errors = signatureErrors.map(
(error) =>
error.message ?? "Something went wrong! Please try again later"
);
throw new Error(errors.join(", "));
}

if (imageData.error) {
throw new Error(
imageData.error.message ??
"Something went wrong! Please try again later"
);
}
if (signatureData) {
const { signature, timestamp } = signatureData.createImageSignature;
const imageData = await uploadImage(
data.image[0] as File,
signature,
timestamp
);

image = imageData.secure_url;
if (imageData.error) {
throw new Error(
imageData.error.message ??
"Something went wrong! Please try again later"
);
}

image = imageData.secure_url;
}
}

const { data: placeData, errors: placeErrors } = await updatePlace({
variables: {
id: place.id,
input: {
placeName: data.placeName,
placeType: data.placeType,
description: data.description,
address: data.address,
image: image,
coordinates: {
latitude: data.latitude,
longitude: data.longitude,
},
const { data: placeData, errors: placeErrors } = await updatePlace({
variables: {
id: place.id,
input: {
placeName: data.placeName,
placeType: data.placeType,
description: data.description,
address: data.address,
image: image,
coordinates: {
latitude: data.latitude,
longitude: data.longitude,
},
},
});
},
});

if (placeErrors && placeErrors.length) {
placeErrors.map((error) => {
throw new Error(
error.message ?? "Something went wrong! Please try again later"
);
});
}
if (placeErrors && placeErrors.length) {
const errors = placeErrors.map(
(error) =>
error.message ?? "Something went wrong! Please try again later"
);
throw new Error(errors.join(", "));
}

if (placeData?.updatePlace?.id) {
addToast("Place updated successfully", {
appearance: "success",
});
onSubmitted(placeData.updatePlace.id);
} else {
throw new Error("Something went wrong! Please try again later");
}
} else {
if (!placeData?.updatePlace?.id) {
throw new Error("Something went wrong! Please try again later");
}

addToast("Place updated successfully", {
appearance: "success",
});
onSubmitted(placeData.updatePlace.id);
} catch (err) {
console.error(`😱: ${err}`);
addToast(err.message ?? "Something went wrong! Please try again later.", {
Expand Down Expand Up @@ -425,7 +425,7 @@ const PlaceForm: FC<IPlaceFormProps> = ({
shouldValidate: true,
shouldDirty: true,
});
searchedCoordiantes({ latitude: lat, longitude: lng });
searchedCoordinates({ latitude: lat, longitude: lng });
}}
error={errors?.address || errors?.latitude || errors?.longitude}
/>
Expand Down
23 changes: 20 additions & 3 deletions src/components/PlaceList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import Link from "next/link";
import LocationSearch from "./LocationSearch";
import { IoLocationSharp } from "react-icons/io5";
import { minWidthXl } from "src/utils";
import { useAuth } from "src/contexts";

interface IPlaceList {
places: GetPlacesQuery_places[];
focusedPlaceId: string;
setFocusedPlaceId: Dispatch<SetStateAction<string>>;
searchedCoordiantes: ({
searchedCoordinates: ({
latitude,
longitude,
}: {
Expand All @@ -24,8 +25,9 @@ const PlaceList: FC<IPlaceList> = ({
places,
focusedPlaceId,
setFocusedPlaceId,
searchedCoordiantes,
searchedCoordinates,
}) => {
const { authenticated } = useAuth();
return (
<div
className="mx-auto xl:overflow-y-scroll p-8"
Expand All @@ -38,12 +40,27 @@ const PlaceList: FC<IPlaceList> = ({
<LocationSearch
defaultValue=""
onSelectAddress={({ lat, lng }) =>
searchedCoordiantes({ latitude: lat, longitude: lng })
searchedCoordinates({ latitude: lat, longitude: lng })
}
/>
</div>

<div className="flex flex-col space-y-4">
{places.length === 0 && (
<div className="flex flex-col items-center rounded-md p-4 overflow-hidden bg-gray-800 border-2 border-solid border-gray-700">
<div className="text-xl">Nothing found here!</div>
{authenticated ? (
<div>
Want to share something interesting about this place, click on
"Add a new Place"
</div>
) : (
<div>
Want to add something to this place? Please SignIn / SignUp
</div>
)}
</div>
)}
{places.map((place) => (
<Link key={place.id} href={`${urls.places}/${place.id}`}>
<a
Expand Down

1 comment on commit 0a39329

@vercel
Copy link

@vercel vercel bot commented on 0a39329 Feb 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.