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 - : } + : }