52 lines
1.7 KiB
TypeScript
52 lines
1.7 KiB
TypeScript
import { defineStore } from 'pinia';
|
|
import { Game } from "../models/game";
|
|
|
|
export const useAppStore = defineStore('app', {
|
|
state: () => ({
|
|
tags: [] as string[],
|
|
games: [] as Game[],
|
|
selectedTag: null as string | null,
|
|
transitionDirection: 'down' as 'up' | 'down',
|
|
selectedGame: null as Game | null,
|
|
selectedGameIndex: 0,
|
|
qrLink: '' as string
|
|
}),
|
|
getters: {
|
|
filteredGames(state): Game[] {
|
|
return state.games.filter(game => game.tags.includes(state.selectedTag ?? ''));
|
|
}
|
|
},
|
|
actions: {
|
|
moveGameRight() {
|
|
this.selectGame(this.selectedGameIndex + 1);
|
|
},
|
|
moveGameLeft() {
|
|
this.selectGame(this.selectedGameIndex - 1);
|
|
},
|
|
moveTagUp() {
|
|
const index = this.tags.findIndex(t => t === this.selectedTag);
|
|
this.transitionDirection = 'down';
|
|
if (index > 0) this.selectTag(this.tags[index - 1]);
|
|
},
|
|
moveTagDown() {
|
|
const index = this.tags.findIndex(t => t === this.selectedTag);
|
|
this.transitionDirection = 'up';
|
|
if (index < this.tags.length - 1) this.selectTag(this.tags[index + 1]);
|
|
},
|
|
selectGame(index: number) {
|
|
const games = this.filteredGames;
|
|
if (index >= 0 && index < games.length) {
|
|
this.selectedGameIndex = index;
|
|
this.selectedGame = games[index];
|
|
}
|
|
},
|
|
selectTag(tag: string) {
|
|
this.selectedTag = tag;
|
|
this.selectedGameIndex = 0;
|
|
this.selectedGame = this.filteredGames[0] ?? null;
|
|
},
|
|
showQr(link: string) {
|
|
this.qrLink = link;
|
|
}
|
|
}
|
|
}); |