mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-23 01:57:29 +00:00
Type window reducers
This commit is contained in:
parent
378b74e7e1
commit
365935c0b8
2 changed files with 20 additions and 16 deletions
|
|
@ -15,8 +15,9 @@ import {
|
|||
SET_WINDOW_VISIBILITY
|
||||
} from "../actionTypes";
|
||||
|
||||
import { getPositionDiff } from "../resizeUtils";
|
||||
import { getPositionDiff, SizeDiff } from "../resizeUtils";
|
||||
import { applyDiff } from "../snapUtils";
|
||||
import { Action, Dispatchable, WindowId, WindowPositions } from "../types";
|
||||
|
||||
// Dispatch an action and, if needed rearrange the windows to preserve
|
||||
// the existing edge relationship.
|
||||
|
|
@ -24,7 +25,7 @@ import { applyDiff } from "../snapUtils";
|
|||
// Works by checking the edges before the action is dispatched. Then,
|
||||
// after disatching, calculating what position change would be required
|
||||
// to restore those relationships.
|
||||
function withWindowGraphIntegrity(action) {
|
||||
function withWindowGraphIntegrity(action: Action): Dispatchable {
|
||||
return (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const graph = getWindowGraph(state);
|
||||
|
|
@ -33,7 +34,7 @@ function withWindowGraphIntegrity(action) {
|
|||
dispatch(action);
|
||||
|
||||
const newSizes = getWindowSizes(getState());
|
||||
const sizeDiff = {};
|
||||
const sizeDiff: SizeDiff = {};
|
||||
for (const window of Object.keys(newSizes)) {
|
||||
const original = originalSizes[window];
|
||||
const current = newSizes[window];
|
||||
|
|
@ -54,51 +55,56 @@ function withWindowGraphIntegrity(action) {
|
|||
};
|
||||
}
|
||||
|
||||
export function toggleDoubleSizeMode() {
|
||||
export function toggleDoubleSizeMode(): Dispatchable {
|
||||
return withWindowGraphIntegrity({ type: TOGGLE_DOUBLESIZE_MODE });
|
||||
}
|
||||
|
||||
export function toggleEqualizerShadeMode() {
|
||||
export function toggleEqualizerShadeMode(): Dispatchable {
|
||||
return withWindowGraphIntegrity({
|
||||
type: TOGGLE_WINDOW_SHADE_MODE,
|
||||
windowId: "equalizer"
|
||||
});
|
||||
}
|
||||
|
||||
export function toggleMainWindowShadeMode() {
|
||||
export function toggleMainWindowShadeMode(): Dispatchable {
|
||||
return withWindowGraphIntegrity({
|
||||
type: TOGGLE_WINDOW_SHADE_MODE,
|
||||
windowId: "main"
|
||||
});
|
||||
}
|
||||
|
||||
export function togglePlaylistShadeMode() {
|
||||
export function togglePlaylistShadeMode(): Dispatchable {
|
||||
return withWindowGraphIntegrity({
|
||||
type: TOGGLE_WINDOW_SHADE_MODE,
|
||||
windowId: "playlist"
|
||||
});
|
||||
}
|
||||
|
||||
export function closeWindow(windowId) {
|
||||
export function closeWindow(windowId: WindowId): Dispatchable {
|
||||
return { type: CLOSE_WINDOW, windowId };
|
||||
}
|
||||
|
||||
export function hideWindow(windowId) {
|
||||
export function hideWindow(windowId: WindowId): Dispatchable {
|
||||
return { type: SET_WINDOW_VISIBILITY, windowId, hidden: true };
|
||||
}
|
||||
|
||||
export function showWindow(windowId) {
|
||||
export function showWindow(windowId: WindowId): Dispatchable {
|
||||
return { type: SET_WINDOW_VISIBILITY, windowId, hidden: false };
|
||||
}
|
||||
|
||||
export function setWindowSize(windowId, size) {
|
||||
export function setWindowSize(
|
||||
windowId: WindowId,
|
||||
size: [number, number]
|
||||
): Dispatchable {
|
||||
return { type: WINDOW_SIZE_CHANGED, windowId, size };
|
||||
}
|
||||
|
||||
export function toggleWindow(windowId) {
|
||||
export function toggleWindow(windowId: WindowId): Dispatchable {
|
||||
return { type: TOGGLE_WINDOW, windowId };
|
||||
}
|
||||
|
||||
export function updateWindowPositions(positions) {
|
||||
export function updateWindowPositions(
|
||||
positions: WindowPositions
|
||||
): Dispatchable {
|
||||
return { type: UPDATE_WINDOW_POSITIONS, positions };
|
||||
}
|
||||
|
|
@ -14,10 +14,8 @@ interface PositionDiff {
|
|||
};
|
||||
}
|
||||
|
||||
interface SizeDiff {
|
||||
export interface SizeDiff {
|
||||
[key: string]: {
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue