From 46a8b19a1ccd07e4143c509e057299b76c9f173f Mon Sep 17 00:00:00 2001 From: Soenke Date: Sun, 14 Sep 2025 03:56:04 +0200 Subject: [PATCH] update --- backend/src/api.js | 7 +- frontend/src/layouts/MainLayout.vue | 6 + .../src/pages/game/createOnlineGamePage.vue | 165 +++++++++++++++++- .../src/pages/game/joinOnlineGamePage.vue | 96 ++++++++++ frontend/src/pages/user/userSettingsPage.vue | 82 ++++++++- frontend/src/pages/user/usernamePage.vue | 2 +- frontend/src/router/routes.js | 1 + 7 files changed, 350 insertions(+), 9 deletions(-) create mode 100644 frontend/src/pages/game/joinOnlineGamePage.vue diff --git a/backend/src/api.js b/backend/src/api.js index 5f36b00..44009f3 100644 --- a/backend/src/api.js +++ b/backend/src/api.js @@ -173,6 +173,7 @@ router.get("/games", async (req, res) => { * is_local: false * current_playing_user: 1 * turn_order: null + * creator: 1 */ router.get("/games/:id", asyncHandler(async (req, res) => { const gameId = parseInt(req.params.id, 10); @@ -182,7 +183,7 @@ router.get("/games/:id", asyncHandler(async (req, res) => { if (!games.length) throw new ApiError(404, "Game not found"); const [creatorRows] = await pool.query( - `SELECT u.id, u.username + `SELECT u.id FROM game_players gp JOIN users u ON gp.user = u.id WHERE gp.game = ? AND gp.is_creator = TRUE @@ -190,7 +191,7 @@ router.get("/games/:id", asyncHandler(async (req, res) => { [gameId] ); - const creator = creatorRows.lenght ? creatorRows[0] : null; + const creator = creatorRows.length ? creatorRows[0].id : null; res.json({ ...games[0], creator}); })); @@ -388,7 +389,7 @@ router.patch("/games/:id/lock", asyncHandler(async (req, res) => { const currentPlayingUser = turnOrder[0]; await conn.query( "UPDATE current_games SET is_open = FALSE, turn_order = ?, current_playing_user = ? WHERE id = ?", - [JSON.stringify(turnOrder), gameId, currentPlayingUser] + [JSON.stringify(turnOrder), currentPlayingUser, gameId] ); await conn.commit(); diff --git a/frontend/src/layouts/MainLayout.vue b/frontend/src/layouts/MainLayout.vue index a5cfd9f..d60bf0e 100644 --- a/frontend/src/layouts/MainLayout.vue +++ b/frontend/src/layouts/MainLayout.vue @@ -73,6 +73,12 @@ + + + Join Online Game + + + Game diff --git a/frontend/src/pages/game/createOnlineGamePage.vue b/frontend/src/pages/game/createOnlineGamePage.vue index f44d972..c3b04dd 100644 --- a/frontend/src/pages/game/createOnlineGamePage.vue +++ b/frontend/src/pages/game/createOnlineGamePage.vue @@ -1,7 +1,168 @@ diff --git a/frontend/src/pages/game/joinOnlineGamePage.vue b/frontend/src/pages/game/joinOnlineGamePage.vue new file mode 100644 index 0000000..83bb3f5 --- /dev/null +++ b/frontend/src/pages/game/joinOnlineGamePage.vue @@ -0,0 +1,96 @@ + + + diff --git a/frontend/src/pages/user/userSettingsPage.vue b/frontend/src/pages/user/userSettingsPage.vue index 94c8caa..4df2a51 100644 --- a/frontend/src/pages/user/userSettingsPage.vue +++ b/frontend/src/pages/user/userSettingsPage.vue @@ -1,7 +1,83 @@ +import { ref } from 'vue' +import { useQuasar, LocalStorage } from 'quasar' +import { useRouter } from 'vue-router' + +const router = useRouter() +const $q = useQuasar(); +const options = ['Dart Picker', 'Numbers'] +const selected = ref('Input method') +const user = ref({ username:"", id:0 }); + +const storedUser = LocalStorage.getItem("user") +if (storedUser) { + console.log(storedUser) + user.value = storedUser +} else { + router.push("/user/username") +} + +function selectOption(opt) { + selected.value = opt +} + +function resetForm () { + $q.notify({ message: 'Changes discarded', color: 'negative' }) +} + +function onSave () { + $q.notify({ message: 'Settings saved', color: 'positive' }) +} + \ No newline at end of file diff --git a/frontend/src/pages/user/usernamePage.vue b/frontend/src/pages/user/usernamePage.vue index f203d1a..1f0621b 100644 --- a/frontend/src/pages/user/usernamePage.vue +++ b/frontend/src/pages/user/usernamePage.vue @@ -75,7 +75,7 @@ async function setUsername() { message: "Success!", }); - router.push("/game/select") + router.push("/") }) .catch(function (error) { diff --git a/frontend/src/router/routes.js b/frontend/src/router/routes.js index 338eac0..9a68643 100644 --- a/frontend/src/router/routes.js +++ b/frontend/src/router/routes.js @@ -15,6 +15,7 @@ const routes = [ { path: 'game/select', component: () => import('pages/game/gameModeSelectPage.vue') }, { path: 'game/local/create', component: () => import('pages/game/createLocalGamePage.vue') }, { path: 'game/online/create', component: () => import('pages/game/createOnlineGamePage.vue') }, + { path: 'game/online/join', component: () => import('pages/game/joinOnlineGamePage.vue') }, { path: 'error', component: () => import('pages/ErrorPage.vue') } ],