mirror of
https://github.com/captbaritone/webamp.git
synced 2026-01-23 02:15:01 +00:00
Inline action types
This commit is contained in:
parent
aa7ea12b41
commit
48ef4eeff2
11 changed files with 96 additions and 268 deletions
|
|
@ -1,11 +1,4 @@
|
|||
import { BANDS } from "../constants";
|
||||
|
||||
import {
|
||||
SET_EQ_ON,
|
||||
SET_EQ_OFF,
|
||||
SET_BAND_VALUE,
|
||||
SET_EQ_AUTO,
|
||||
} from "../actionTypes";
|
||||
import { Band, Thunk, Action } from "../types";
|
||||
|
||||
const BAND_SNAP_DISTANCE = 5;
|
||||
|
|
@ -22,14 +15,14 @@ function _snapBandValue(value: number): number {
|
|||
}
|
||||
|
||||
export function setEqBand(band: Band, value: number): Action {
|
||||
return { type: SET_BAND_VALUE, band, value: _snapBandValue(value) };
|
||||
return { type: "SET_BAND_VALUE", band, value: _snapBandValue(value) };
|
||||
}
|
||||
|
||||
function _setEqTo(value: number): Thunk {
|
||||
return (dispatch) => {
|
||||
Object.values(BANDS).forEach((band) => {
|
||||
dispatch({
|
||||
type: SET_BAND_VALUE,
|
||||
type: "SET_BAND_VALUE",
|
||||
value,
|
||||
band: band,
|
||||
});
|
||||
|
|
@ -50,15 +43,19 @@ export function setEqToMin(): Thunk {
|
|||
}
|
||||
|
||||
export function setPreamp(value: number): Action {
|
||||
return { type: SET_BAND_VALUE, band: "preamp", value: _snapBandValue(value) };
|
||||
return {
|
||||
type: "SET_BAND_VALUE",
|
||||
band: "preamp",
|
||||
value: _snapBandValue(value),
|
||||
};
|
||||
}
|
||||
|
||||
export function toggleEq(): Thunk {
|
||||
return (dispatch, getState) => {
|
||||
if (getState().equalizer.on) {
|
||||
dispatch({ type: SET_EQ_OFF });
|
||||
dispatch({ type: "SET_EQ_OFF" });
|
||||
} else {
|
||||
dispatch({ type: SET_EQ_ON });
|
||||
dispatch({ type: "SET_EQ_ON" });
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -67,6 +64,6 @@ export function toggleEqAuto(): Thunk {
|
|||
return (dispatch) => {
|
||||
// We don't actually support this feature yet so don't let the user ever turn it on.
|
||||
// dispatch({ type: SET_EQ_AUTO, value: !getState().equalizer.auto });
|
||||
dispatch({ type: SET_EQ_AUTO, value: false });
|
||||
dispatch({ type: "SET_EQ_AUTO", value: false });
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,18 +18,6 @@ import {
|
|||
getPlaylistURL,
|
||||
} from "../selectors";
|
||||
|
||||
import {
|
||||
ADD_TRACK_FROM_URL,
|
||||
PLAY_TRACK,
|
||||
BUFFER_TRACK,
|
||||
SET_MEDIA_TAGS,
|
||||
SET_MEDIA_DURATION,
|
||||
MEDIA_TAG_REQUEST_INITIALIZED,
|
||||
MEDIA_TAG_REQUEST_FAILED,
|
||||
SET_SKIN_DATA,
|
||||
LOADED,
|
||||
LOADING,
|
||||
} from "../actionTypes";
|
||||
import LoadQueue from "../loadQueue";
|
||||
|
||||
import { removeAllTracks } from "./playlist";
|
||||
|
|
@ -93,20 +81,20 @@ export function setSkinFromBlob(blob: Blob | Promise<Blob>): Thunk {
|
|||
alert("Webamp has not been configured to support custom skins.");
|
||||
return;
|
||||
}
|
||||
dispatch({ type: LOADING });
|
||||
dispatch({ type: "LOADING" });
|
||||
let JSZip;
|
||||
try {
|
||||
JSZip = await requireJSZip();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
dispatch({ type: LOADED });
|
||||
dispatch({ type: "LOADED" });
|
||||
alert("Failed to load the skin parser.");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const skinData = await skinParser(blob, JSZip);
|
||||
dispatch({
|
||||
type: SET_SKIN_DATA,
|
||||
type: "SET_SKIN_DATA",
|
||||
data: {
|
||||
skinImages: skinData.images,
|
||||
skinColors: skinData.colors,
|
||||
|
|
@ -119,7 +107,7 @@ export function setSkinFromBlob(blob: Blob | Promise<Blob>): Thunk {
|
|||
});
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
dispatch({ type: LOADED });
|
||||
dispatch({ type: "LOADED" });
|
||||
alert(`Failed to parse skin`);
|
||||
}
|
||||
};
|
||||
|
|
@ -127,7 +115,7 @@ export function setSkinFromBlob(blob: Blob | Promise<Blob>): Thunk {
|
|||
|
||||
export function setSkinFromUrl(url: string): Thunk {
|
||||
return async (dispatch) => {
|
||||
dispatch({ type: LOADING });
|
||||
dispatch({ type: "LOADING" });
|
||||
try {
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) {
|
||||
|
|
@ -136,7 +124,7 @@ export function setSkinFromUrl(url: string): Thunk {
|
|||
dispatch(setSkinFromBlob(response.blob()));
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
dispatch({ type: LOADED });
|
||||
dispatch({ type: "LOADED" });
|
||||
alert(`Failed to download skin from ${url}`);
|
||||
}
|
||||
};
|
||||
|
|
@ -179,7 +167,7 @@ export function fetchMediaDuration(url: string, id: number): Thunk {
|
|||
async () => {
|
||||
try {
|
||||
const duration = await genMediaDuration(url);
|
||||
dispatch({ type: SET_MEDIA_DURATION, duration, id });
|
||||
dispatch({ type: "SET_MEDIA_DURATION", duration, id });
|
||||
} catch (e) {
|
||||
// TODO: Should we update the state to indicate that we don't know the length?
|
||||
}
|
||||
|
|
@ -250,7 +238,7 @@ export function loadMediaFile(
|
|||
}
|
||||
|
||||
dispatch({
|
||||
type: ADD_TRACK_FROM_URL,
|
||||
type: "ADD_TRACK_FROM_URL",
|
||||
url: canonicalUrl,
|
||||
duration: track.duration,
|
||||
defaultName,
|
||||
|
|
@ -259,17 +247,17 @@ export function loadMediaFile(
|
|||
});
|
||||
switch (priority) {
|
||||
case LOAD_STYLE.BUFFER:
|
||||
dispatch({ type: BUFFER_TRACK, id });
|
||||
dispatch({ type: "BUFFER_TRACK", id });
|
||||
break;
|
||||
case LOAD_STYLE.PLAY:
|
||||
dispatch({ type: PLAY_TRACK, id });
|
||||
dispatch({ type: "PLAY_TRACK", id });
|
||||
break;
|
||||
case LOAD_STYLE.NONE:
|
||||
default:
|
||||
// If we're not going to load this right away,
|
||||
// we should set duration on our own
|
||||
if (duration != null) {
|
||||
dispatch({ type: SET_MEDIA_DURATION, duration, id });
|
||||
dispatch({ type: "SET_MEDIA_DURATION", duration, id });
|
||||
} else {
|
||||
dispatch(fetchMediaDuration(canonicalUrl, id));
|
||||
}
|
||||
|
|
@ -278,7 +266,7 @@ export function loadMediaFile(
|
|||
if (metaData != null) {
|
||||
const { artist, title, album } = metaData;
|
||||
dispatch({
|
||||
type: SET_MEDIA_TAGS,
|
||||
type: "SET_MEDIA_TAGS",
|
||||
artist,
|
||||
title,
|
||||
album,
|
||||
|
|
@ -316,7 +304,7 @@ function queueFetchingMediaTags(id: number): Thunk {
|
|||
|
||||
export function fetchMediaTags(file: string | Blob, id: number): Thunk {
|
||||
return async (dispatch, getState, { requireMusicMetadata }) => {
|
||||
dispatch({ type: MEDIA_TAG_REQUEST_INITIALIZED, id });
|
||||
dispatch({ type: "MEDIA_TAG_REQUEST_INITIALIZED", id });
|
||||
|
||||
try {
|
||||
const metadata = await genMediaTags(file, await requireMusicMetadata());
|
||||
|
|
@ -330,7 +318,7 @@ export function fetchMediaTags(file: string | Blob, id: number): Thunk {
|
|||
albumArtUrl = URL.createObjectURL(blob);
|
||||
}
|
||||
dispatch({
|
||||
type: SET_MEDIA_TAGS,
|
||||
type: "SET_MEDIA_TAGS",
|
||||
artist: artist ? artist : "",
|
||||
title: title ? title : "",
|
||||
album,
|
||||
|
|
@ -341,7 +329,7 @@ export function fetchMediaTags(file: string | Blob, id: number): Thunk {
|
|||
id,
|
||||
});
|
||||
} catch (e) {
|
||||
dispatch({ type: MEDIA_TAG_REQUEST_FAILED, id });
|
||||
dispatch({ type: "MEDIA_TAG_REQUEST_FAILED", id });
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,3 @@
|
|||
import {
|
||||
CLOSE_WINAMP,
|
||||
OPEN_WINAMP,
|
||||
STOP,
|
||||
TOGGLE_VISUALIZER_STYLE,
|
||||
CLOSE_REQUESTED,
|
||||
MINIMIZE_WINAMP,
|
||||
SET_FOCUS,
|
||||
UNSET_FOCUS,
|
||||
LOAD_SERIALIZED_STATE,
|
||||
LOAD_DEFAULT_SKIN,
|
||||
SET_MILKDROP_DESKTOP,
|
||||
SET_MILKDROP_FULLSCREEN,
|
||||
TOGGLE_PRESET_OVERLAY,
|
||||
STEP_MARQUEE,
|
||||
SET_BAND_FOCUS,
|
||||
} from "../actionTypes";
|
||||
import { WINDOWS } from "../constants";
|
||||
import { Thunk, Action, Slider } from "../types";
|
||||
import { SerializedStateV1 } from "../serializedStates/v1Types";
|
||||
|
|
@ -131,36 +114,36 @@ export function close(): Thunk {
|
|||
const cancel = () => {
|
||||
defaultPrevented = true;
|
||||
};
|
||||
dispatch({ type: CLOSE_REQUESTED, cancel });
|
||||
dispatch({ type: "CLOSE_REQUESTED", cancel });
|
||||
if (!defaultPrevented) {
|
||||
dispatch({ type: STOP });
|
||||
dispatch({ type: CLOSE_WINAMP });
|
||||
dispatch({ type: "STOP" });
|
||||
dispatch({ type: "CLOSE_WINAMP" });
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function open(): Action {
|
||||
return { type: OPEN_WINAMP };
|
||||
return { type: "OPEN_WINAMP" };
|
||||
}
|
||||
|
||||
export function toggleVisualizerStyle(): Action {
|
||||
return { type: TOGGLE_VISUALIZER_STYLE };
|
||||
return { type: "TOGGLE_VISUALIZER_STYLE" };
|
||||
}
|
||||
|
||||
export function minimize(): Action {
|
||||
return { type: MINIMIZE_WINAMP };
|
||||
return { type: "MINIMIZE_WINAMP" };
|
||||
}
|
||||
|
||||
export function setFocus(input: string): Action {
|
||||
return { type: SET_FOCUS, input };
|
||||
return { type: "SET_FOCUS", input };
|
||||
}
|
||||
|
||||
export function unsetFocus(): Action {
|
||||
return { type: UNSET_FOCUS };
|
||||
return { type: "UNSET_FOCUS" };
|
||||
}
|
||||
|
||||
export function focusBand(band: Slider): Action {
|
||||
return { type: SET_BAND_FOCUS, input: "eq", bandFocused: band };
|
||||
return { type: "SET_BAND_FOCUS", input: "eq", bandFocused: band };
|
||||
}
|
||||
|
||||
export function loadSerializedState(
|
||||
|
|
@ -168,27 +151,27 @@ export function loadSerializedState(
|
|||
serializedState: SerializedStateV1
|
||||
): Thunk {
|
||||
return (dispatch) => {
|
||||
dispatch({ type: LOAD_SERIALIZED_STATE, serializedState });
|
||||
dispatch({ type: "LOAD_SERIALIZED_STATE", serializedState });
|
||||
dispatch(ensureWindowsAreOnScreen());
|
||||
};
|
||||
}
|
||||
|
||||
export function loadDefaultSkin(): Action {
|
||||
return { type: LOAD_DEFAULT_SKIN };
|
||||
return { type: "LOAD_DEFAULT_SKIN" };
|
||||
}
|
||||
|
||||
export function toggleMilkdropDesktop(): Thunk {
|
||||
return (dispatch, getState) => {
|
||||
if (Selectors.getMilkdropDesktopEnabled(getState())) {
|
||||
dispatch({ type: SET_MILKDROP_DESKTOP, enabled: false });
|
||||
dispatch({ type: "SET_MILKDROP_DESKTOP", enabled: false });
|
||||
} else {
|
||||
dispatch({ type: SET_MILKDROP_DESKTOP, enabled: true });
|
||||
dispatch({ type: "SET_MILKDROP_DESKTOP", enabled: true });
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function setMilkdropFullscreen(enabled: boolean): Action {
|
||||
return { type: SET_MILKDROP_FULLSCREEN, enabled };
|
||||
return { type: "SET_MILKDROP_FULLSCREEN", enabled };
|
||||
}
|
||||
export function toggleMilkdropFullscreen(): Thunk {
|
||||
return (dispatch, getState) => {
|
||||
|
|
@ -204,10 +187,10 @@ export function togglePresetOverlay(): Thunk {
|
|||
dispatch(setFocusedWindow(WINDOWS.MILKDROP));
|
||||
}
|
||||
|
||||
dispatch({ type: TOGGLE_PRESET_OVERLAY });
|
||||
dispatch({ type: "TOGGLE_PRESET_OVERLAY" });
|
||||
};
|
||||
}
|
||||
|
||||
export function stepMarquee(): Action {
|
||||
return { type: STEP_MARQUEE };
|
||||
return { type: "STEP_MARQUEE" };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,4 @@
|
|||
import { clamp } from "../utils";
|
||||
import {
|
||||
SEEK_TO_PERCENT_COMPLETE,
|
||||
SET_BALANCE,
|
||||
SET_VOLUME,
|
||||
STOP,
|
||||
TOGGLE_REPEAT,
|
||||
TOGGLE_SHUFFLE,
|
||||
PLAY,
|
||||
PAUSE,
|
||||
PLAY_TRACK,
|
||||
TOGGLE_TIME_MODE,
|
||||
BUFFER_TRACK,
|
||||
IS_STOPPED,
|
||||
} from "../actionTypes";
|
||||
|
||||
import { MEDIA_STATUS } from "../constants";
|
||||
import { openMediaFileDialog } from "./files";
|
||||
|
|
@ -24,15 +10,15 @@ export function playTrack(id: number): Thunk {
|
|||
const state = getState();
|
||||
const isStopped = Selectors.getMediaStatus(state) === MEDIA_STATUS.STOPPED;
|
||||
if (isStopped) {
|
||||
dispatch({ type: BUFFER_TRACK, id });
|
||||
dispatch({ type: "BUFFER_TRACK", id });
|
||||
} else {
|
||||
dispatch({ type: PLAY_TRACK, id });
|
||||
dispatch({ type: "PLAY_TRACK", id });
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function playTrackNow(id: number): Action {
|
||||
return { type: PLAY_TRACK, id };
|
||||
return { type: "PLAY_TRACK", id };
|
||||
}
|
||||
|
||||
export function play(): Thunk {
|
||||
|
|
@ -45,7 +31,7 @@ export function play(): Thunk {
|
|||
) {
|
||||
dispatch(openMediaFileDialog());
|
||||
} else {
|
||||
dispatch({ type: PLAY });
|
||||
dispatch({ type: "PLAY" });
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -54,22 +40,22 @@ export function pause(): Thunk {
|
|||
return (dispatch, getState) => {
|
||||
const { status } = getState().media;
|
||||
if (status === MEDIA_STATUS.PLAYING) {
|
||||
dispatch({ type: PAUSE });
|
||||
dispatch({ type: "PAUSE" });
|
||||
} else {
|
||||
dispatch({ type: PLAY });
|
||||
dispatch({ type: "PLAY" });
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function stop(): Action {
|
||||
return { type: STOP };
|
||||
return { type: "STOP" };
|
||||
}
|
||||
|
||||
export function nextN(n: number): Thunk {
|
||||
return (dispatch, getState) => {
|
||||
const nextTrackId = Selectors.getNextTrackId(getState(), n);
|
||||
if (nextTrackId == null) {
|
||||
dispatch({ type: IS_STOPPED });
|
||||
dispatch({ type: "IS_STOPPED" });
|
||||
return;
|
||||
}
|
||||
dispatch(playTrack(nextTrackId));
|
||||
|
|
@ -92,7 +78,7 @@ export function seekToTime(seconds: number): Thunk {
|
|||
return;
|
||||
}
|
||||
dispatch({
|
||||
type: SEEK_TO_PERCENT_COMPLETE,
|
||||
type: "SEEK_TO_PERCENT_COMPLETE",
|
||||
percent: (seconds / duration) * 100,
|
||||
});
|
||||
};
|
||||
|
|
@ -110,7 +96,7 @@ export function seekBackward(seconds: number): Thunk {
|
|||
|
||||
export function setVolume(volume: number): Action {
|
||||
return {
|
||||
type: SET_VOLUME,
|
||||
type: "SET_VOLUME",
|
||||
volume: clamp(volume, 0, 100),
|
||||
};
|
||||
}
|
||||
|
|
@ -138,19 +124,19 @@ export function setBalance(balance: number): Action {
|
|||
balance = 0;
|
||||
}
|
||||
return {
|
||||
type: SET_BALANCE,
|
||||
type: "SET_BALANCE",
|
||||
balance,
|
||||
};
|
||||
}
|
||||
|
||||
export function toggleRepeat(): Action {
|
||||
return { type: TOGGLE_REPEAT };
|
||||
return { type: "TOGGLE_REPEAT" };
|
||||
}
|
||||
|
||||
export function toggleShuffle(): Action {
|
||||
return { type: TOGGLE_SHUFFLE };
|
||||
return { type: "TOGGLE_SHUFFLE" };
|
||||
}
|
||||
|
||||
export function toggleTimeMode(): Action {
|
||||
return { type: TOGGLE_TIME_MODE };
|
||||
return { type: "TOGGLE_TIME_MODE" };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,3 @@
|
|||
import {
|
||||
GOT_BUTTERCHURN_PRESETS,
|
||||
GOT_BUTTERCHURN,
|
||||
SELECT_PRESET_AT_INDEX,
|
||||
RESOLVE_PRESET_AT_INDEX,
|
||||
PRESET_REQUESTED,
|
||||
TOGGLE_RANDOMIZE_PRESETS,
|
||||
TOGGLE_PRESET_CYCLING,
|
||||
SCHEDULE_MILKDROP_MESSAGE,
|
||||
} from "../actionTypes";
|
||||
import * as Selectors from "../selectors";
|
||||
import {
|
||||
TransitionType,
|
||||
|
|
@ -51,7 +41,7 @@ export function initializePresets(presetOptions: ButterchurnOptions): Thunk {
|
|||
const { getPresets, importButterchurn } = presetOptions;
|
||||
importButterchurn().then((butterchurnModule) => {
|
||||
const butterchurn = butterchurnModule.default ?? butterchurnModule;
|
||||
dispatch({ type: GOT_BUTTERCHURN, butterchurn });
|
||||
dispatch({ type: "GOT_BUTTERCHURN", butterchurn });
|
||||
});
|
||||
|
||||
const presets = await getPresets();
|
||||
|
|
@ -64,7 +54,7 @@ export function loadPresets(presets: StatePreset[]): Thunk {
|
|||
return (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const presetsLength = state.milkdrop.presets.length;
|
||||
dispatch({ type: GOT_BUTTERCHURN_PRESETS, presets });
|
||||
dispatch({ type: "GOT_BUTTERCHURN_PRESETS", presets });
|
||||
if (presetsLength === 0 && Selectors.getRandomizePresets(state)) {
|
||||
dispatch(selectRandomPreset());
|
||||
} else {
|
||||
|
|
@ -171,16 +161,16 @@ export function requestPresetAtIndex(
|
|||
// Index might be out of range.
|
||||
return;
|
||||
}
|
||||
dispatch({ type: PRESET_REQUESTED, index, addToHistory });
|
||||
dispatch({ type: "PRESET_REQUESTED", index, addToHistory });
|
||||
switch (preset.type) {
|
||||
case "RESOLVED":
|
||||
dispatch({ type: SELECT_PRESET_AT_INDEX, index, transitionType });
|
||||
dispatch({ type: "SELECT_PRESET_AT_INDEX", index, transitionType });
|
||||
return;
|
||||
case "UNRESOLVED":
|
||||
const json = await preset.getPreset();
|
||||
// TODO: Ensure that this works correctly even if requests resolve out of order
|
||||
dispatch({ type: RESOLVE_PRESET_AT_INDEX, index, json });
|
||||
dispatch({ type: SELECT_PRESET_AT_INDEX, index, transitionType });
|
||||
dispatch({ type: "RESOLVE_PRESET_AT_INDEX", index, json });
|
||||
dispatch({ type: "SELECT_PRESET_AT_INDEX", index, transitionType });
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
|
@ -191,13 +181,13 @@ export function handlePresetDrop(e: React.DragEvent): Thunk {
|
|||
}
|
||||
|
||||
export function toggleRandomizePresets(): Action {
|
||||
return { type: TOGGLE_RANDOMIZE_PRESETS };
|
||||
return { type: "TOGGLE_RANDOMIZE_PRESETS" };
|
||||
}
|
||||
|
||||
export function togglePresetCycling(): Action {
|
||||
return { type: TOGGLE_PRESET_CYCLING };
|
||||
return { type: "TOGGLE_PRESET_CYCLING" };
|
||||
}
|
||||
|
||||
export function scheduleMilkdropMessage(message: string): Action {
|
||||
return { type: SCHEDULE_MILKDROP_MESSAGE, message };
|
||||
return { type: "SCHEDULE_MILKDROP_MESSAGE", message };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,19 +2,6 @@ import { TRACK_HEIGHT } from "../constants";
|
|||
import * as Selectors from "../selectors";
|
||||
|
||||
import { clamp, sort, findLastIndex } from "../utils";
|
||||
import {
|
||||
STOP,
|
||||
REMOVE_TRACKS,
|
||||
REMOVE_ALL_TRACKS,
|
||||
REVERSE_LIST,
|
||||
RANDOMIZE_LIST,
|
||||
SET_TRACK_ORDER,
|
||||
SET_PLAYLIST_SCROLL_POSITION,
|
||||
DRAG_SELECTED,
|
||||
SELECT_ALL,
|
||||
SELECT_ZERO,
|
||||
INVERT_SELECTION,
|
||||
} from "../actionTypes";
|
||||
import { Thunk, Action } from "../types";
|
||||
|
||||
export function cropPlaylist(): Thunk {
|
||||
|
|
@ -28,7 +15,7 @@ export function cropPlaylist(): Thunk {
|
|||
playlist: { trackOrder },
|
||||
} = state;
|
||||
dispatch({
|
||||
type: REMOVE_TRACKS,
|
||||
type: "REMOVE_TRACKS",
|
||||
// @ts-ignore The keys are numbers, but TypeScript does not trust us.
|
||||
// https://github.com/Microsoft/TypeScript/pull/12253#issuecomment-263132208
|
||||
ids: trackOrder.filter((id) => !selectedTrackIds.has(id)),
|
||||
|
|
@ -39,7 +26,7 @@ export function cropPlaylist(): Thunk {
|
|||
export function removeSelectedTracks(): Thunk {
|
||||
return (dispatch, getState) => {
|
||||
dispatch({
|
||||
type: REMOVE_TRACKS,
|
||||
type: "REMOVE_TRACKS",
|
||||
// @ts-ignore The keys are numbers, but TypeScript does not trust us.
|
||||
// https://github.com/Microsoft/TypeScript/pull/12253#issuecomment-263132208
|
||||
ids: Array.from(Selectors.getSelectedTrackIds(getState())),
|
||||
|
|
@ -50,17 +37,17 @@ export function removeSelectedTracks(): Thunk {
|
|||
export function removeAllTracks(): Thunk {
|
||||
return (dispatch) => {
|
||||
// It's a bit funky that we need to do both of these.
|
||||
dispatch({ type: STOP });
|
||||
dispatch({ type: REMOVE_ALL_TRACKS });
|
||||
dispatch({ type: "STOP" });
|
||||
dispatch({ type: "REMOVE_ALL_TRACKS" });
|
||||
};
|
||||
}
|
||||
|
||||
export function reverseList(): Action {
|
||||
return { type: REVERSE_LIST };
|
||||
return { type: "REVERSE_LIST" };
|
||||
}
|
||||
|
||||
export function randomizeList(): Action {
|
||||
return { type: RANDOMIZE_LIST };
|
||||
return { type: "RANDOMIZE_LIST" };
|
||||
}
|
||||
|
||||
export function sortListByTitle(): Thunk {
|
||||
|
|
@ -70,12 +57,12 @@ export function sortListByTitle(): Thunk {
|
|||
const trackOrder = sort(Selectors.getTrackOrder(state), (i) =>
|
||||
`${tracks[i].title}`.toLowerCase()
|
||||
);
|
||||
return dispatch({ type: SET_TRACK_ORDER, trackOrder });
|
||||
return dispatch({ type: "SET_TRACK_ORDER", trackOrder });
|
||||
};
|
||||
}
|
||||
|
||||
export function setPlaylistScrollPosition(position: number): Action {
|
||||
return { type: SET_PLAYLIST_SCROLL_POSITION, position };
|
||||
return { type: "SET_PLAYLIST_SCROLL_POSITION", position };
|
||||
}
|
||||
|
||||
export function scrollNTracks(n: number): Thunk {
|
||||
|
|
@ -85,7 +72,7 @@ export function scrollNTracks(n: number): Thunk {
|
|||
const currentOffset = Selectors.getScrollOffset(state);
|
||||
const position = overflow ? clamp((currentOffset + n) / overflow, 0, 1) : 0;
|
||||
return dispatch({
|
||||
type: SET_PLAYLIST_SCROLL_POSITION,
|
||||
type: "SET_PLAYLIST_SCROLL_POSITION",
|
||||
position: position * 100,
|
||||
});
|
||||
};
|
||||
|
|
@ -101,7 +88,7 @@ export function scrollPlaylistByDelta(e: WheelEvent): Thunk {
|
|||
const totalPixelHeight = state.playlist.trackOrder.length * TRACK_HEIGHT;
|
||||
const percentDelta = (e.deltaY / totalPixelHeight) * 100;
|
||||
dispatch({
|
||||
type: SET_PLAYLIST_SCROLL_POSITION,
|
||||
type: "SET_PLAYLIST_SCROLL_POSITION",
|
||||
position: clamp(
|
||||
state.display.playlistScrollPosition + percentDelta,
|
||||
0,
|
||||
|
|
@ -143,18 +130,18 @@ export function dragSelected(offset: number): Thunk {
|
|||
const max = trackOrder.length - 1 - lastSelected;
|
||||
const normalizedOffset = clamp(offset, min, max);
|
||||
if (normalizedOffset !== 0) {
|
||||
dispatch({ type: DRAG_SELECTED, offset: normalizedOffset });
|
||||
dispatch({ type: "DRAG_SELECTED", offset: normalizedOffset });
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function invertSelection(): Action {
|
||||
return { type: INVERT_SELECTION };
|
||||
return { type: "INVERT_SELECTION" };
|
||||
}
|
||||
export function selectZero(): Action {
|
||||
return { type: SELECT_ZERO };
|
||||
return { type: "SELECT_ZERO" };
|
||||
}
|
||||
|
||||
export function selectAll(): Action {
|
||||
return { type: SELECT_ALL };
|
||||
return { type: "SELECT_ALL" };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,6 @@
|
|||
import * as Selectors from "../selectors";
|
||||
|
||||
import * as Utils from "../utils";
|
||||
import {
|
||||
UPDATE_WINDOW_POSITIONS,
|
||||
TOGGLE_DOUBLESIZE_MODE,
|
||||
WINDOW_SIZE_CHANGED,
|
||||
TOGGLE_WINDOW,
|
||||
CLOSE_WINDOW,
|
||||
TOGGLE_WINDOW_SHADE_MODE,
|
||||
BROWSER_WINDOW_SIZE_CHANGED,
|
||||
RESET_WINDOW_SIZES,
|
||||
TOGGLE_LLAMA_MODE,
|
||||
SET_FOCUSED_WINDOW,
|
||||
} from "../actionTypes";
|
||||
|
||||
import { getPositionDiff, SizeDiff } from "../resizeUtils";
|
||||
import { applyDiff } from "../snapUtils";
|
||||
|
|
@ -62,58 +50,58 @@ function withWindowGraphIntegrity(action: Action): Thunk {
|
|||
}
|
||||
|
||||
export function toggleDoubleSizeMode(): Thunk {
|
||||
return withWindowGraphIntegrity({ type: TOGGLE_DOUBLESIZE_MODE });
|
||||
return withWindowGraphIntegrity({ type: "TOGGLE_DOUBLESIZE_MODE" });
|
||||
}
|
||||
|
||||
export function toggleLlamaMode(): Action {
|
||||
return { type: TOGGLE_LLAMA_MODE };
|
||||
return { type: "TOGGLE_LLAMA_MODE" };
|
||||
}
|
||||
|
||||
export function toggleEqualizerShadeMode(): Thunk {
|
||||
return withWindowGraphIntegrity({
|
||||
type: TOGGLE_WINDOW_SHADE_MODE,
|
||||
type: "TOGGLE_WINDOW_SHADE_MODE",
|
||||
windowId: "equalizer",
|
||||
});
|
||||
}
|
||||
|
||||
export function toggleMainWindowShadeMode(): Thunk {
|
||||
return withWindowGraphIntegrity({
|
||||
type: TOGGLE_WINDOW_SHADE_MODE,
|
||||
type: "TOGGLE_WINDOW_SHADE_MODE",
|
||||
windowId: "main",
|
||||
});
|
||||
}
|
||||
|
||||
export function togglePlaylistShadeMode(): Thunk {
|
||||
return withWindowGraphIntegrity({
|
||||
type: TOGGLE_WINDOW_SHADE_MODE,
|
||||
type: "TOGGLE_WINDOW_SHADE_MODE",
|
||||
windowId: "playlist",
|
||||
});
|
||||
}
|
||||
|
||||
export function closeWindow(windowId: WindowId): Action {
|
||||
return { type: CLOSE_WINDOW, windowId };
|
||||
return { type: "CLOSE_WINDOW", windowId };
|
||||
}
|
||||
|
||||
export function setFocusedWindow(window: WindowId | null): Action {
|
||||
return { type: SET_FOCUSED_WINDOW, window };
|
||||
return { type: "SET_FOCUSED_WINDOW", window };
|
||||
}
|
||||
|
||||
export function setWindowSize(
|
||||
windowId: WindowId,
|
||||
size: [number, number]
|
||||
): Action {
|
||||
return { type: WINDOW_SIZE_CHANGED, windowId, size };
|
||||
return { type: "WINDOW_SIZE_CHANGED", windowId, size };
|
||||
}
|
||||
|
||||
export function toggleWindow(windowId: WindowId): Action {
|
||||
return { type: TOGGLE_WINDOW, windowId };
|
||||
return { type: "TOGGLE_WINDOW", windowId };
|
||||
}
|
||||
|
||||
export function updateWindowPositions(
|
||||
positions: WindowPositions,
|
||||
absolute?: boolean
|
||||
): Action {
|
||||
return { type: UPDATE_WINDOW_POSITIONS, positions, absolute };
|
||||
return { type: "UPDATE_WINDOW_POSITIONS", positions, absolute };
|
||||
}
|
||||
|
||||
export function centerWindowsInContainer(container: HTMLElement): Thunk {
|
||||
|
|
@ -185,13 +173,13 @@ export function browserWindowSizeChanged(size: {
|
|||
width: number;
|
||||
}): Thunk {
|
||||
return (dispatch: Dispatch) => {
|
||||
dispatch({ type: BROWSER_WINDOW_SIZE_CHANGED, ...size });
|
||||
dispatch({ type: "BROWSER_WINDOW_SIZE_CHANGED", ...size });
|
||||
dispatch(ensureWindowsAreOnScreen());
|
||||
};
|
||||
}
|
||||
|
||||
export function resetWindowSizes(): Action {
|
||||
return { type: RESET_WINDOW_SIZES };
|
||||
return { type: "RESET_WINDOW_SIZES" };
|
||||
}
|
||||
|
||||
export function stackWindows(): Thunk {
|
||||
|
|
@ -224,7 +212,7 @@ export function setWindowLayout(layout?: WindowLayout): Thunk {
|
|||
for (const id of ["main", "playlist", "equalizer"] as const) {
|
||||
if (layout[id]?.shadeMode) {
|
||||
dispatch({
|
||||
type: TOGGLE_WINDOW_SHADE_MODE,
|
||||
type: "TOGGLE_WINDOW_SHADE_MODE",
|
||||
windowId: id,
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,87 +0,0 @@
|
|||
export const ADD_TRACK_FROM_URL = "ADD_TRACK_FROM_URL";
|
||||
export const CLOSE_WINAMP = "CLOSE_WINAMP";
|
||||
export const OPEN_WINAMP = "OPEN_WINAMP";
|
||||
export const MINIMIZE_WINAMP = "MINIMIZE_WINAMP";
|
||||
export const IS_PLAYING = "IS_PLAYING";
|
||||
export const IS_STOPPED = "IS_STOPPED";
|
||||
export const PAUSE = "PAUSE";
|
||||
export const PLAY = "PLAY";
|
||||
export const SEEK_TO_PERCENT_COMPLETE = "SEEK_TO_PERCENT_COMPLETE";
|
||||
export const SET_BALANCE = "SET_BALANCE";
|
||||
export const SET_BAND_VALUE = "SET_BAND_VALUE";
|
||||
export const SET_FOCUS = "SET_FOCUS";
|
||||
export const SET_BAND_FOCUS = "SET_BAND_FOCUS";
|
||||
export const SET_FOCUSED_WINDOW = "SET_FOCUSED_WINDOW";
|
||||
export const SET_MEDIA = "SET_MEDIA";
|
||||
export const SET_SCRUB_POSITION = "SET_SCRUB_POSITION";
|
||||
export const SET_SKIN_DATA = "SET_SKIN_DATA";
|
||||
export const SET_VOLUME = "SET_VOLUME";
|
||||
export const START_WORKING = "START_WORKING";
|
||||
export const STEP_MARQUEE = "STEP_MARQUEE";
|
||||
export const STOP = "STOP";
|
||||
export const STOP_WORKING = "STOP_WORKING";
|
||||
export const TOGGLE_DOUBLESIZE_MODE = "TOGGLE_DOUBLESIZE_MODE";
|
||||
export const SET_EQ_AUTO = "SET_EQ_AUTO";
|
||||
export const SET_EQ_ON = "SET_EQ_ON";
|
||||
export const SET_EQ_OFF = "SET_EQ_OFF";
|
||||
export const TOGGLE_LLAMA_MODE = "TOGGLE_LLAMA_MODE";
|
||||
export const TOGGLE_REPEAT = "TOGGLE_REPEAT";
|
||||
export const TOGGLE_SHUFFLE = "TOGGLE_SHUFFLE";
|
||||
export const TOGGLE_TIME_MODE = "TOGGLE_TIME_MODE";
|
||||
export const TOGGLE_VISUALIZER_STYLE = "TOGGLE_VISUALIZER_STYLE";
|
||||
export const UNSET_FOCUS = "UNSET_FOCUS";
|
||||
export const UPDATE_TIME_ELAPSED = "UPDATE_TIME_ELAPSED";
|
||||
export const SET_USER_MESSAGE = "SET_USER_MESSAGE";
|
||||
export const UNSET_USER_MESSAGE = "UNSET_USER_MESSAGE";
|
||||
export const SET_PLAYLIST_SCROLL_POSITION = "SET_PLAYLIST_SCROLL_POSITION";
|
||||
export const CLICKED_TRACK = "CLICKED_TRACK";
|
||||
export const CTRL_CLICKED_TRACK = "CTRL_CLICKED_TRACK";
|
||||
export const SHIFT_CLICKED_TRACK = "SHIFT_CLICKED_TRACK";
|
||||
export const SELECT_ALL = "SELECT_ALL";
|
||||
export const SELECT_ZERO = "SELECT_ZERO";
|
||||
export const INVERT_SELECTION = "INVERT_SELECTION";
|
||||
export const REMOVE_ALL_TRACKS = "REMOVE_ALL_TRACKS";
|
||||
export const CROP_TRACKS = "CROP_TRACKS";
|
||||
export const FILE_INFO = "FILE_INFO";
|
||||
export const REMOVE_TRACKS = "REMOVE_TRACKS";
|
||||
export const SET_AVAILABLE_SKINS = "SET_AVAILABLE_SKINS";
|
||||
export const REVERSE_LIST = "REVERSE_LIST";
|
||||
export const RANDOMIZE_LIST = "RANDOMIZE_LIST";
|
||||
export const SET_TRACK_ORDER = "SET_TRACK_ORDER";
|
||||
export const PLAY_TRACK = "PLAY_TRACK";
|
||||
export const BUFFER_TRACK = "BUFFER_TRACK";
|
||||
export const DRAG_SELECTED = "DRAG_SELECTED";
|
||||
export const SET_MEDIA_TAGS = "SET_MEDIA_TAGS";
|
||||
export const SET_MEDIA_DURATION = "SET_MEDIA_DURATION";
|
||||
export const TOGGLE_WINDOW = "TOGGLE_WINDOW";
|
||||
export const CLOSE_WINDOW = "CLOSE_WINDOW";
|
||||
export const MEDIA_TAG_REQUEST_INITIALIZED = "MEDIA_TAG_REQUEST_INITIALIZED";
|
||||
export const MEDIA_TAG_REQUEST_FAILED = "MEDIA_TAG_REQUEST_FAILED";
|
||||
export const NETWORK_CONNECTED = "NETWORK_CONNECTED";
|
||||
export const NETWORK_DISCONNECTED = "NETWORK_DISCONNECTED";
|
||||
export const UPDATE_WINDOW_POSITIONS = "UPDATE_WINDOW_POSITIONS";
|
||||
export const WINDOW_SIZE_CHANGED = "WINDOW_SIZE_CHANGED";
|
||||
export const TOGGLE_WINDOW_SHADE_MODE = "TOGGLE_WINDOW_SHADE_MODE";
|
||||
export const LOADED = "LOADED";
|
||||
export const SET_Z_INDEX = "SET_Z_INDEX";
|
||||
export const DISABLE_MARQUEE = "DISABLE_MARQUEE";
|
||||
export const SET_DUMMY_VIZ_DATA = "SET_DUMMY_VIZ_DATA";
|
||||
export const LOADING = "LOADING";
|
||||
export const CLOSE_REQUESTED = "CLOSE_REQUESTED";
|
||||
export const LOAD_SERIALIZED_STATE = "LOAD_SERIALIZED_STATE";
|
||||
export const RESET_WINDOW_SIZES = "RESET_WINDOW_SIZES";
|
||||
export const BROWSER_WINDOW_SIZE_CHANGED = "BROWSER_WINDOW_SIZE_CHANGED";
|
||||
export const LOAD_DEFAULT_SKIN = "LOAD_DEFAULT_SKIN";
|
||||
export const ENABLE_MILKDROP = "ENABLE_MILKDROP";
|
||||
export const SET_MILKDROP_DESKTOP = "SET_MILKDROP_DESKTOP";
|
||||
export const SET_VISUALIZER_STYLE = "SET_VISUALIZER_STYLE";
|
||||
export const GOT_BUTTERCHURN_PRESETS = "GOT_BUTTERCHURN_PRESETS";
|
||||
export const GOT_BUTTERCHURN = "GOT_BUTTERCHURN";
|
||||
export const RESOLVE_PRESET_AT_INDEX = "RESOLVE_PRESET_AT_INDEX";
|
||||
export const SELECT_PRESET_AT_INDEX = "SELECT_PRESET_AT_INDEX";
|
||||
export const TOGGLE_PRESET_OVERLAY = "TOGGLE_PRESET_OVERLAY";
|
||||
export const PRESET_REQUESTED = "PRESET_REQUESTED";
|
||||
export const TOGGLE_RANDOMIZE_PRESETS = "TOGGLE_RANDOMIZE_PRESETS";
|
||||
export const TOGGLE_PRESET_CYCLING = "TOGGLE_PRESET_CYCLING";
|
||||
export const SCHEDULE_MILKDROP_MESSAGE = "SCHEDULE_MILKDROP_MESSAGE";
|
||||
export const SET_MILKDROP_FULLSCREEN = "SET_MILKDROP_FULLSCREEN";
|
||||
|
|
@ -16,8 +16,6 @@ import {
|
|||
toggleWindow,
|
||||
} from "./actionCreators";
|
||||
|
||||
import { TOGGLE_TIME_MODE, TOGGLE_LLAMA_MODE } from "./actionTypes";
|
||||
|
||||
import { Dispatch } from "./types";
|
||||
|
||||
const IGNORE_EVENTS_FROM_TAGS = new Set(["input", "textarea", "select"]);
|
||||
|
|
@ -54,7 +52,7 @@ export function bindHotkeys(dispatch: Dispatch): () => void {
|
|||
dispatch(reverseList());
|
||||
break;
|
||||
case 84: // CTRL+T
|
||||
dispatch({ type: TOGGLE_TIME_MODE });
|
||||
dispatch({ type: "TOGGLE_TIME_MODE" });
|
||||
break;
|
||||
}
|
||||
} else if (e.altKey) {
|
||||
|
|
@ -146,7 +144,7 @@ export function bindHotkeys(dispatch: Dispatch): () => void {
|
|||
if (e.keyCode !== 27) {
|
||||
currentPos = e.keyCode === trigger[currentPos] ? currentPos + 1 : 0;
|
||||
if (currentPos === trigger.length) {
|
||||
dispatch({ type: TOGGLE_LLAMA_MODE });
|
||||
dispatch({ type: "TOGGLE_LLAMA_MODE" });
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import { kebabCase } from "lodash";
|
|||
|
||||
import { legacy_createStore as createStore, applyMiddleware } from "redux";
|
||||
import thunk from "redux-thunk";
|
||||
import { LOAD_SERIALIZED_STATE } from "./actionTypes";
|
||||
import { SerializedStateV1 } from "./serializedStates/v1Types";
|
||||
import { AppState, Action } from "./types";
|
||||
|
||||
|
|
@ -69,7 +68,7 @@ function testSerialization<T>({
|
|||
// Try to apply this serialized state to the default state
|
||||
const secondStore = getStore();
|
||||
secondStore.dispatch({
|
||||
type: LOAD_SERIALIZED_STATE,
|
||||
type: "LOAD_SERIALIZED_STATE",
|
||||
serializedState: readSerializedState,
|
||||
});
|
||||
|
||||
|
|
@ -94,7 +93,7 @@ describe("can serialize", () => {
|
|||
|
||||
const newStore = getStore();
|
||||
newStore.dispatch({
|
||||
type: LOAD_SERIALIZED_STATE,
|
||||
type: "LOAD_SERIALIZED_STATE",
|
||||
serializedState,
|
||||
});
|
||||
expect(store.getState()).toEqual(newStore.getState());
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import { composeWithDevTools } from "@redux-devtools/extension";
|
|||
import reducer from "./reducers";
|
||||
import mediaMiddleware from "./mediaMiddleware";
|
||||
import { merge } from "./utils";
|
||||
import { UPDATE_TIME_ELAPSED, STEP_MARQUEE } from "./actionTypes";
|
||||
import { IMedia } from "./media";
|
||||
import Emitter from "./emitter";
|
||||
import {
|
||||
|
|
@ -21,7 +20,7 @@ import {
|
|||
} from "./types";
|
||||
|
||||
const compose = composeWithDevTools({
|
||||
actionsDenylist: [UPDATE_TIME_ELAPSED, STEP_MARQUEE],
|
||||
actionsDenylist: ["UPDATE_TIME_ELAPSED", "STEP_MARQUEE"],
|
||||
});
|
||||
|
||||
export default function createWebampStore(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue