Skip to content

Commit

Permalink
Invitee Prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
ProLoser committed Oct 13, 2024
1 parent 9926d12 commit 48a8cc1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
3 changes: 1 addition & 2 deletions src/Dialogues/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -75,7 +75,6 @@ export default function Login({ reset, friend, load, toggle }: LoginProps) {

const decline = useCallback(() => {
load()
toggle(false)
}, [load]);

return (
Expand Down
22 changes: 10 additions & 12 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,21 @@ 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);
setFriend(null);
return;
}

window.history.pushState(null, '', `${friendId}`);
const friendSnapshot = await database.ref(`users/${friendId}`).get();
if (!friendSnapshot.exists()) {
console.error('User not found', friendId);
Expand Down Expand Up @@ -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(() => {
Expand Down Expand Up @@ -255,7 +253,7 @@ export function App() {

return (
<>
<dialog open={!!state}>
<dialog open={(friendData&&!user)||!!state}>
{user
? state === 'friends'
? <Friends authUser={user} load={load} toggle={toggle} reset={reset} />
Expand All @@ -264,7 +262,7 @@ export function App() {
: state === 'chat'
? <Chat chats={chats} user={user} />
: null
: <Login reset={reset} friend={friendData} toggle={toggle} load={load} />}
: <Login reset={reset} friend={friendData} load={load} />}
</dialog>

<div id="board">
Expand Down

0 comments on commit 48a8cc1

Please sign in to comment.