diff --git a/src/App.vue b/src/App.vue index 8ce5497..c8592d2 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,12 +1,9 @@ diff --git a/src/components/MainMenuBoxes.vue b/src/components/MainMenuBoxes.vue index 68adeac..f4f6c5e 100644 --- a/src/components/MainMenuBoxes.vue +++ b/src/components/MainMenuBoxes.vue @@ -1,40 +1,68 @@ @@ -57,7 +85,7 @@ const navigateTo = (routeName: string) => { { - - Not Logged In + + + diff --git a/src/composables/useWebsocket.ts b/src/composables/useWebsocket.ts index e66860c..6e660d1 100644 --- a/src/composables/useWebsocket.ts +++ b/src/composables/useWebsocket.ts @@ -1,4 +1,4 @@ -import { ref, onMounted, onBeforeUnmount } from "vue"; +import { ref, onMounted, onBeforeUnmount, watch } from "vue"; import { connectWebSocket, disconnectWebSocket, @@ -8,6 +8,7 @@ import { isWebSocketConnected, setDefaultHandler, } from "@/services/ws"; +import { useIngame } from "@/composables/useIngame"; function defaultEventHandler(data: (data: T) => void) { setDefaultHandler(data); @@ -16,15 +17,28 @@ function defaultEventHandler(data: (data: T) => void) { export function useWebSocket() { const isConnected = ref(isWebSocketConnected()); const lastMessage = ref(null); - const lastError = ref(null); + + // Get ingame store to sync connection state + const ig = useIngame(); + + // Watch the ingame store's connection state and keep this composable in sync + watch(() => ig.isWsConnected, (connected) => { + isConnected.value = connected; + }); + + // Also update this composable's state when connecting/disconnecting + const updateConnectionState = (connected: boolean) => { + isConnected.value = connected; + }; async function safeConnect(url?: string) { return connectWebSocket(url) .then(() => { - isConnected.value = true; + updateConnectionState(true); }) .catch((err) => { + updateConnectionState(false); lastError.value = err?.message ?? "Unknown WS error"; throw err; }); diff --git a/src/main.ts b/src/main.ts index 33dc571..6229753 100644 --- a/src/main.ts +++ b/src/main.ts @@ -5,8 +5,9 @@ import App from './App.vue' import router from './router' import Particles from "@tsparticles/vue3"; import { loadFull } from "tsparticles"; -import { Quasar, Notify, QExpansionItem } from 'quasar' +import {Quasar, Notify, QExpansionItem, Dialog, Dark} from 'quasar' import '@quasar/extras/material-icons/material-icons.css' +import '@quasar/extras/bootstrap-icons/bootstrap-icons.css' import 'quasar/dist/quasar.css' import { createPinia } from 'pinia' import axios from 'axios' @@ -25,10 +26,9 @@ initWebSocket(ui); app.use(router) app.use(Quasar, { plugins: { - Notify - }, - components: { - QExpansionItem + Notify, + Dialog, + Dark } }) app.use(VueAxios, axios) diff --git a/src/router/index.ts b/src/router/index.ts index a77a9b4..f8edc5d 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -19,13 +19,13 @@ const router = createRouter({ { path: '/', component: MainMenuView, - meta: { requiresAuth: true }, + meta: { requiresAuth: false }, children: [ { path: '', name: 'mainmenu', component: defaultMenu, - meta: { requiresAuth: true } + meta: { requiresAuth: false } }, { path: 'create', @@ -43,7 +43,7 @@ const router = createRouter({ path: 'rules', name: 'rules-Game', component: rulesView, - meta: {requiresAuth: true } + meta: {requiresAuth: false } }, ], }, @@ -83,19 +83,16 @@ const router = createRouter({ router.beforeEach(async (to, from, next) => { const info = useUserInfo(); const isOnline = navigator.onLine; + if (to.name === 'offline') { if (isOnline) { - try { await info.requestState(); - if (!info.username) { info.clearUserInfo(); return next('/login'); } - return next({ name: 'mainmenu' }); - } catch (err) { info.clearUserInfo(); return next('/login'); @@ -104,28 +101,27 @@ router.beforeEach(async (to, from, next) => { return next(); } } + if (!isOnline) { return next({ name: 'offline' }); } if (!to.meta.requiresAuth) return next(); + try { await info.requestState(); - if (!info.username) { info.clearUserInfo(); return next('/login'); } - if (info.gameId && to.name !== 'game') { return next({ name: 'game' }); } - next(); } catch (err) { - info.clearUserInfo(); - next('/login'); - + console.error("Routing Error", err); + info.clearUserInfo(); + next('/login'); } }); diff --git a/src/views/Game.vue b/src/views/Game.vue index 663301d..13008cd 100644 --- a/src/views/Game.vue +++ b/src/views/Game.vue @@ -25,7 +25,16 @@ ui.requestState().then(() => { router.replace("/") } else { ig.requestGame(ui.gameId).then(() => { - wb.connect() + // Attempt to connect to WebSocket + wb.connect().catch((err) => { + console.error('[Game] Initial WebSocket connection failed:', err); + $q.notify({ + message: 'Failed to connect to game server. Please try reconnecting.', + color: 'negative', + icon: 'error', + timeout: 5000 + }); + }); }) } }) diff --git a/src/views/LoginView.vue b/src/views/LoginView.vue index 6566bba..83da4d5 100644 --- a/src/views/LoginView.vue +++ b/src/views/LoginView.vue @@ -1,95 +1,111 @@ - - - - - - - - - - - - - - - - - - - - - Or continue with: - - - - + + + + + + KnockOut Whist - - + + Welcome Back + + + + + + + + + + + + + + + + + + + + + + Or continue with + + + + + + + + + + Don't have an account? + + - + + - diff --git a/src/views/RegisterView.vue b/src/views/RegisterView.vue index 35d7a6a..171aa4e 100644 --- a/src/views/RegisterView.vue +++ b/src/views/RegisterView.vue @@ -1,124 +1,139 @@ - - - - - - Create Account - - - - - - - - - - - - - - - - - - - - - - Or register with: - - - - + + + + + + KnockOut Whist - - + + Create Account + Join the ultimate card game experience + + + + + + + + + + + + + + + + + + + + + + + + + + + + Or register with + + + + + + + + + + Already have an account? + + - + + - diff --git a/src/views/UsernameSelectionView.vue b/src/views/UsernameSelectionView.vue index 2e2f663..3e2c2e8 100644 --- a/src/views/UsernameSelectionView.vue +++ b/src/views/UsernameSelectionView.vue @@ -1,70 +1,82 @@ - - - - - - Choose Your Username - - You're signed in with {{ userInfo.provider }}. Please choose a username for your account. - - - - - - - {{ userInfo.name?.charAt(0)?.toUpperCase() || 'U' }} - - - {{ userInfo.name || 'Unknown User' }} - Signed in with {{ userInfo.provider }} + + + + + + KnockOut Whist + + + Choose Your Username + + You're signed in with {{ userInfo.providerName }}. Please choose a username for your account. + + + + + + {{ userInfo.name?.charAt(0)?.toUpperCase() || 'U' }} + + + {{ userInfo.name || 'Unknown User' }} + Signed in with {{ userInfo.providerName }} + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - + -
Or continue with:
Or register with:
Join the ultimate card game experience
- You're signed in with {{ userInfo.provider }}. Please choose a username for your account. -
+ You're signed in with {{ userInfo.providerName }}. Please choose a username for your account. +