From 00259f38e9437b082f683464082c009c17a0e300 Mon Sep 17 00:00:00 2001 From: Jonathan Wofford Date: Sat, 28 Oct 2023 21:02:29 +0200 Subject: [PATCH 1/3] working on state persistance --- frontend/src/App.js | 18 ++++++++++++------ frontend/src/Components/Navigation.js | 2 +- frontend/src/Components/ProfileButton.js | 12 ++++++++---- frontend/src/SCSS/scheduling.css | 2 +- frontend/src/store/session.js | 12 ++++-------- 5 files changed, 26 insertions(+), 20 deletions(-) diff --git a/frontend/src/App.js b/frontend/src/App.js index 587e81c..ce07482 100644 --- a/frontend/src/App.js +++ b/frontend/src/App.js @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, { useState, useEffect } from 'react'; // import logo from './logo.svg'; import './App.css'; import Login from './Components/Login'; @@ -10,11 +10,19 @@ 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 Scheduling from './Components/Scheduling'; import{ supabase } from './supabaseclient'; - - +import { setUser } from './store/session'; function App() { + const user = useSelector(state => state.session.user); + useEffect(() => { + const loggedInUser = localStorage.getItem("user"); + if (loggedInUser) { + const foundUser = loggedInUser; + setUser(foundUser); + } + }, []); + // const [isLoaded, setIsLoaded] = useState(false); // useEffect(() => { // dispatch(authenticate()).then(() => setIsLoaded(true)); @@ -43,9 +51,7 @@ function App() { setTimeSlot(slot); } - const user = useSelector(state => state.session.user); - console.log("LOGIN USER", user?.user?.id); - console.log("LOGIN", user); + const Wrapper = () => { return ( 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 3d51673..1fa2c18 100644 --- a/frontend/src/Components/ProfileButton.js +++ b/frontend/src/Components/ProfileButton.js @@ -1,4 +1,5 @@ import React, { useState, useEffect, useRef } from "react"; +import { useDispatch } from "react-redux"; import { logout } from "../store/session"; import { useNavigate } from "react-router-dom"; @@ -7,8 +8,8 @@ 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); @@ -28,8 +29,11 @@ function ProfileButton({ user }) { const handleLogout = (e) => { e.preventDefault(); - logout(); - navigate("/"); + dispatch(logout()) + .then(() => { + navigate("/"); + closeMenu(); + }) }; const navUserProfile = (e) => { diff --git a/frontend/src/SCSS/scheduling.css b/frontend/src/SCSS/scheduling.css index f872236..6efa9b1 100644 --- a/frontend/src/SCSS/scheduling.css +++ b/frontend/src/SCSS/scheduling.css @@ -147,7 +147,7 @@ select, input[type="range"] { background-color: #45a049; } -.randomize-button { +.randomize-button, .customize-button { height: 100px !important; width: 250px !important; font-size: 25px; 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()); } }; From bad7d0e6089a46c2b31e8a06c5a38028970b5575 Mon Sep 17 00:00:00 2001 From: flalom Date: Sun, 29 Oct 2023 11:02:05 +0100 Subject: [PATCH 2/3] Add constrains on group size --- backend/src/lunchheros/db/dbFetcher.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/backend/src/lunchheros/db/dbFetcher.py b/backend/src/lunchheros/db/dbFetcher.py index 429af96..6f9bd76 100644 --- a/backend/src/lunchheros/db/dbFetcher.py +++ b/backend/src/lunchheros/db/dbFetcher.py @@ -3,9 +3,6 @@ import json import os - - - async def get_encoded_data(time_slot: int, location: str, data): print("get_encoded_data") # Transform data @@ -19,7 +16,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) From eead0f7261c02ea580044b122307f48cb7e57a8c Mon Sep 17 00:00:00 2001 From: flalom Date: Sun, 29 Oct 2023 11:12:35 +0100 Subject: [PATCH 3/3] Fix naming --- backend/src/lunchheros/match/_randomize.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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)