sendou.ink/app/hooks/usePlannerBg.ts
Kalle fd48bced91
Migrate Prettier/Eslint/Stylelint setup to Biome (#1772)
* Initial

* CSS lint

* Test CI

* Add 1v1, 2v2, and 3v3 Tags (#1771)

* Initial

* CSS lint

* Test CI

* Rename step

---------

Co-authored-by: xi <104683822+ximk@users.noreply.github.com>
2024-06-24 13:07:17 +03:00

43 lines
1.1 KiB
TypeScript

import { useEffect, useState } from "react";
import { useWindowSize } from "react-use";
type PlannerBgParams = {
bgWidth: number;
bgHeight: number;
pointOffsetX: number;
pointOffsetY: number;
};
// Dynamic background size. See this issue for more info: https://github.com/Sendouc/sendou.ink/issues/1161
const bgSizeFactor = 0.8;
export function usePlannerBg() {
const [plannerBgParams, setPlannerBgParams] = useState<PlannerBgParams>({
bgWidth: 1200,
bgHeight: 800,
pointOffsetX: 240,
pointOffsetY: 96,
});
// Natively available WindowSize hook: https://usehooks-ts.com/react-hook/use-window-size
const windowSize = useWindowSize();
useEffect(() => {
const bgWidth = windowSize.width * bgSizeFactor;
const bgHeight = windowSize.height * bgSizeFactor;
// Point offsets that move the image closer to the center of the window
const pointOffsetX = bgWidth * (1 - bgSizeFactor);
const pointOffsetY = 0.6 * (bgHeight * (1 - bgSizeFactor)); // Removes some dead space above the image
setPlannerBgParams({
bgWidth,
bgHeight,
pointOffsetX,
pointOffsetY,
});
}, [windowSize.width, windowSize.height]);
return plannerBgParams;
}