Skip to content
Merged
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
10 changes: 5 additions & 5 deletions FindMyClass/app/api/googleCalendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { getAuth } from "firebase/auth";
import AsyncStorage from '@react-native-async-storage/async-storage';
import { googleCalendarConfig } from '../secrets';

//This file is only called from Chatbot, since the schedule is using a refined version, this is hardcoded into schedule.js
// This file is only called from Chatbot, since the schedule is using a refined version,
// this is hardcoded into schedule.js

const fetchGoogleCalendarEvents = async () => {
try {
Expand Down Expand Up @@ -35,12 +36,11 @@ const fetchGoogleCalendarEvents = async () => {
console.error("Google API Error:", data.error);
return [];
}


return data.items || []; // Return events list
return data.items || []; // Return events list
} catch (error) {

return [];
console.error("Error fetching Google Calendar events:", error);
throw error; // Rethrow the error after logging it
}
};

Expand Down
3 changes: 2 additions & 1 deletion FindMyClass/app/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { View, StyleSheet } from 'react-native';
import { useRoute } from '@react-navigation/native';
import ToggleCampusMap from '../components/ToggleCampusMap';
import 'react-native-get-random-values'
import FloatingChatButton from '../components/FloatingChatButton'; // Ensure this path is correct


export default function MapScreen() { // Renamed to avoid conflict
Expand All @@ -15,7 +16,7 @@ export default function MapScreen() { // Renamed to avoid conflict
return (
<View style={styles.container} testID="map-container">
<ToggleCampusMap searchText={searchText} testID="toggle-campus-map" />
{/* <FloatingChatButton testID="floating-chat-button" /> */}
{ <FloatingChatButton testID="floating-chat-button" /> }
</View>
);
}
Expand Down
103 changes: 29 additions & 74 deletions FindMyClass/app/screens/directions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import polyline from "@mapbox/polyline";
import { googleAPIKey } from "../../app/secrets";
import LocationSelector from "../../components/directions/LocationSelector";
import ModalSearchBars from "../../components/directions/ModalSearchBars";
import { isBuildingFocused } from "../../components/locationUtils";
import SwipeUpModal from "../../components/directions/SwipeUpModal";
import {
isNearCampus,
Expand Down Expand Up @@ -630,80 +631,34 @@ export default function DirectionsScreen() {



const onRegionChange = (region) => {
// Calculate zoom level based on latitudeDelta
const calculatedZoom = calculateZoomLevel(region);
setZoomLevel( calculatedZoom );
const minimumZoom = 17;
// Check if we're zoomed in on the Hall Building
if (hallBuilding ) {
const hallLatLng = {
latitude: hallBuilding.latitude,
longitude: hallBuilding.longitude,
};

// Calculate distance between map center and Hall Building
const distance = Math.sqrt(
Math.pow(region.latitude - hallLatLng.latitude, 2) +
Math.pow(region.longitude - hallLatLng.longitude, 2)
);

// Determine if we're focused on Hall Building (centered and zoomed in)
const isHallFocused = distance < 0.0005 && calculatedZoom > minimumZoom;
setHallBuildingFocused(isHallFocused);
}
if (jmsbBuilding) {
const jmsbLatLng = {
latitude: jmsbBuilding.latitude,
longitude: jmsbBuilding.longitude,
};

// Calculate distance between map center and Hall Building
const distance = Math.sqrt(
Math.pow(region.latitude - jmsbLatLng.latitude, 2) +
Math.pow(region.longitude - jmsbLatLng.longitude, 2)
);

// Determine if we're focused on Hall Building (centered and zoomed in)
const isJMSBFocused = distance < 0.0006 && calculatedZoom > minimumZoom;
setJMSBBuildingFocused(isJMSBFocused);
}

if (vanierBuilding) {
const vanierLatLng = {
latitude: vanierBuilding.latitude,
longitude: vanierBuilding.longitude,
};

// Calculate distance between map center and Hall Building
const distance = Math.sqrt(
Math.pow(region.latitude - vanierLatLng.latitude, 2) +
Math.pow(region.longitude - vanierLatLng.longitude, 2)
);

// Determine if we're focused on Hall Building (centered and zoomed in)
const isVanierFocused = distance < 0.001 && calculatedZoom > minimumZoom;
setVanierBuildingFocused(isVanierFocused);
}

if (ccBuilding) {
const ccLatLng = {
latitude: ccBuilding.latitude,
longitude: ccBuilding.longitude,
};

// Calculate distance between map center and Hall Building
const distance = Math.sqrt(
Math.pow(region.latitude - ccLatLng.latitude, 2) +
Math.pow(region.longitude - ccLatLng.longitude, 2)
);

// Determine if we're focused on Hall Building (centered and zoomed in)
const isCCFocused = distance < 0.0005 && calculatedZoom > minimumZoom;
setCCBuildingFocused(isCCFocused);
}

};
const onRegionChange = (region) => {
// Calculate zoom level based on latitudeDelta
const calculatedZoom = calculateZoomLevel(region);
setZoomLevel(calculatedZoom);
const minimumZoom = 17;

// Set focus for each building using the helper
if (hallBuilding) {
setHallBuildingFocused(
isBuildingFocused(region, hallBuilding, calculatedZoom, 0.0005, minimumZoom)
);
}
if (jmsbBuilding) {
setJMSBBuildingFocused(
isBuildingFocused(region, jmsbBuilding, calculatedZoom, 0.0006, minimumZoom)
);
}
if (vanierBuilding) {
setVanierBuildingFocused(
isBuildingFocused(region, vanierBuilding, calculatedZoom, 0.001, minimumZoom)
);
}
if (ccBuilding) {
setCCBuildingFocused(
isBuildingFocused(region, ccBuilding, calculatedZoom, 0.0005, minimumZoom)
);
}
};

const handleMarkerPress = (coordinate) => {
mapRef.current?.animateToRegion({
Expand Down
3 changes: 2 additions & 1 deletion FindMyClass/app/screens/profile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useAuth } from '../../contexts/AuthContext';
import { useTheme } from '../../contexts/ThemeContext';
import { useLanguage } from '../../contexts/LanguageContext';
import { useRouter } from 'expo-router';
import FloatingChatButton from '../../components/FloatingChatButton';

export default function Profile() {
const { user } = useAuth();
Expand Down Expand Up @@ -503,7 +504,7 @@ export default function Profile() {
<Text style={styles.scheduleButtonText}>{t.viewSchedule}</Text>
</TouchableOpacity>
</View>
{/* <FloatingChatButton /> */}
{ <FloatingChatButton />}
</View>
);
}
Expand Down
2 changes: 0 additions & 2 deletions FindMyClass/app/screens/schedule.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import {
} from 'react-native';
import { MaterialIcons } from '@expo/vector-icons';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { getAuth } from 'firebase/auth';
import { googleCalendarConfig } from '../secrets';
import { useAuth } from '../../contexts/AuthContext';
import { useTheme } from '../../contexts/ThemeContext';
import { useLanguage } from '../../contexts/LanguageContext';
Expand Down
78 changes: 12 additions & 66 deletions FindMyClass/components/BuildingMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,17 @@ import {vanierBounds, vanierFlippedGrid, gridVanier } from "./rooms/VanierBuildi
import {ccBounds, ccFlippedGrid, gridCC } from "./rooms/CCBuildingRooms";
import { googleAPIKey } from '../app/secrets';
import RoomMarker from './RoomMarker';

import { isBuildingFocused } from "./locationUtils";




import { useTheme } from '../contexts/ThemeContext';
import { useLanguage } from '../contexts/LanguageContext';
import * as Location from 'expo-location';


// Define paths to floor plan images/SVGs
const floorPlans = {
1: require('../floorPlans/Hall-1.png'),
Expand Down Expand Up @@ -194,73 +201,12 @@ export default function BuildingMap({
const calculatedZoom = Math.log2(360 / region.latitudeDelta);
setZoomLevel(calculatedZoom);

// Check if we're zoomed in on the Hall Building
if (hallBuilding ) {
const hallLatLng = {
latitude: hallBuilding.latitude,
longitude: hallBuilding.longitude,
};

// Calculate distance between map center and Hall Building
const distance = Math.sqrt(
Math.pow(region.latitude - hallLatLng.latitude, 2) +
Math.pow(region.longitude - hallLatLng.longitude, 2)
);

// Determine if we're focused on Hall Building (centered and zoomed in)
const isHallFocused = distance < 0.0005 && calculatedZoom > 18;
setHallBuildingFocused(isHallFocused);
}
if (jmsbBuilding) {
const jmsbLatLng = {
latitude: jmsbBuilding.latitude,
longitude: jmsbBuilding.longitude,
};

// Calculate distance between map center and Hall Building
const distance = Math.sqrt(
Math.pow(region.latitude - jmsbLatLng.latitude, 2) +
Math.pow(region.longitude - jmsbLatLng.longitude, 2)
);

// Determine if we're focused on Hall Building (centered and zoomed in)
const isJMSBFocused = distance < 0.0006 && calculatedZoom > 18;
setJMSBBuildingFocused(isJMSBFocused);
}

if (vanierBuilding) {
const vanierLatLng = {
latitude: vanierBuilding.latitude,
longitude: vanierBuilding.longitude,
};

// Calculate distance between map center and Hall Building
const distance = Math.sqrt(
Math.pow(region.latitude - vanierLatLng.latitude, 2) +
Math.pow(region.longitude - vanierLatLng.longitude, 2)
);

// Determine if we're focused on Hall Building (centered and zoomed in)
const isVanierFocused = distance < 0.001 && calculatedZoom > 18;
setVanierBuildingFocused(isVanierFocused);
}

if (ccBuilding) {
const ccLatLng = {
latitude: ccBuilding.latitude,
longitude: ccBuilding.longitude,
};

// Calculate distance between map center and Hall Building
const distance = Math.sqrt(
Math.pow(region.latitude - ccLatLng.latitude, 2) +
Math.pow(region.longitude - ccLatLng.longitude, 2)
);

// Determine if we're focused on Hall Building (centered and zoomed in)
const isCCFocused = distance < 0.0005 && calculatedZoom > 18;
setCCBuildingFocused(isCCFocused);
}
// Use the helper to determine if each building is focused.
setHallBuildingFocused(isBuildingFocused(region, hallBuilding, calculatedZoom, 0.0005, 18));
setJMSBBuildingFocused(isBuildingFocused(region, jmsbBuilding, calculatedZoom, 0.0006, 18));
setVanierBuildingFocused(isBuildingFocused(region, vanierBuilding, calculatedZoom, 0.001, 18));
setCCBuildingFocused(isBuildingFocused(region, ccBuilding, calculatedZoom, 0.0005, 18));
};

// Search for a building and move the map to it
Expand Down
36 changes: 36 additions & 0 deletions FindMyClass/components/__tests__/locationUtils.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { calculateDistance, isBuildingFocused } from '../locationUtils';

describe('calculateDistance', () => {
it('returns 0 when both points are the same', () => {
expect(calculateDistance(45.0, -73.0, 45.0, -73.0)).toBe(0);
});

it('returns a positive value when points differ', () => {
const distance = calculateDistance(45.0, -73.0, 45.1, -73.1);
expect(distance).toBeGreaterThan(0);
});
});

describe('isBuildingFocused', () => {
const region = { latitude: 45.5, longitude: -73.6 };
const building = { latitude: 45.5, longitude: -73.6 };
const farBuilding = { latitude: 46.0, longitude: -74.0 };

it('returns false if building is null', () => {
expect(isBuildingFocused(region, null, 10, 0.1, 5)).toBe(false);
});

it('returns true if the distance is less than threshold and zoom is above minZoom', () => {
expect(isBuildingFocused(region, building, 10, 0.1, 5)).toBe(true);
});

it('returns false if the distance is greater than or equal to threshold', () => {
// Use a very low distanceThreshold.
expect(isBuildingFocused(region, farBuilding, 10, 0.1, 5)).toBe(false);
});

it('returns false if the calculatedZoom is not above minZoom', () => {
// Even if the distance is small but zoom is too low.
expect(isBuildingFocused(region, building, 4, 0.1, 5)).toBe(false);
});
});
32 changes: 32 additions & 0 deletions FindMyClass/components/locationUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// locationUtils.js

/**
* Calculate the distance between two points (lat1, lon1) and (lat2, lon2)
*/
export const calculateDistance = (lat1, lon1, lat2, lon2) => {
return Math.sqrt(
Math.pow(lat1 - lat2, 2) + Math.pow(lon1 - lon2, 2)
);
};

/**
* Determine if the map is focused on a building based on a distance threshold and minimum zoom.
* @param {object} region - The current region from the map.
* @param {object} building - The building object containing latitude and longitude.
* @param {number} calculatedZoom - The zoom level calculated from the region.
* @param {number} distanceThreshold - Maximum allowed distance to consider the building focused.
* @param {number} minZoom - The minimum zoom level required.
* @returns {boolean} True if focused, false otherwise.
*/
export const isBuildingFocused = (region, building, calculatedZoom, distanceThreshold, minZoom) => {
if (!building) return false;

const distance = calculateDistance(
region.latitude,
region.longitude,
building.latitude,
building.longitude
);

return distance < distanceThreshold && calculatedZoom > minZoom;
};
Loading
Loading