Cuter 2 years ago
parent
commit
1cc9964b5f
  1. 42
      front/volume/src/App.svelte
  2. 3
      front/volume/src/components/Channels.svelte

42
front/volume/src/App.svelte

@ -26,9 +26,11 @@
import Pong from "./components/Pong/Pong.svelte"; import Pong from "./components/Pong/Pong.svelte";
import type { ChannelsType } from "./components/Channels.svelte"; import type { ChannelsType } from "./components/Channels.svelte";
import { API_URL } from "./Auth";
import { store, getUser, login, verify } from "./Auth"; import { store, getUser, login, verify } from "./Auth";
import FakeLogin from "./FakeLogin.svelte"; import FakeLogin from "./FakeLogin.svelte";
// import { channel } from "diagnostics_channel";
// Single Page Application config // Single Page Application config
let appState: string = APPSTATE.HOME; let appState: string = APPSTATE.HOME;
@ -57,6 +59,15 @@
getUser(); getUser();
}, 15000); }, 15000);
let DMChannel: Array<ChannelsType> = [];
onMount(async () => {
const res = await fetch(API_URL + "/channels/dms/" + DMUsername, {
credentials: "include",
mode: "cors",
});
if (res.ok) DMChannel = await res.json();
});
function clickProfile() { function clickProfile() {
setAppState(APPSTATE.PROFILE); setAppState(APPSTATE.PROFILE);
} }
@ -67,6 +78,18 @@
setAppState(APPSTATE.PROFILE_ID); setAppState(APPSTATE.PROFILE_ID);
} }
let chan: Channels;
let DMUsername: string = "";
async function openDirectChat(event: CustomEvent<string>) {
// pass profile to backend
// backend looks for a chat and if it doesn't exist it creates it
// backend send chat id to front end
// front opens chat with selectChat()
DMUsername = event.detail;
console.log(chan);
chan.selectChat(DMChannel[0].id);
}
async function clickHistory() { async function clickHistory() {
setAppState(APPSTATE.HISTORY); setAppState(APPSTATE.HISTORY);
} }
@ -130,8 +153,9 @@
{clickLeaderboard} {clickLeaderboard}
/> />
{#if appState.includes(APPSTATE.CHANNELS)} {#if appState.includes(APPSTATE.CHANNELS)}
{#if appState.replace(APPSTATE.CHANNELS, "") !== ""} <!-- {#if appState.replace(APPSTATE.CHANNELS, "") !== ""} -->
<div <div
class="{appState.replace(APPSTATE.CHANNELS, "") === "" ? 'hidden' : ''}"
on:click={() => setAppState(APPSTATE.CHANNELS)} on:click={() => setAppState(APPSTATE.CHANNELS)}
on:keydown={() => setAppState(APPSTATE.CHANNELS)} on:keydown={() => setAppState(APPSTATE.CHANNELS)}
> >
@ -140,13 +164,17 @@
on:view-profile={openIdProfile} on:view-profile={openIdProfile}
on:add-friend={addFriend} on:add-friend={addFriend}
on:invite-to-game={pong.inviteToGame} on:invite-to-game={pong.inviteToGame}
on:send-message={openDirectChat}
/> />
</div> </div>
{:else} <!-- {:else} -->
<div on:click={resetAppState} on:keydown={resetAppState}> <div
<Channels onSelectChannel={handleSelectChannel} /> class="{appState.replace(APPSTATE.CHANNELS, "") !== "" ? 'hidden' : ''}"
on:click={resetAppState}
on:keydown={resetAppState}>
<Channels bind:this={chan} onSelectChannel={handleSelectChannel} />
</div> </div>
{/if} <!-- {/if} -->
{/if} {/if}
{#if appState === APPSTATE.LEADERBOARD} {#if appState === APPSTATE.LEADERBOARD}
<div on:click={resetAppState} on:keydown={resetAppState}> <div on:click={resetAppState} on:keydown={resetAppState}>
@ -244,4 +272,8 @@
outline: none; outline: none;
box-shadow: 0 0 0 2px rgba(25, 135, 84, 0.25); box-shadow: 0 0 0 2px rgba(25, 135, 84, 0.25);
} }
.hidden {
display: none;
}
</style> </style>

3
front/volume/src/components/Channels.svelte

@ -39,7 +39,8 @@
//--------------------------------------------------------------------------------/ //--------------------------------------------------------------------------------/
export let onSelectChannel: (channel: ChannelsType) => void; export let onSelectChannel: (channel: ChannelsType) => void;
const selectChat = (id: number) => { export const selectChat = (id: number) => {
console.log(id);
const channel = channels.find((c) => c.id === id); const channel = channels.find((c) => c.id === id);
if (channel) { if (channel) {
joinChannel(id); joinChannel(id);

Loading…
Cancel
Save