boredgame/src/lib/util/manipulateCollection.ts

22 lines
745 B
TypeScript
Raw Normal View History

import { collectionStore } from '$lib/stores/collectionStore';
import { toast } from '$lib/components/toast/toast';
import { ToastType, type GameType, type SavedGameType } from '$lib/types';
2022-08-29 21:41:11 +00:00
function convertToSavedGame(game: GameType | SavedGameType): SavedGameType {
return {
id: game.id,
name: game.name,
thumb_url: game.thumb_url,
};
}
2022-08-29 21:41:11 +00:00
export function addToCollection(game: GameType | SavedGameType) {
collectionStore.add(convertToSavedGame(game));
2022-07-29 00:34:34 +00:00
toast.send("Added to collection", { duration: 3000, type: ToastType.INFO });
}
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
}