diff --git a/README.md b/README.md index 666721d..76eadf8 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,13 @@ # LunchHeroes -Lunch Heros Basel Hack Event Repo + +Lunch Heros Basel Hack Event Repo # Presentation Slides + [LunchHero Presentation](https://www.canva.com/design/DAFyifsFr18/oOybsSYmFfqYSdd0SuqZMA/edit?utm_content=DAFyifsFr18&utm_campaign=designshare&utm_medium=link2&utm_source=sharebutton) +# Figma Mockup +[Figma Mockup] (https://www.figma.com/file/gjotWvh3EWwIkEOtJcM88B/Untitled?type=design&node-id=0%3A1&mode=design&t=BT1mFm6CNMV2inDX-1) diff --git a/backend/main.py b/backend/main.py index 8ade5f6..ee77c17 100644 --- a/backend/main.py +++ b/backend/main.py @@ -1,8 +1,8 @@ -import lunchheros + from fastapi.encoders import jsonable_encoder -from src.lunchheros.db.dbFetcher import get_encoded_data +from src.lunchheros.db.dbFetcher import filter_data, get_encoded_data from src.routes.users.userFunctions import getAllQueryListData, getAllUsers, getUserWithId from fastapi import FastAPI from supabase_client import supabase_client @@ -30,6 +30,6 @@ def load_current_user(userId: str): userData = getUserWithId(userId) queryList = getAllQueryListData() - test = lunchheros.match.match(userData) + test = filter_data(queryList) return { "currentUser" : userData, "query": queryList} \ No newline at end of file diff --git a/backend/src/lunchheros/db/dbFetcher.py b/backend/src/lunchheros/db/dbFetcher.py index 429af96..559c128 100644 --- a/backend/src/lunchheros/db/dbFetcher.py +++ b/backend/src/lunchheros/db/dbFetcher.py @@ -1,13 +1,12 @@ +from lunchheros import match import numpy as np import pandas as pd import json import os - - - -async def get_encoded_data(time_slot: int, location: str, data): +async def filter_data(data): print("get_encoded_data") + return match(data) # Transform data #print(f"Data {time_slot} {location} {data}") #df = pd.DataFrame(data) @@ -19,7 +18,6 @@ async def get_encoded_data(time_slot: int, location: str, data): #return one_hot_encoded_df - def parse_user_id_tolist(test_data): data = json.loads(test_data) diff --git a/backend/src/lunchheros/match/__init__.py b/backend/src/lunchheros/match/__init__.py index 7233da5..d7f7564 100644 --- a/backend/src/lunchheros/match/__init__.py +++ b/backend/src/lunchheros/match/__init__.py @@ -1,5 +1,5 @@ """Subpackage related to matching between users into groups.""" -from lunchheros.match import matching +from lunchheros.match._randomize import matching __all__ = ["matching"] \ No newline at end of file diff --git a/backend/src/lunchheros/match/_randomize.py b/backend/src/lunchheros/match/_randomize.py index fd05658..31859ab 100644 --- a/backend/src/lunchheros/match/_randomize.py +++ b/backend/src/lunchheros/match/_randomize.py @@ -39,7 +39,7 @@ def _randomize_groups(group_size: int, users: list[str]) -> list[list]: return groups -def match(userids): +def matching(userids): # convert userids to list userids = parse_user_id_tolist(userids) diff --git a/backend/tests/match/test_randomize.py b/backend/tests/match/test_randomize.py index e3236e7..4fa52e2 100644 --- a/backend/tests/match/test_randomize.py +++ b/backend/tests/match/test_randomize.py @@ -1,4 +1,4 @@ -from lunchheros.match._randomize import _randomize_groups +from lunchheros.match._randomize import _randomize_groups, matching import json import numpy as np @@ -37,4 +37,13 @@ def test_randomize_with_real(): group_size = 4 # randomize groups groups = _randomize_groups(group_size, numpy_array.tolist()) - print(groups) \ No newline at end of file + print(groups) + + +def test_matching(): + + grouping = matching(test_data) + + print(grouping) + return grouping + \ No newline at end of file diff --git a/frontend/src/App.js b/frontend/src/App.js index 587e81c..3f8cd0f 100644 --- a/frontend/src/App.js +++ b/frontend/src/App.js @@ -1,4 +1,5 @@ -import React, { useState } from 'react'; + +import React, { useState, useEffect } from 'react'; // import logo from './logo.svg'; import './App.css'; import Login from './Components/Login'; @@ -7,14 +8,15 @@ import Navigation from './Components/Navigation'; import Profile from './Components/Profile'; import Status from './Components/Status'; import {useSelector} from 'react-redux'; // import useSelector from react-redux -import { Route, Navigate, Routes } from 'react-router-dom'; // import Route and Navigate from react-router-dom +import { Route, Navigate, Routes, useNavigate } from 'react-router-dom'; // import Route and Navigate from react-router-dom import Scheduling from './Components/Scheduling'; -import{ supabase } from './supabaseclient'; - - function App() { + const user = useSelector(state => state.session.user); + console.log("LOGIN USER", user?.user?.id); + console.log("LOGIN", user); + // const [isLoaded, setIsLoaded] = useState(false); // useEffect(() => { // dispatch(authenticate()).then(() => setIsLoaded(true)); @@ -43,9 +45,17 @@ function App() { setTimeSlot(slot); } - const user = useSelector(state => state.session.user); - console.log("LOGIN USER", user?.user?.id); - console.log("LOGIN", user); + + + const RedirectToHome = () => { + const navigate = useNavigate(); + + useEffect(() => { + navigate('/home'); + }, [navigate]); + + return null; // This component does not render anything to the DOM + } const Wrapper = () => { return ( @@ -56,17 +66,6 @@ function App() { onGroupSizeChange={handleGroupSizeChange} // Changed from props.onGroupSizeChange onTimeSlotChange={handleTimeSlotChange} /> - @@ -81,7 +80,23 @@ function App() { {user ? ( //routes that will be available ONLY when user is logged in //add additional routes here + <> + } /> } path="/home" /> + + } path="/profile" /> + ) : ( // } path="/home" /> //will redirect to '/' from any url if no user is logged in diff --git a/frontend/src/Components/Navigation.js b/frontend/src/Components/Navigation.js index ce182cb..5043ab8 100644 --- a/frontend/src/Components/Navigation.js +++ b/frontend/src/Components/Navigation.js @@ -40,7 +40,7 @@ function Navigation({ isLoaded }) { <>
- + Here the Basel Hack Logo is displayed Here the Basel Hack Logo is displayed diff --git a/frontend/src/Components/ProfileButton.js b/frontend/src/Components/ProfileButton.js index 68b475e..a9d8fb2 100644 --- a/frontend/src/Components/ProfileButton.js +++ b/frontend/src/Components/ProfileButton.js @@ -1,11 +1,14 @@ import React, { useState, useEffect, useRef } from "react"; +import { useDispatch } from "react-redux"; + import { logout } from "../store/session"; import { useNavigate } from "react-router-dom"; import "../SCSS/navigation.css"; function ProfileButton({ user }) { const [showMenu, setShowMenu] = useState(false); const ulRef = useRef(); - const navigate= useNavigate() + const navigate= useNavigate(); + const dispatch = useDispatch(); const openMenu = () => { if (showMenu) return; setShowMenu(true); @@ -22,8 +25,11 @@ function ProfileButton({ user }) { }, [showMenu]); const handleLogout = (e) => { e.preventDefault(); - logout(); - navigate("/"); + dispatch(logout()) + .then(() => { + navigate("/"); + closeMenu(); + }) }; const navUserProfile = (e) => { e.preventDefault(); @@ -54,4 +60,4 @@ function ProfileButton({ user }) { ); } -export default ProfileButton; \ No newline at end of file +export default ProfileButton; diff --git a/frontend/src/SCSS/scheduling.css b/frontend/src/SCSS/scheduling.css index 1b766d1..2aee297 100644 --- a/frontend/src/SCSS/scheduling.css +++ b/frontend/src/SCSS/scheduling.css @@ -176,9 +176,10 @@ input[type='range'] { border: 1px solid #007CAA; /* Change border color when hovered or focused */ } + .randomize-button { height: 100px !important; width: 250px !important; font-size: 25px; margin-top: 25px; -} \ No newline at end of file +} diff --git a/frontend/src/store/session.js b/frontend/src/store/session.js index e5ccf60..7cf7879 100644 --- a/frontend/src/store/session.js +++ b/frontend/src/store/session.js @@ -5,7 +5,7 @@ const SET_USER = "session/SET_USER"; const REMOVE_USER = "session/REMOVE_USER"; -const setUser = (user) => ({ +export const setUser = (user) => ({ type: SET_USER, payload: user, }); @@ -44,7 +44,7 @@ export const login = (email, password) => async (dispatch) => { if (response.data.user) { const data = response.data - console.log('DATA', data) + localStorage.setItem('user', data.user) dispatch(setUser(data)); return data; } else if (response.error) { @@ -57,13 +57,9 @@ export const login = (email, password) => async (dispatch) => { }; export const logout = () => async (dispatch) => { - const response = await fetch("/api/auth/logout", { - headers: { - "Content-Type": "application/json", - }, - }); + const response = await supabase.auth.signOut() - if (response.ok) { + if (!response.error) { dispatch(removeUser()); } }; diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..b1c591a --- /dev/null +++ b/package-lock.json @@ -0,0 +1,6 @@ +{ + "name": "LunchHeroes", + "lockfileVersion": 3, + "requires": true, + "packages": {} +}