From 48a8cc136a311e45e7232bb18fad166538cdf6a3 Mon Sep 17 00:00:00 2001 From: Dean Sofer Date: Sun, 13 Oct 2024 22:33:24 +0000 Subject: [PATCH] Invitee Prompt --- src/Dialogues/Login.tsx | 3 +-- src/index.tsx | 22 ++++++++++------------ 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/Dialogues/Login.tsx b/src/Dialogues/Login.tsx index f60be70..52561bb 100644 --- a/src/Dialogues/Login.tsx +++ b/src/Dialogues/Login.tsx @@ -45,7 +45,7 @@ type LoginProps = { friend?: { name: string }; }; -export default function Login({ reset, friend, load, toggle }: LoginProps) { +export default function Login({ reset, friend, load }: LoginProps) { const [userSignedIn, setUserSignedIn] = useState(false); const elementRef = useRef(null); const [isExpanded, setIsExpanded] = useState(false); @@ -75,7 +75,6 @@ export default function Login({ reset, friend, load, toggle }: LoginProps) { const decline = useCallback(() => { load() - toggle(false) }, [load]); return ( diff --git a/src/index.tsx b/src/index.tsx index 3e25b03..996fc8f 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -65,9 +65,14 @@ export function App() { }); }, [lastState]); - const load = useCallback(async (friendId?: string) => { + const load = useCallback(async (friendId: string = '') => { console.log('Loading', friendId); + // Update URL + if (window.location.pathname !== `/${friendId}`) { + window.history.pushState(null, '', `/${friendId}`); + } + if (!friendId) { setMatch(null); setChats(null); @@ -75,7 +80,6 @@ export function App() { return; } - window.history.pushState(null, '', `${friendId}`); const friendSnapshot = await database.ref(`users/${friendId}`).get(); if (!friendSnapshot.exists()) { console.error('User not found', friendId); @@ -118,15 +122,9 @@ export function App() { useEffect(() => { const friendId = location.pathname.split('/').pop() if (friendId && friendId !== 'PeaceInTheMiddleEast') { - if (user) { - load(friendId) - } else { - load(friendId); - toggle('friends'); - } + load(friendId) } - - }, [load, user]); + }, []); // onLogin/Logout useEffect(() => { @@ -255,7 +253,7 @@ export function App() { return ( <> - + {user ? state === 'friends' ? @@ -264,7 +262,7 @@ export function App() { : state === 'chat' ? : null - : } + : }