Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ client.zip
.vscode
*.DS_Store
package-lock.json
serviceAccountKey.json

# Logs
logs
Expand Down
15 changes: 8 additions & 7 deletions client/screens/firebase.js → client/auth/firebase.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { initializeApp } from "firebase/app";
import { getAuth, GoogleAuthProvider, signInWithPopup } from "firebase/auth";
import { FIREBASE_API_KEY } from "@env"
import { FIREBASE_API_KEY, FIREBASE_AUTH_DOMAIN, FIREBASE_PROJECT_ID, FIREBASE_STORAGE_BUCKET, FIREBASE_MESSAGING_SENDER_ID, FIREBASE_APP_ID, FIREBASE_MEASUREMENT_ID } from "@env"

const firebaseConfig = {
apiKey: FIREBASE_API_KEY,
authDomain: "auth-8b1ef.firebaseapp.com",
projectId: "auth-8b1ef",
storageBucket: "auth-8b1ef.appspot.com",
messagingSenderId: "445273762769",
appId: "1:445273762769:web:81f403cae7cb5fe3760ef0",
authDomain: FIREBASE_AUTH_DOMAIN,
projectId: FIREBASE_PROJECT_ID,
storageBucket: FIREBASE_STORAGE_BUCKET,
messagingSenderId: FIREBASE_MESSAGING_SENDER_ID,
appId: FIREBASE_APP_ID,
measurementId: FIREBASE_MEASUREMENT_ID
};

const app = initializeApp(firebaseConfig);
export const app = initializeApp(firebaseConfig);
export const auth = getAuth(app);

const provider = new GoogleAuthProvider();
Expand Down
25 changes: 16 additions & 9 deletions client/components/SearchInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,19 @@ import { getWeatherWeek } from "../api/getWeatherWeek";

export const SearchInput = () => {
const [searchString, setSearchString] = useState("Virginia US");
const [geoCode, setGeoCode] = useState();
const [geoCode, setGeoCode] = useState({});
const [isLoadingMobile, setIsLoadingMobile] = useState(false);

const dispatch = useDispatch();
const lat = geoCode?.features[0]?.geometry?.coordinates[1];
const lon = geoCode?.features[0]?.geometry?.coordinates[0];
const state = geoCode?.features[0]?.properties.state;
// const lat = geoCode?.features[0]?.geometry?.coordinates[1];
// const lon = geoCode?.features[0]?.geometry?.coordinates[0];
// const state = geoCode?.features[0]?.properties?.state;

useEffect(() => {
const getCode = async () => {
setIsLoadingMobile(true);
const code = await getGeoCode(searchString);
console.log("code:", code);
setIsLoadingMobile(false);
setGeoCode(code);
};
Expand All @@ -67,12 +68,18 @@ export const SearchInput = () => {
const weeekArray = await getWeatherWeek(lat, lon);
dispatch(addWeek(weeekArray));
};

if (lat && lon) {
getWeatherObject();
getWeek();

if (geoCode?.features) {
const lat = geoCode.features[0]?.geometry?.coordinates?.[1];
const lon = geoCode.features[0]?.geometry?.coordinates?.[0];
const state = geoCode.features[0]?.properties?.state;

if (lat && lon) {
getWeatherObject();
getWeek();
}
}
}, [lat, lon, state]);
}, [geoCode, dispatch]);

return Platform.OS === "web" ? (
<VStack my="4" space={5} w="100%" maxW="300px">
Expand Down
39 changes: 24 additions & 15 deletions client/components/map/MapContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ export function CustomizedMap() {

const [style, setStyle] = React.useState("mapbox://styles/mapbox/outdoors-v11");


useEffect(() => {
console.log("StyleURL:", Mapbox?.StyleURL);
}, []);
if (mapViewLoaded) {
handleShapeSourceLoad();
}
}, [mapViewLoaded]);

const [lng, setLng] = useState(103.8519599);
const [lat, setLat] = useState(1.29027);
Expand All @@ -39,6 +42,7 @@ export function CustomizedMap() {

function handleMapViewLayout() {
setMapViewLoaded(true);

}

const handleStyleChange = (value) => {
Expand Down Expand Up @@ -106,22 +110,26 @@ export function CustomizedMap() {

const bounds = getShapeSourceBounds(shape);

mapViewRef.current.fitBounds(bounds, {
mapViewRef?.current?.fitBounds(bounds, {
edgePadding: {
top: 5,
right: 5,
bottom: 5,
left: 5
top: 100,
right: 100,
bottom: 100,
left: 100
}
}, () => {
const centerLng = (bounds[0][0] + bounds[1][0]) / 2;
const centerLat = (bounds[0][1] + bounds[1][1]) / 2;

mapViewRef.current.setCamera({
centerCoordinate: [centerLng, centerLat],
minZoomLevel: 10,
});
});

mapViewRef.current.setCamera({
centerCoordinate: mapViewRef.current.getCenter(),
zoomLevel: Math.min(
mapViewRef.current.zoomLevel,
mapViewRef.current.getZoomForBounds(bounds, { padding: 50 })
)
});
console.log('shape:', shape);
console.log('bounds:', bounds);
console.log('mapViewRef:', mapViewRef);
}


Expand Down Expand Up @@ -174,6 +182,7 @@ export function CustomizedMap() {
>
<Mapbox.Camera
centerCoordinate={[-77.035, 38.875]}

// zoomLevel={12}
/>

Expand Down Expand Up @@ -241,7 +250,7 @@ export function MapContainer() {
return (
<View style={styles.container}>
<Text>Map - Basic</Text>
<BasicMap />
{/* <BasicMap /> */}

<Text>Map - Customized</Text>
<CustomizedMap />
Expand Down
35 changes: 25 additions & 10 deletions client/hooks/useLogin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,31 @@ import { api } from "../constants/api";
import { useMutation } from "@tanstack/react-query";
import { queryClient } from "../constants/queryClient";
import { useAuth } from "../auth/provider";
import { app, auth } from "../auth/firebase";
import { getAuth, signInWithEmailAndPassword } from "firebase/auth";

const loginUser = async (user) => {
return await fetcher(`${api}/user/login`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(user),
});
try {
const { email, password } = user;
signInWithEmailAndPassword(auth, email, password)
.then((userCredential) => {
// Signed in
const user = userCredential.user;
// ...
const token = user.getIdToken();

return user;
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
});


} catch (error) {
console.log(error);
}

};

export default function useLogin() {
Expand All @@ -22,11 +38,10 @@ export default function useLogin() {
return loginUser(user);
},
onSuccess: (data, variables, context) => {
// Invalidate and refetch
signIn(data.user);
signIn(data);
queryClient.invalidateQueries({ queryKey: ["user"] });
},
});

return { loginUser: mutation };
}
}
9 changes: 7 additions & 2 deletions client/hooks/useRegister.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,26 @@ import { useMutation } from "@tanstack/react-query";
import { queryClient } from "../constants/queryClient";

const addUser = async (newUser) => {
return await fetcher(`${api}/user/`, {
const response = await fetch(`${api}/user/`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(newUser),
});
const data = await response.json();
if (!response.ok) {
throw new Error(data.error.message);
}
return data;
};

export default function useRegister() {
const mutation = useMutation({
mutationFn: async (newUser) => {
return addUser(newUser);
},
onSuccess: () => {
onSuccess: (data, variables, context) => {
// Invalidate and refetch
queryClient.invalidateQueries({ queryKey: ["user"] });
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>PreviewsEnabled</key>
<false/>
</dict>
</plist>
Loading