From 82e1a4ca5da59c17b3d694f28e61d9e98e4b8e62 Mon Sep 17 00:00:00 2001 From: nicolas-arnaud Date: Thu, 23 Mar 2023 17:20:42 +0100 Subject: [PATCH] open profile after login; use appStates for profiles and histories --- back/src/auth/auth.controller.ts | 2 +- front/src/App.svelte | 39 ++++++------ front/src/components/Channels.svelte | 4 +- front/src/components/Chat.svelte | 6 +- front/src/components/Friends.svelte | 8 +-- front/src/components/MatchHistory.svelte | 41 +++++++----- front/src/components/Profile.svelte | 81 +++++++++++++----------- 7 files changed, 100 insertions(+), 81 deletions(-) diff --git a/back/src/auth/auth.controller.ts b/back/src/auth/auth.controller.ts index a0ea023..eabdd6d 100644 --- a/back/src/auth/auth.controller.ts +++ b/back/src/auth/auth.controller.ts @@ -42,7 +42,7 @@ export class AuthController { @Get('inReturn') @UseGuards(FtOauthGuard) - @Redirect(`http://${frontHost}:${frontPort}`) + @Redirect(`http://${frontHost}:${frontPort}/profile`) ftAuthCallback ( @Res({ passthrough: true }) response: Response, @Req() request: Request diff --git a/front/src/App.svelte b/front/src/App.svelte index 5fe3a52..767d56a 100644 --- a/front/src/App.svelte +++ b/front/src/App.svelte @@ -3,13 +3,11 @@ HOME = "/", PROFILE = "/profile", HISTORY = "/history", - HISTORY_ID = "/history_id", FRIENDS = "/friends", CHANNELS = "/channels", LEADERBOARD = "/leaderboard", CREATE_GAME = "/create-game", MATCHMAKING = "/matchmaking", - PROFILE_ID = "/profile_id", } @@ -90,7 +88,10 @@ } onMount(() => { - history.replaceState({ appState: "" }, "", "/"); + if (window.location.pathname === "/profile") + history.replaceState({ appState: APPSTATE.PROFILE }, "", APPSTATE.PROFILE); + else + history.replaceState({ appState: "" }, "", "/"); window.onpopstate = (e: PopStateEvent) => { if (e.state) { appState = e.state.appState; @@ -103,16 +104,17 @@ }, 15000); function clickProfile() { - profileUsername = $store.username setAppState(APPSTATE.PROFILE); } - let profileUsername: string = $store?.username ?? ""; async function openIdProfile(event: CustomEvent) { - profileUsername = event.detail; - setAppState(APPSTATE.PROFILE_ID); + setAppState(APPSTATE.PROFILE + "#" + event.detail); } - $: console.log("New profileUsername:", profileUsername) + + async function openIdHistory(event: CustomEvent) { + setAppState(APPSTATE.HISTORY + "#" + event.detail); + } + async function clickHistory() { setAppState(APPSTATE.HISTORY); } @@ -176,8 +178,7 @@ {failedGameLogIn} {gamePlaying} /> - - {#if appState.includes(`${APPSTATE.CHANNELS}#`)} + {#if appState.includes(`${APPSTATE.CHANNELS}#`)} {#key appState}
setAppState(APPSTATE.CHANNELS)} @@ -195,8 +196,8 @@
{/key} {/if} - {#if appState.includes(APPSTATE.CHANNELS)} -
- +
{/if} - {#if appState === APPSTATE.HISTORY_ID} + {#if appState.includes(`${APPSTATE.HISTORY}#`)}
setAppState(APPSTATE.PROFILE)} on:keydown={() => setAppState(APPSTATE.PROFILE)} > - +
{/if} {#if appState === APPSTATE.PROFILE}
- setAppState(APPSTATE.HISTORY_ID)} /> +
{/if} - {#if appState === APPSTATE.PROFILE_ID} + {#if appState.includes(`${APPSTATE.PROFILE}#`)}
setAppState(history.state.prevState)} on:keydown={() => setAppState(history.state.prevState)} > setAppState(APPSTATE.HISTORY_ID)} + on:view-history={openIdHistory} on:add-friend={addFriend} on:invite-to-game={pong.inviteToGame} /> diff --git a/front/src/components/Channels.svelte b/front/src/components/Channels.svelte index 385d1c1..14385f9 100644 --- a/front/src/components/Channels.svelte +++ b/front/src/components/Channels.svelte @@ -1,6 +1,6 @@
- {#if data.length > 0} - - - - - - +
{username}'s last matchs
+ + + {#if username === ""} + + {:else} + + {/if} + + + {#if data.length > 0} @@ -89,10 +98,10 @@ {/each} -
Global historyHistory of {username}
Date
{:else}

No matches to display

{/if} +
0} diff --git a/front/src/components/Profile.svelte b/front/src/components/Profile.svelte index 2b2b033..fdcd68b 100644 --- a/front/src/components/Profile.svelte +++ b/front/src/components/Profile.svelte @@ -14,22 +14,49 @@