2022-07-27 23:16:50 +00:00
|
|
|
import { collectionStore } from '$lib/stores/collectionStore';
|
|
|
|
|
import { toast } from '$lib/components/toast/toast';
|
2022-08-08 19:07:44 +00:00
|
|
|
import { ToastType, type GameType, type SavedGameType } from '$lib/types';
|
|
|
|
|
|
2022-08-29 21:41:11 +00:00
|
|
|
function convertToSavedGame(game: GameType | SavedGameType): SavedGameType {
|
2022-08-08 19:07:44 +00:00
|
|
|
return {
|
|
|
|
|
id: game.id,
|
|
|
|
|
name: game.name,
|
2022-08-29 16:33:51 +00:00
|
|
|
thumb_url: game.thumb_url,
|
2022-08-08 19:07:44 +00:00
|
|
|
};
|
|
|
|
|
}
|
2022-07-27 23:16:50 +00:00
|
|
|
|
2022-08-29 21:41:11 +00:00
|
|
|
export function addToCollection(game: GameType | SavedGameType) {
|
2022-08-08 19:07:44 +00:00
|
|
|
collectionStore.add(convertToSavedGame(game));
|
2022-07-29 00:34:34 +00:00
|
|
|
toast.send("Added to collection", { duration: 3000, type: ToastType.INFO });
|
2022-07-27 23:16:50 +00:00
|
|
|
}
|
|
|
|
|
|
2022-08-29 21:41:11 +00:00
|
|
|
export function removeFromCollection(game: GameType | SavedGameType) {
|
2022-07-28 00:05:54 +00:00
|
|
|
collectionStore.remove(game.id);
|
2022-07-29 00:34:34 +00:00
|
|
|
toast.send("Removed from collection", { duration: 3000, type: ToastType.INFO });
|
2022-07-28 00:05:54 +00:00
|
|
|
}
|