2022-07-27 00:23:58 +00:00
|
|
|
<script lang="ts">
|
|
|
|
|
import { boredState } from '$lib/stores/boredState';
|
|
|
|
|
import { gameStore } from '$lib/stores/gameSearchStore';
|
|
|
|
|
import { collectionStore } from '$lib/stores/collectionStore';
|
|
|
|
|
import { toast } from '$lib/components/toast/toast';
|
|
|
|
|
import { ToastType } from '$lib/types';
|
|
|
|
|
|
|
|
|
|
function getRandomCollectionGame() {
|
|
|
|
|
if ($collectionStore.length > 0) {
|
|
|
|
|
boredState.set({ loading: true });
|
|
|
|
|
let randomNumber: number = Math.round(Math.random() * $collectionStore.length - 1);
|
|
|
|
|
if ($collectionStore.at(randomNumber)) {
|
|
|
|
|
gameStore.removeAll();
|
2022-07-28 00:05:54 +00:00
|
|
|
gameStore.add($collectionStore.at(randomNumber)!);
|
2022-07-27 00:23:58 +00:00
|
|
|
boredState.set({ loading: false });
|
|
|
|
|
} else {
|
|
|
|
|
toast.send('Error!', { duration: 3000, type: ToastType.ERROR, dismissible: true });
|
|
|
|
|
}
|
|
|
|
|
boredState.set({ loading: false });
|
|
|
|
|
} else {
|
2022-07-28 00:05:54 +00:00
|
|
|
toast.send('No items in your collection!', {
|
|
|
|
|
duration: 3000,
|
|
|
|
|
type: ToastType.ERROR,
|
|
|
|
|
dismissible: true
|
|
|
|
|
});
|
2022-07-27 00:23:58 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
2022-07-28 00:05:54 +00:00
|
|
|
<button class="btn" type="button" on:click={getRandomCollectionGame}
|
|
|
|
|
>Random from collection 🎲</button
|
|
|
|
|
>
|