|
@ -21,7 +21,7 @@ |
|
|
import MatchHistory from "./components/MatchHistory.svelte"; |
|
|
import MatchHistory from "./components/MatchHistory.svelte"; |
|
|
import Friends, { addFriend } from "./components/Friends.svelte"; |
|
|
import Friends, { addFriend } from "./components/Friends.svelte"; |
|
|
import Chat from "./components/Chat.svelte"; |
|
|
import Chat from "./components/Chat.svelte"; |
|
|
import Channels from "./components/Channels.svelte"; |
|
|
import Channels, { formatChannelNames } from "./components/Channels.svelte"; |
|
|
import Leaderboard from "./components/Leaderboard.svelte"; |
|
|
import Leaderboard from "./components/Leaderboard.svelte"; |
|
|
|
|
|
|
|
|
import Pong from "./components/Pong/Pong.svelte"; |
|
|
import Pong from "./components/Pong/Pong.svelte"; |
|
@ -34,18 +34,16 @@ |
|
|
// Single Page Application config |
|
|
// Single Page Application config |
|
|
let appState: string = APPSTATE.HOME; |
|
|
let appState: string = APPSTATE.HOME; |
|
|
|
|
|
|
|
|
function updateChat() { |
|
|
async function updateChat() { |
|
|
const urlSplit = appState.split("#", 2) |
|
|
const urlSplit = appState.split("#", 2) |
|
|
if (urlSplit && urlSplit.length > 1) { |
|
|
|
|
|
console.log(urlSplit[1]) |
|
|
|
|
|
} |
|
|
|
|
|
if (appState.includes(APPSTATE.CHANNELS) && urlSplit.length > 1) { |
|
|
if (appState.includes(APPSTATE.CHANNELS) && urlSplit.length > 1) { |
|
|
const currentChannelName = appState.split("#", 2)[1]; |
|
|
const currentChannelName = appState.split("#", 2)[1]; |
|
|
fetch(API_URL + "/channels", { |
|
|
fetch(API_URL + "/channels", { |
|
|
credentials: "include", |
|
|
credentials: "include", |
|
|
mode: "cors", |
|
|
mode: "cors", |
|
|
}).then((res) => { |
|
|
}).then((res) => { |
|
|
res.json().then((channels) => { |
|
|
res.json().then(async (channels) => { |
|
|
|
|
|
await formatChannelNames(channels); |
|
|
const channel = channels.find((c: ChannelsType) => c.name === currentChannelName); |
|
|
const channel = channels.find((c: ChannelsType) => c.name === currentChannelName); |
|
|
if (channel) { |
|
|
if (channel) { |
|
|
chan.selectChat(channel.id); |
|
|
chan.selectChat(channel.id); |
|
@ -63,7 +61,7 @@ |
|
|
window.onpopstate = (e: PopStateEvent) => { |
|
|
window.onpopstate = (e: PopStateEvent) => { |
|
|
if (e.state) { |
|
|
if (e.state) { |
|
|
appState = e.state.appState; |
|
|
appState = e.state.appState; |
|
|
updateChat(); |
|
|
void updateChat(); |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
@ -75,7 +73,7 @@ |
|
|
if (newState === appState) return; |
|
|
if (newState === appState) return; |
|
|
appState = newState; |
|
|
appState = newState; |
|
|
history.pushState({ appState }, "", appState); |
|
|
history.pushState({ appState }, "", appState); |
|
|
updateChat(); |
|
|
void updateChat(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
onMount(() => { |
|
|
onMount(() => { |
|
@ -105,7 +103,8 @@ |
|
|
|
|
|
|
|
|
let chan: Channels; |
|
|
let chan: Channels; |
|
|
async function openDirectChat(event: CustomEvent<string>) { |
|
|
async function openDirectChat(event: CustomEvent<string>) { |
|
|
const DMUsername = event.detail; |
|
|
const DMUsername = "test"; |
|
|
|
|
|
// const DMUsername = event.detail; |
|
|
let DMChannel: Array<ChannelsType> = []; |
|
|
let DMChannel: Array<ChannelsType> = []; |
|
|
const res = await getDMs($store.username) |
|
|
const res = await getDMs($store.username) |
|
|
if (res.ok) { |
|
|
if (res.ok) { |
|
|