diff --git a/src/components/InputSuggest/SuggestByCurrentLocation/button.tsx b/src/components/InputSuggest/SuggestByCurrentLocation/button.tsx
new file mode 100644
index 00000000..9eb948dc
--- /dev/null
+++ b/src/components/InputSuggest/SuggestByCurrentLocation/button.tsx
@@ -0,0 +1,61 @@
+import { useCallback, useState } from "react";
+import styles from "./styles.module.scss";
+
+const suggestLocationTexts = {
+ en: "Suggest by current location",
+ ja: "現在地から提案",
+};
+
+const getSuggestLocationText = () => {
+ const lang = navigator.language;
+ if (lang.startsWith("ja")) {
+ return suggestLocationTexts.ja;
+ }
+ return suggestLocationTexts.en;
+};
+
+export const SuggestByCurrentLocationButton: React.FC<{
+ onClick: () => void;
+ onChange: ({
+ coordinates,
+ }: {
+ coordinates: GeolocationCoordinates | null;
+ }) => void;
+}> = ({ onClick, onChange }) => {
+ const [geoLocating, setGeoLocating] = useState(false);
+
+ const onGeolocate = useCallback(() => {
+ setGeoLocating(true);
+ navigator.geolocation.getCurrentPosition(
+ (position) => {
+ onChange({
+ coordinates: position.coords,
+ });
+ setGeoLocating(false);
+ },
+ (error) => {
+ onChange({
+ coordinates: null,
+ });
+ setGeoLocating(false);
+ }
+ );
+ }, [onChange]);
+
+ return (
+
+
+
+ );
+};
diff --git a/src/components/InputSuggest/SuggestByCurrentLocation/index.tsx b/src/components/InputSuggest/SuggestByCurrentLocation/index.tsx
index 376dc034..41afbba4 100644
--- a/src/components/InputSuggest/SuggestByCurrentLocation/index.tsx
+++ b/src/components/InputSuggest/SuggestByCurrentLocation/index.tsx
@@ -4,46 +4,13 @@ import { useCallback, useEffect, useState } from "react";
import styles from "./styles.module.scss";
-const suggestLocationTexts = {
- en: "Suggest by current location",
- ja: "現在地から提案",
-};
-
-const getSuggestLocationText = () => {
- const lang = navigator.language;
- if (lang.startsWith("ja")) {
- return suggestLocationTexts.ja;
- }
- return suggestLocationTexts.en;
-};
-
export const SuggestByCurrentLocation: React.FC<{
+ coordinates: GeolocationCoordinates | null;
onSelected?: (value: string) => void;
-}> = ({ onSelected }) => {
- const [geoLocating, setGeoLocating] = useState(false);
- const [geoLocated, setGeoLocated] = useState(false);
- const [coordinates, setCoordinates] = useState(
- null
- );
+}> = ({ coordinates, onSelected }) => {
const [address, setAddress] = useState(null);
const [suggests, setSuggests] = useState([]);
- const onGeolocate = useCallback(() => {
- setGeoLocating(true);
- navigator.geolocation.getCurrentPosition(
- (position) => {
- setGeoLocating(false);
- setGeoLocated(true);
- setCoordinates(position.coords);
- },
- (error) => {
- setGeoLocating(false);
- setGeoLocated(true);
- setCoordinates(null);
- }
- );
- }, []);
-
useEffect(() => {
if (!coordinates) {
return;
@@ -89,22 +56,9 @@ export const SuggestByCurrentLocation: React.FC<{
}, [address, suggests]);
return (
-
-
-
-
- {geoLocated && address && (
-
{address}
- )}
- {!geoLocating && suggests?.length > 0 && (
+
+ {address &&
{address}
}
+ {coordinates && suggests?.length > 0 && (
{suggests.map((suggest) => (