Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull marquee stepping out of Redux #1063

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/webamp/demo/js/Webamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export {
} from "../../js/types";
export { WINDOWS } from "../../js/constants";
export {
STEP_MARQUEE,
UPDATE_TIME_ELAPSED,
UPDATE_WINDOW_POSITIONS,
SET_VOLUME,
Expand Down
2 changes: 0 additions & 2 deletions packages/webamp/demo/js/webampConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
Options,
PrivateOptions,
WINDOWS,
STEP_MARQUEE,
UPDATE_TIME_ELAPSED,
UPDATE_WINDOW_POSITIONS,
SET_VOLUME,
Expand All @@ -29,7 +28,6 @@ import { initialTracks, initialState } from "./config";
import screenshotInitialState from "./screenshotInitialState";

const NOISY_ACTION_TYPES = new Set([
STEP_MARQUEE,
UPDATE_TIME_ELAPSED,
UPDATE_WINDOW_POSITIONS,
SET_VOLUME,
Expand Down
5 changes: 0 additions & 5 deletions packages/webamp/js/actionCreators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
SET_MILKDROP_DESKTOP,
SET_MILKDROP_FULLSCREEN,
TOGGLE_PRESET_OVERLAY,
STEP_MARQUEE,
SET_BAND_FOCUS,
} from "../actionTypes";
import { WINDOWS } from "../constants";
Expand Down Expand Up @@ -215,7 +214,3 @@ export function togglePresetOverlay(): Thunk {
dispatch({ type: TOGGLE_PRESET_OVERLAY });
};
}

export function stepMarquee(): Action {
return { type: STEP_MARQUEE };
}
1 change: 0 additions & 1 deletion packages/webamp/js/actionTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ 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";
Expand Down
24 changes: 13 additions & 11 deletions packages/webamp/js/components/MainWindow/Marquee.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
// Knows how to display various modes like tracking, volume, balance, etc.
import * as React from "react";
import CharacterString from "../CharacterString";
import * as Actions from "../../actionCreators";
import * as Selectors from "../../selectors";
import { useTypedSelector, useActionCreator } from "../../hooks";
import { useTypedSelector } from "../../hooks";

const SEPARATOR = " *** ";

Expand Down Expand Up @@ -43,20 +42,24 @@ export const loopText = (text: string): string =>
: text.padEnd(MARQUEE_MAX_LENGTH, " ");

interface UseStepperArgs {
step: () => void;
dragging: boolean;
disableMarquee: boolean;
}

// Call `step` every second, except when dragging. Resume stepping 1 second after dragging ceases.
function useStepper({ step, dragging }: UseStepperArgs): void {
function useStepper({ dragging, disableMarquee }: UseStepperArgs): number {
const [currentStep, setStep] = React.useState(0);
const [stepping, setStepping] = React.useState(true);
React.useEffect(() => {
if (stepping === false) {
if (stepping === false || disableMarquee === true) {
return;
}
const stepHandle = setInterval(step, 220);
const stepHandle = setInterval(
() => setStep((current) => current + 1),
220
);
return () => clearInterval(stepHandle);
}, [step, stepping]);
}, [stepping, disableMarquee]);

React.useEffect(() => {
if (dragging) {
Expand All @@ -70,6 +73,7 @@ function useStepper({ step, dragging }: UseStepperArgs): void {
window.clearTimeout(steppingTimeout);
};
}, [dragging]);
return currentStep;
}

// When user calls `handleMouseDown`, and moves the mouse, `dragOffset` will update as they drag.
Expand Down Expand Up @@ -118,14 +122,12 @@ function useDragX() {
const Marquee = React.memo(() => {
const text = useTypedSelector(Selectors.getMarqueeText);
const doubled = useTypedSelector(Selectors.getDoubled);
const marqueeStep = useTypedSelector(Selectors.getMarqueeStep);
const stepMarquee = useActionCreator(Actions.stepMarquee);
const { handleMouseDown, dragOffset, dragging } = useDragX();
const disableMarquee = useTypedSelector(Selectors.getDisableMarquee);
const marqueeStep = useStepper({ dragging, disableMarquee });
const offset = stepOffset(text, marqueeStep, dragOffset);
const offsetPixels = pixelUnits(-offset);

useStepper({ step: stepMarquee, dragging });

return (
<div
id="marquee"
Expand Down
9 changes: 1 addition & 8 deletions packages/webamp/js/reducers/display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
OPEN_WINAMP,
SET_SKIN_DATA,
START_WORKING,
STEP_MARQUEE,
STOP_WORKING,
TOGGLE_DOUBLESIZE_MODE,
TOGGLE_LLAMA_MODE,
Expand All @@ -38,7 +37,6 @@ export interface DisplayState {
doubled: boolean;
llama: boolean;
disableMarquee: boolean;
marqueeStep: number;
skinImages: SkinImages;
skinCursors: Cursors | null;
skinRegion: SkinRegion;
Expand Down Expand Up @@ -131,10 +129,6 @@ const display = (
return { ...state, doubled: !state.doubled };
case TOGGLE_LLAMA_MODE:
return { ...state, llama: !state.llama };
case STEP_MARQUEE:
return state.disableMarquee
? state
: { ...state, marqueeStep: state.marqueeStep + 1 };
case DISABLE_MARQUEE:
return { ...state, disableMarquee: true };
case STOP_WORKING:
Expand Down Expand Up @@ -194,7 +188,6 @@ export const getSerializedState = (
visualizerStyle,
doubled,
llama,
marqueeStep,
skinImages,
skinCursors,
skinRegion,
Expand All @@ -217,7 +210,7 @@ export const getSerializedState = (
visualizerStyle,
doubled,
llama,
marqueeStep,
marqueeStep: 0, // This is not used any more.
skinImages,
skinCursors: newCursors,
skinRegion,
Expand Down
8 changes: 4 additions & 4 deletions packages/webamp/js/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,10 @@ export const getMarqueeText = (state: AppState): string => {
return defaultText;
};

export function getDisableMarquee(state: AppState): boolean {
return state.display.disableMarquee;
}

export const getKbps = createSelector(
getCurrentTrack,
(track: PlaylistTrack | null): string | null => {
Expand Down Expand Up @@ -757,10 +761,6 @@ export function getDummyVizData(state: AppState): DummyVizData | null {
return state.display.dummyVizData;
}

export function getMarqueeStep(state: AppState): number {
return state.display.marqueeStep;
}

export function getNetworkConnected(state: AppState): boolean {
return state.network.connected;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/webamp/js/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ 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 { UPDATE_TIME_ELAPSED } from "./actionTypes";
import Media from "./media";
import Emitter from "./emitter";
import { Extras, Dispatch, Action, AppState, Middleware } from "./types";

// TODO: Move to demo
const compose = composeWithDevTools({
actionsBlacklist: [UPDATE_TIME_ELAPSED, STEP_MARQUEE],
actionsBlacklist: [UPDATE_TIME_ELAPSED],
});

export default function (
Expand Down
3 changes: 0 additions & 3 deletions packages/webamp/js/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,6 @@ export type Action =
| {
type: "TOGGLE_LLAMA_MODE";
}
| {
type: "STEP_MARQUEE";
}
| {
type: "DISABLE_MARQUEE";
}
Expand Down