mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-19 17:23:57 +00:00
22 lines
676 B
TypeScript
22 lines
676 B
TypeScript
import { useCallback } from "react";
|
|
import { useAppDispatch, useAppSelector } from "./redux";
|
|
import { setLibrary } from "@renderer/features";
|
|
|
|
export function useLibrary() {
|
|
const dispatch = useAppDispatch();
|
|
const library = useAppSelector((state) => state.library.value);
|
|
|
|
const updateLibrary = useCallback(async () => {
|
|
return window.electron
|
|
.getLibrary()
|
|
.then((updatedLibrary) => dispatch(setLibrary(updatedLibrary)));
|
|
}, [dispatch]);
|
|
|
|
const removeGameFromLibrary = (gameId: number) =>
|
|
window.electron.removeGameFromLibrary(gameId).then(() => {
|
|
updateLibrary();
|
|
});
|
|
|
|
return { library, updateLibrary, removeGameFromLibrary };
|
|
}
|