mirror of
https://github.com/rommapp/romm.git
synced 2026-12-03 10:33:22 +01:00
add random game to views
This commit is contained in:
@@ -5,6 +5,7 @@ import FilterDrawer from "@/components/Gallery/AppBar/common/FilterDrawer/Base.v
|
||||
import SelectingBtn from "@/components/Gallery/AppBar/common/SelectingBtn.vue";
|
||||
import GalleryViewBtn from "@/components/Gallery/AppBar/common/GalleryViewBtn.vue";
|
||||
import CharIndexBar from "@/components/Gallery/AppBar/common/CharIndexBar.vue";
|
||||
import ContextualRandomBtn from "@/components/Gallery/AppBar/common/ContextualRandomBtn.vue";
|
||||
import { calculateMainLayoutWidth } from "@/utils";
|
||||
|
||||
// Props
|
||||
@@ -39,6 +40,7 @@ const { calculatedWidth } = calculateMainLayoutWidth();
|
||||
<template #append>
|
||||
<selecting-btn />
|
||||
<gallery-view-btn />
|
||||
<contextual-random-btn />
|
||||
<slot name="append" />
|
||||
</template>
|
||||
</v-app-bar>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import BaseGalleryAppBar from "@/components/Gallery/AppBar/Base.vue";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<base-gallery-app-bar show-platforms-filter show-search-bar />
|
||||
</template>
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
<script setup lang="ts">
|
||||
import romApi from "@/services/api/rom";
|
||||
import storeGalleryFilter from "@/stores/galleryFilter";
|
||||
import storeRoms from "@/stores/roms";
|
||||
import type { Platform } from "@/stores/platforms";
|
||||
import type { Collection, VirtualCollection } from "@/stores/collections";
|
||||
import type { Events } from "@/types/emitter";
|
||||
import type { Emitter } from "mitt";
|
||||
import { inject } from "vue";
|
||||
import { useRouter } from "vue-router";
|
||||
import { ROUTES } from "@/plugins/router";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { useI18n } from "vue-i18n";
|
||||
|
||||
const { t } = useI18n();
|
||||
const router = useRouter();
|
||||
const emitter = inject<Emitter<Events>>("emitter");
|
||||
const galleryFilterStore = storeGalleryFilter();
|
||||
const romsStore = storeRoms();
|
||||
const { currentPlatform, currentCollection, currentVirtualCollection } =
|
||||
storeToRefs(romsStore);
|
||||
|
||||
const {
|
||||
searchTerm,
|
||||
filterUnmatched,
|
||||
filterMatched,
|
||||
filterFavourites,
|
||||
filterDuplicates,
|
||||
filterPlayables,
|
||||
filterRA,
|
||||
filterMissing,
|
||||
filterVerified,
|
||||
selectedGenre,
|
||||
selectedFranchise,
|
||||
selectedCollection,
|
||||
selectedCompany,
|
||||
selectedAgeRating,
|
||||
selectedStatus,
|
||||
selectedRegion,
|
||||
selectedLanguage,
|
||||
} = storeToRefs(galleryFilterStore);
|
||||
|
||||
async function goToRandomGame() {
|
||||
try {
|
||||
const apiParams = {
|
||||
limit: 1,
|
||||
offset: 0,
|
||||
platformId: currentPlatform.value?.id || null,
|
||||
collectionId: currentCollection.value?.id || null,
|
||||
virtualCollectionId: currentVirtualCollection.value?.id || null,
|
||||
searchTerm:
|
||||
searchTerm.value && searchTerm.value.trim()
|
||||
? searchTerm.value.trim()
|
||||
: null,
|
||||
filterUnmatched: filterUnmatched.value,
|
||||
filterMatched: filterMatched.value,
|
||||
filterFavourites: filterFavourites.value,
|
||||
filterDuplicates: filterDuplicates.value,
|
||||
filterPlayables: filterPlayables.value,
|
||||
filterRA: filterRA.value,
|
||||
filterMissing: filterMissing.value,
|
||||
filterVerified: filterVerified.value,
|
||||
selectedGenre: selectedGenre.value,
|
||||
selectedFranchise: selectedFranchise.value,
|
||||
selectedCollection: selectedCollection.value,
|
||||
selectedCompany: selectedCompany.value,
|
||||
selectedAgeRating: selectedAgeRating.value,
|
||||
selectedStatus: selectedStatus.value,
|
||||
selectedRegion: selectedRegion.value,
|
||||
selectedLanguage: selectedLanguage.value,
|
||||
};
|
||||
|
||||
// Get the total count first
|
||||
const { data: romsResponse } = await romApi.getRoms(apiParams);
|
||||
|
||||
if (!romsResponse.total || romsResponse.total === 0) {
|
||||
emitter?.emit("snackbarShow", {
|
||||
msg: "No games found",
|
||||
icon: "mdi-information",
|
||||
color: "info",
|
||||
timeout: 3000,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Get a random offset between 0 and total-1
|
||||
const randomOffset = Math.floor(Math.random() * romsResponse.total);
|
||||
const { data: randomRomResponse } = await romApi.getRoms({
|
||||
...apiParams,
|
||||
offset: randomOffset,
|
||||
});
|
||||
|
||||
if (randomRomResponse.items.length > 0) {
|
||||
const randomRom = randomRomResponse.items[0];
|
||||
router.push({ name: ROUTES.ROM, params: { rom: randomRom.id } });
|
||||
} else {
|
||||
emitter?.emit("snackbarShow", {
|
||||
msg: "Could not find a random game",
|
||||
icon: "mdi-alert",
|
||||
color: "warning",
|
||||
timeout: 3000,
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error fetching random game:", error);
|
||||
emitter?.emit("snackbarShow", {
|
||||
msg: "Error finding random game",
|
||||
icon: "mdi-close-circle",
|
||||
color: "red",
|
||||
timeout: 4000,
|
||||
});
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<v-btn
|
||||
icon
|
||||
variant="text"
|
||||
color="text-white"
|
||||
:disabled="romsStore.filteredRoms.length === 0"
|
||||
rounded="0"
|
||||
@click="goToRandomGame"
|
||||
:title="t('common.random')"
|
||||
class="bg-surface ma-0"
|
||||
>
|
||||
<v-icon>mdi-shuffle-variant</v-icon>
|
||||
</v-btn>
|
||||
</template>
|
||||
@@ -77,7 +77,7 @@ async function goToRandomGame() {
|
||||
icon
|
||||
:block="block"
|
||||
variant="flat"
|
||||
color="background"
|
||||
color="text-white"
|
||||
:height="height"
|
||||
:class="{ rounded: rounded }"
|
||||
class="py-4 bg-background d-flex align-center justify-center"
|
||||
@@ -86,7 +86,9 @@ async function goToRandomGame() {
|
||||
<div class="d-flex flex-column align-center">
|
||||
<v-icon>mdi-shuffle-variant</v-icon>
|
||||
<v-expand-transition>
|
||||
<span v-if="withTag" class="text-caption text-center"> Random </span>
|
||||
<span v-if="withTag" class="text-caption text-center">
|
||||
{{ $t("common.random") }}
|
||||
</span>
|
||||
</v-expand-transition>
|
||||
</div>
|
||||
</v-btn>
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
"platforms-n": "{n} Plattform | {n} Plattformen",
|
||||
"platforms-size": "Größe pro Plattform",
|
||||
"profile": "Profil",
|
||||
"random": "Zufällig",
|
||||
"required": "Erforderlich",
|
||||
"invalid-name": "Ungültiger Name",
|
||||
"invalid-email": "Ungültige E-Mail",
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
"platforms-n": "{n} Platform | {n} Platforms",
|
||||
"platforms-size": "Size per platform",
|
||||
"profile": "Profile",
|
||||
"random": "Random",
|
||||
"required": "Required",
|
||||
"invalid-name": "Invalid name",
|
||||
"invalid-email": "Invalid email",
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
"platforms-n": "{n} Platform | {n} Platforms",
|
||||
"platforms-size": "Size per platform",
|
||||
"profile": "Profile",
|
||||
"random": "Random",
|
||||
"required": "Required",
|
||||
"invalid-name": "Invalid name",
|
||||
"invalid-email": "Invalid email",
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
"platforms-n": "{n} Plataforma | {n} Plataformas",
|
||||
"platforms-size": "Tamaño por plataforma",
|
||||
"profile": "Perfil",
|
||||
"random": "Aleatorio",
|
||||
"required": "Requerido",
|
||||
"invalid-name": "Nombre inválido",
|
||||
"invalid-email": "Correo electrónico inválido",
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
"platforms-n": "{n} Plateforme | {n} Plateformes",
|
||||
"platforms-size": "Taille par plateforme",
|
||||
"profile": "Profil",
|
||||
"random": "Aléatoire",
|
||||
"required": "Requis",
|
||||
"invalid-name": "Nom invalide",
|
||||
"invalid-email": "E-mail invalide",
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
"platforms-n": "{n} Piattaforma | {n} Piattaforme",
|
||||
"platforms-size": "Dimensione per piattaforma",
|
||||
"profile": "Profilo",
|
||||
"random": "Casuale",
|
||||
"required": "Obbligatorio",
|
||||
"invalid-name": "Nome non valido",
|
||||
"invalid-email": "Email non valida",
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
"platforms-n": "{n} プラットフォーム | {n} プラットフォームs",
|
||||
"platforms-size": "プラットフォームごとのサイズ",
|
||||
"profile": "プロファイル",
|
||||
"random": "ランダム",
|
||||
"required": "必須",
|
||||
"invalid-name": "無効な名前",
|
||||
"invalid-email": "無効なメールアドレス",
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
"platforms-n": "{n}가지 플랫폼 | {n}가지 플랫폼",
|
||||
"platforms-size": "플랫폼별 크기",
|
||||
"profile": "프로필",
|
||||
"random": "무작위",
|
||||
"required": "필수",
|
||||
"invalid-name": "유효하지 않은 이름",
|
||||
"invalid-email": "유효하지 않은 이메일",
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
"platforms-n": "{n} Plataforma | {n} Plataformas",
|
||||
"platforms-size": "Tamanho por plataforma",
|
||||
"profile": "Perfil",
|
||||
"random": "Aleatório",
|
||||
"required": "Requerido",
|
||||
"invalid-name": "Nome inválido",
|
||||
"invalid-email": "Email inválido",
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
"platforms-n": "{n} Platformă | {n} Platforme",
|
||||
"platforms-size": "Dimensiune per platformă",
|
||||
"profile": "Profil",
|
||||
"random": "Aleatoriu",
|
||||
"required": "Obligatoriu",
|
||||
"invalid-name": "Nume invalid",
|
||||
"invalid-email": "Email invalid",
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
"platforms-n": "{n} Платформа | {n} Платформы",
|
||||
"platforms-size": "Размер по платформе",
|
||||
"profile": "Профиль",
|
||||
"random": "Случайный",
|
||||
"required": "Обязательное поле",
|
||||
"invalid-name": "Недопустимое имя",
|
||||
"invalid-email": "Недопустимый адрес электронной почты",
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
"platforms-n": "{n} 平台 | {n} 平台",
|
||||
"platforms-size": "每个平台的大小",
|
||||
"profile": "简介",
|
||||
"random": "随机",
|
||||
"required": "必填",
|
||||
"invalid-name": "无效的名称",
|
||||
"invalid-email": "无效的电子邮件",
|
||||
|
||||
Reference in New Issue
Block a user