boredgame/src/lib/util/manipulateCollection.ts

26 lines
1,009 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';
import { convertToSavedGame } from './gameMapper';
import { saved_game_schema } from '../zodValidation';
2022-08-29 21:41:11 +00:00
export function addToCollection(game: GameType | SavedGameType) {
try {
saved_game_schema.parse(game);
collectionStore.add(convertToSavedGame(game));
toast.send("Added to collection", { duration: 3000, type: ToastType.INFO });
} catch (error) {
toast.send('Error adding to collection', { duration: 3000, type: ToastType.ERROR });
}
}
2022-08-29 21:41:11 +00:00
export function removeFromCollection(game: GameType | SavedGameType) {
try {
saved_game_schema.parse(game);
collectionStore.remove(game.id);
toast.send("Removed from collection", { duration: 3000, type: ToastType.INFO });
} catch (error) {
toast.send('Error removing from collection', { duration: 3000, type: ToastType.ERROR });
}
2022-07-28 00:05:54 +00:00
}