From d529cbf486350dfa8bf3e0d65a0c075479187de4 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Mon, 6 Feb 2023 19:47:53 -0800 Subject: [PATCH] Fix windowId type errors --- .../components/MainWindow/MainContextMenu.tsx | 4 +-- packages/webamp/js/resizeUtils.test.ts | 26 +++++++++---------- packages/webamp/js/resizeUtils.ts | 8 +++--- packages/webamp/js/selectors.ts | 4 ++- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/packages/webamp/js/components/MainWindow/MainContextMenu.tsx b/packages/webamp/js/components/MainWindow/MainContextMenu.tsx index 550b85c8..b091b5a6 100644 --- a/packages/webamp/js/components/MainWindow/MainContextMenu.tsx +++ b/packages/webamp/js/components/MainWindow/MainContextMenu.tsx @@ -6,7 +6,7 @@ import { Hr, Node, Parent, LinkNode } from "../ContextMenu"; import PlaybackContextMenu from "../PlaybackContextMenu"; import OptionsContextMenu from "../OptionsContextMenu"; import SkinsContextMenu from "../SkinsContextMenu"; -import { FilePicker } from "../../types"; +import { FilePicker, WindowId } from "../../types"; import { useTypedSelector, useActionCreator } from "../../hooks"; interface Props { @@ -64,7 +64,7 @@ const MainContextMenu = memo(({ filePickers }: Props) => { key={i} label={genWindows[i].title} checked={genWindows[i].open} - onClick={() => toggleWindow(i)} + onClick={() => toggleWindow(i as WindowId)} hotkey={genWindows[i].hotkey} /> ))} diff --git a/packages/webamp/js/resizeUtils.test.ts b/packages/webamp/js/resizeUtils.test.ts index 23edacc7..614d231f 100644 --- a/packages/webamp/js/resizeUtils.test.ts +++ b/packages/webamp/js/resizeUtils.test.ts @@ -244,9 +244,9 @@ describe("resizeUtils", () => { describe("generateGraph", () => { it("of stacked windows", () => { const actual = generateGraph([ - { key: "a", x: 0, y: 0, width: 100, height: 100 }, - { key: "b", x: 0, y: 100, width: 100, height: 100 }, - { key: "c", x: 0, y: 200, width: 100, height: 100 }, + { key: "main", x: 0, y: 0, width: 100, height: 100 }, + { key: "equalizer", x: 0, y: 100, width: 100, height: 100 }, + { key: "playlist", x: 0, y: 200, width: 100, height: 100 }, ]); expect(actual).toEqual({ a: {}, @@ -256,8 +256,8 @@ describe("generateGraph", () => { }); it("of disconnected windows", () => { const actual = generateGraph([ - { key: "a", x: 0, y: 0, width: 100, height: 100 }, - { key: "b", x: 0, y: 110, width: 100, height: 100 }, + { key: "main", x: 0, y: 0, width: 100, height: 100 }, + { key: "equalizer", x: 0, y: 110, width: 100, height: 100 }, ]); expect(actual).toEqual({ a: {}, @@ -266,8 +266,8 @@ describe("generateGraph", () => { }); it("of windows that touch in y, but the lower one is to the right", () => { const actual = generateGraph([ - { key: "a", x: 0, y: 0, width: 100, height: 100 }, - { key: "b", x: 110, y: 100, width: 100, height: 100 }, + { key: "main", x: 0, y: 0, width: 100, height: 100 }, + { key: "equalizer", x: 110, y: 100, width: 100, height: 100 }, ]); expect(actual).toEqual({ a: {}, @@ -276,8 +276,8 @@ describe("generateGraph", () => { }); it("of windows that touch in y, but the lower one is to the left", () => { const actual = generateGraph([ - { key: "a", x: 110, y: 0, width: 100, height: 100 }, - { key: "b", x: 0, y: 100, width: 100, height: 100 }, + { key: "main", x: 110, y: 0, width: 100, height: 100 }, + { key: "equalizer", x: 0, y: 100, width: 100, height: 100 }, ]); expect(actual).toEqual({ a: {}, @@ -286,8 +286,8 @@ describe("generateGraph", () => { }); it("of windows that touch in x, but the right one is below", () => { const actual = generateGraph([ - { key: "a", x: 0, y: 0, width: 100, height: 100 }, - { key: "b", x: 100, y: 110, width: 100, height: 100 }, + { key: "main", x: 0, y: 0, width: 100, height: 100 }, + { key: "equalizer", x: 100, y: 110, width: 100, height: 100 }, ]); expect(actual).toEqual({ a: {}, @@ -296,8 +296,8 @@ describe("generateGraph", () => { }); it("of windows that touch in x, but the right one is above", () => { const actual = generateGraph([ - { key: "a", x: 0, y: 110, width: 100, height: 100 }, - { key: "b", x: 100, y: 0, width: 100, height: 100 }, + { key: "main", x: 0, y: 110, width: 100, height: 100 }, + { key: "equalizer", x: 100, y: 0, width: 100, height: 100 }, ]); expect(actual).toEqual({ a: {}, diff --git a/packages/webamp/js/resizeUtils.ts b/packages/webamp/js/resizeUtils.ts index d2d4bd9c..7eba1566 100644 --- a/packages/webamp/js/resizeUtils.ts +++ b/packages/webamp/js/resizeUtils.ts @@ -43,7 +43,7 @@ export function getPositionDiff( } } - function walkRight(key: WindowId) { + function walkRight(key: string) { const node = newGraph[key]; const nodeSizeDiff = sizeDiff[key]; node.left.forEach((left) => { @@ -52,7 +52,7 @@ export function getPositionDiff( }); } - function walkDown(key: WindowId) { + function walkDown(key: string) { const node = newGraph[key]; const nodeSizeDiff = sizeDiff[key]; node.above.forEach((above) => { @@ -75,8 +75,8 @@ export function getPositionDiff( } interface Edges { - below?: WindowId; - right?: WindowId; + below?: string; + right?: string; } export interface Graph { diff --git a/packages/webamp/js/selectors.ts b/packages/webamp/js/selectors.ts index f5f240ca..1b6ebebc 100644 --- a/packages/webamp/js/selectors.ts +++ b/packages/webamp/js/selectors.ts @@ -203,7 +203,9 @@ export const getNextTrackId = (state: AppState, n = 1) => { return trackOrder[nextIndex]; }; -export const getGenWindows = (state: AppState) => { +export const getGenWindows = ( + state: AppState +): { [name: string]: WebampWindow } => { return state.windows.genWindows; };