feat/FRO-36: PWA #25
4481
package-lock.json
generated
4481
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
24
package.json
24
package.json
@@ -2,18 +2,14 @@
|
|||||||
"name": "knockoutwhistfrontend",
|
"name": "knockoutwhistfrontend",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
|
||||||
"engines": {
|
|
||||||
"node": "^20.19.0 || >=22.12.0"
|
|
||||||
},
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
|
||||||
"build": "run-p type-check \"build-only {@}\" --",
|
"build": "run-p type-check \"build-only {@}\" --",
|
||||||
"preview": "vite preview",
|
|
||||||
"build-only": "vite build",
|
|
||||||
"type-check": "vue-tsc --build",
|
|
||||||
"lint": "eslint . --fix --cache",
|
"lint": "eslint . --fix --cache",
|
||||||
"format": "prettier --write --experimental-cli src/"
|
"build-only": "vite build",
|
||||||
|
"dev": "vite",
|
||||||
|
"format": "prettier --write --experimental-cli src/",
|
||||||
|
"preview": "vite preview",
|
||||||
|
"type-check": "vue-tsc --build"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@quasar/extras": "^1.17.0",
|
"@quasar/extras": "^1.17.0",
|
||||||
@@ -22,6 +18,7 @@
|
|||||||
"axios": "^1.13.2",
|
"axios": "^1.13.2",
|
||||||
"pinia": "^3.0.4",
|
"pinia": "^3.0.4",
|
||||||
"quasar": "^2.18.6",
|
"quasar": "^2.18.6",
|
||||||
|
"register-service-worker": "^1.7.2",
|
||||||
"tsparticles": "~3.9.1",
|
"tsparticles": "~3.9.1",
|
||||||
"vue": "^3.5.25",
|
"vue": "^3.5.25",
|
||||||
"vue-axios": "^3.5.2",
|
"vue-axios": "^3.5.2",
|
||||||
@@ -30,7 +27,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@quasar/vite-plugin": "^1.10.0",
|
"@quasar/vite-plugin": "^1.10.0",
|
||||||
"@tsconfig/node24": "^24.0.3",
|
"@tsconfig/node24": "^24.0.3",
|
||||||
"@types/node": "^24.10.1",
|
"@types/node": "^25.0.3",
|
||||||
"@vitejs/plugin-vue": "^6.0.2",
|
"@vitejs/plugin-vue": "^6.0.2",
|
||||||
"@vitejs/plugin-vue-jsx": "^5.1.2",
|
"@vitejs/plugin-vue-jsx": "^5.1.2",
|
||||||
"@vue/eslint-config-prettier": "^10.2.0",
|
"@vue/eslint-config-prettier": "^10.2.0",
|
||||||
@@ -44,7 +41,12 @@
|
|||||||
"sass-embedded": "^1.93.3",
|
"sass-embedded": "^1.93.3",
|
||||||
"typescript": "~5.9.0",
|
"typescript": "~5.9.0",
|
||||||
"vite": "^7.2.4",
|
"vite": "^7.2.4",
|
||||||
|
"vite-plugin-pwa": "^1.2.0",
|
||||||
"vite-plugin-vue-devtools": "^8.0.5",
|
"vite-plugin-vue-devtools": "^8.0.5",
|
||||||
"vue-tsc": "^3.1.5"
|
"vue-tsc": "^3.1.5"
|
||||||
}
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": "^20.19.0 || >=22.12.0"
|
||||||
|
},
|
||||||
|
"type": "module"
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
public/logo192.png
Normal file
BIN
public/logo192.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.0 KiB |
BIN
public/logo512.png
Normal file
BIN
public/logo512.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
17
src/App.vue
17
src/App.vue
@@ -1,5 +1,22 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { RouterView } from 'vue-router'
|
import { RouterView } from 'vue-router'
|
||||||
|
import { onMounted, onUnmounted } from 'vue';
|
||||||
|
import { useRoute } from 'vue-router';
|
||||||
|
const route = useRoute();
|
||||||
|
|
||||||
|
const handleOnlineStatusChange = () => {
|
||||||
|
if (navigator.onLine) {
|
||||||
|
if (route.name === 'offline') {
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
onMounted(() => {
|
||||||
|
window.addEventListener('online', handleOnlineStatusChange);
|
||||||
|
});
|
||||||
|
onUnmounted(() => {
|
||||||
|
window.removeEventListener('online', handleOnlineStatusChange);
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import axios from "axios";
|
|||||||
import { useUserInfo } from "@/composables/useUserInfo";
|
import { useUserInfo } from "@/composables/useUserInfo";
|
||||||
import rulesView from "../components/Rules.vue";
|
import rulesView from "../components/Rules.vue";
|
||||||
import Game from "@/views/Game.vue";
|
import Game from "@/views/Game.vue";
|
||||||
|
import OfflineView from "@/views/OfflineView.vue";
|
||||||
const api = window?.__RUNTIME_CONFIG__?.API_URL;
|
const api = window?.__RUNTIME_CONFIG__?.API_URL;
|
||||||
|
|
||||||
const router = createRouter({
|
const router = createRouter({
|
||||||
@@ -55,12 +56,40 @@ const router = createRouter({
|
|||||||
name: 'game',
|
name: 'game',
|
||||||
component: Game,
|
component: Game,
|
||||||
meta: {requiresAuth: true }
|
meta: {requiresAuth: true }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/offline',
|
||||||
|
name: 'offline',
|
||||||
|
component: OfflineView,
|
||||||
|
meta: {requiresAuth: false }
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
||||||
router.beforeEach(async (to, from, next) => {
|
router.beforeEach(async (to, from, next) => {
|
||||||
const info = useUserInfo();
|
const info = useUserInfo();
|
||||||
|
const isOnline = navigator.onLine;
|
||||||
|
if (to.name === 'offline') {
|
||||||
|
if (isOnline) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await axios.get(`${api}/userInfo`, { withCredentials: true });
|
||||||
|
info.setUserInfo(response.data.username, response.data.userId);
|
||||||
|
|
||||||
|
return next({ name: 'mainmenu' });
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
info.clearUserInfo();
|
||||||
|
return next('/login');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!isOnline) {
|
||||||
|
return next({ name: 'offline' });
|
||||||
|
}
|
||||||
|
|
||||||
if (!to.meta.requiresAuth) return next();
|
if (!to.meta.requiresAuth) return next();
|
||||||
try {
|
try {
|
||||||
await axios.get(`${api}/userInfo`, { withCredentials: true }).then(
|
await axios.get(`${api}/userInfo`, { withCredentials: true }).then(
|
||||||
@@ -72,6 +101,7 @@ router.beforeEach(async (to, from, next) => {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
info.clearUserInfo();
|
info.clearUserInfo();
|
||||||
next('/login');
|
next('/login');
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
132
src/views/OfflineView.vue
Normal file
132
src/views/OfflineView.vue
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, computed } from 'vue'
|
||||||
|
|
||||||
|
type Symbol = '🍎' | '💎' | '🔔' | '🍒' | '🍋' | '⭐' | '❓';
|
||||||
|
const symbols: Symbol[] = ['🍎', '💎', '🔔', '🍒', '🍋', '⭐']
|
||||||
|
|
||||||
|
const reelStates = ref([
|
||||||
|
{ value: '❓' as Symbol, isSpinning: false },
|
||||||
|
{ value: '❓' as Symbol, isSpinning: false },
|
||||||
|
{ value: '❓' as Symbol, isSpinning: false }
|
||||||
|
])
|
||||||
|
|
||||||
|
const globalSpinning = ref(false)
|
||||||
|
const hasSpun = ref(false)
|
||||||
|
|
||||||
|
const isWinner = computed(() => {
|
||||||
|
const [r1, r2, r3] = reelStates.value;
|
||||||
|
return hasSpun.value && !globalSpinning.value &&
|
||||||
|
r1?.value !== '❓' && r1?.value === r2?.value && r2?.value === r3?.value
|
||||||
|
})
|
||||||
|
|
||||||
|
const getRandomSymbol = (): Symbol => symbols[Math.floor(Math.random() * symbols.length)]!
|
||||||
|
|
||||||
|
const spin = (): void => {
|
||||||
|
if (globalSpinning.value) return;
|
||||||
|
|
||||||
|
globalSpinning.value = true;
|
||||||
|
hasSpun.value = false;
|
||||||
|
|
||||||
|
reelStates.value.forEach((reel, index) => {
|
||||||
|
reel.isSpinning = true;
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
reel.value = getRandomSymbol();
|
||||||
|
reel.isSpinning = false;
|
||||||
|
|
||||||
|
if (index === 2) {
|
||||||
|
globalSpinning.value = false;
|
||||||
|
hasSpun.value = true;
|
||||||
|
}
|
||||||
|
}, 1500 + (index * 800));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<q-layout>
|
||||||
|
<q-page-container>
|
||||||
|
<q-page class="flex flex-center">
|
||||||
|
<transition
|
||||||
|
appear
|
||||||
|
tag="div"
|
||||||
|
enter-active-class="animate__animated animate__fadeInDown"
|
||||||
|
leave-active-class="animate__animated animate__fadeOutUp"
|
||||||
|
>
|
||||||
|
<q-card class="slot-machine-card q-pa-lg text-center shadow-10">
|
||||||
|
<div class="text-h4 q-mb-md text-black text-weight-bolder " style="font-family: serif;">Offline Casino</div>
|
||||||
|
|
||||||
|
<div class="row justify-center q-gutter-md q-mb-xl">
|
||||||
|
<div v-for="(reel, index) in reelStates" :key="index" class="reel-container shadow-2">
|
||||||
|
|
||||||
|
<div v-if="reel.isSpinning" class="reel-strip">
|
||||||
|
<div v-for="n in 10" :key="n" class="text-h2">{{ symbols[n % symbols.length] }}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-else class="text-h2 static-symbol">{{ reel.value }}</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="result-box q-mb-md" style="height: 40px;">
|
||||||
|
<div v-if="isWinner" class="text-h5 text-positive text-weight-bold animate-bounce">YOU WIN! (Nothing)</div>
|
||||||
|
<div v-else-if="hasSpun && !globalSpinning" class="text-h6 text-grey-7">Try again!</div>
|
||||||
|
<div v-else class="text-h6 text-grey-7">Try your luck until you are connected!</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<q-btn
|
||||||
|
size="lg" color="light-green"
|
||||||
|
:label="globalSpinning ? 'SPINNING...' : 'SPIN'"
|
||||||
|
:loading="globalSpinning"
|
||||||
|
@click="spin" class="full-width" rounded
|
||||||
|
/>
|
||||||
|
</q-card>
|
||||||
|
</transition>
|
||||||
|
</q-page>
|
||||||
|
</q-page-container>
|
||||||
|
</q-layout>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.slot-machine-card { width: 100%; max-width: 400px; border: 4px solid #2c3e50; border-radius: 20px; }
|
||||||
|
|
||||||
|
.reel-container {
|
||||||
|
background: white;
|
||||||
|
width: 80px;
|
||||||
|
height: 100px;
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
border-radius: 8px;
|
||||||
|
border: 2px solid #ddd;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.reel-strip {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
animation: move-strip 0.3s linear infinite;
|
||||||
|
filter: blur(2px);
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes move-strip {
|
||||||
|
0% { transform: translateY(-50%); }
|
||||||
|
100% { transform: translateY(0); }
|
||||||
|
}
|
||||||
|
|
||||||
|
.static-symbol {
|
||||||
|
animation: land 0.2s ease-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes land {
|
||||||
|
0% { transform: translateY(-40px); opacity: 0; }
|
||||||
|
70% { transform: translateY(10px); }
|
||||||
|
100% { transform: translateY(0); opacity: 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
.animate-bounce { animation: bounce 0.5s infinite alternate; }
|
||||||
|
@keyframes bounce { from { transform: scale(1); } to { transform: scale(1.1); } }
|
||||||
|
</style>
|
||||||
@@ -1,18 +1,55 @@
|
|||||||
import { fileURLToPath, URL } from 'node:url'
|
import { fileURLToPath, URL } from 'node:url'
|
||||||
|
|
||||||
import { defineConfig } from 'vite'
|
import { defineConfig } from 'vite'
|
||||||
import vue from '@vitejs/plugin-vue'
|
import vue from '@vitejs/plugin-vue'
|
||||||
import { quasar, transformAssetUrls } from '@quasar/vite-plugin'
|
|
||||||
import vueJsx from '@vitejs/plugin-vue-jsx'
|
import vueJsx from '@vitejs/plugin-vue-jsx'
|
||||||
import vueDevTools from 'vite-plugin-vue-devtools'
|
import vueDevTools from 'vite-plugin-vue-devtools'
|
||||||
|
import { quasar, transformAssetUrls } from '@quasar/vite-plugin'
|
||||||
|
|
||||||
|
import { VitePWA } from 'vite-plugin-pwa'
|
||||||
|
|
||||||
// https://vite.dev/config/
|
// https://vite.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [
|
plugins: [
|
||||||
vue({ template: { transformAssetUrls } }),
|
vue({
|
||||||
|
template: { transformAssetUrls }
|
||||||
|
}),
|
||||||
vueJsx(),
|
vueJsx(),
|
||||||
vueDevTools(),
|
vueDevTools(),
|
||||||
quasar(),
|
quasar(),
|
||||||
|
VitePWA({
|
||||||
|
registerType: 'autoUpdate',
|
||||||
|
workbox: {
|
||||||
|
globDirectory: 'dist/',
|
||||||
|
globPatterns: [
|
||||||
|
'**/*.{js,css,html,ico,png,svg,webmanifest}',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
|
||||||
|
manifest: {
|
||||||
|
name: 'Knockout Whist PWA',
|
||||||
|
short_name: 'Whist PWA',
|
||||||
|
description: 'The Knockout Whist card game as a Progressive Web App.',
|
||||||
|
theme_color: '#4A4A4A',
|
||||||
|
background_color: '#ffffff',
|
||||||
|
display: 'standalone',
|
||||||
|
icons: [
|
||||||
|
{
|
||||||
|
src: 'logo192.png',
|
||||||
|
sizes: '192x192',
|
||||||
|
type: 'image/png'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
src: 'logo512.png',
|
||||||
|
sizes: '512x512',
|
||||||
|
type: 'image/png'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
devOptions: {
|
||||||
|
enabled: true,
|
||||||
|
type: 'module',
|
||||||
|
}
|
||||||
|
})
|
||||||
],
|
],
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
|
|||||||
Reference in New Issue
Block a user