From c3a3614c2c3b88ae1573bc3ea792b7aa3dff38b2 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Fri, 18 Aug 2017 17:14:34 -0700 Subject: [PATCH] Standardize feature flags, such as they are --- js/components/MainWindow/Marquee.js | 5 ++- js/config.js | 6 +++ js/index.js | 10 ++--- js/reducers.js | 60 ++++++++++++++--------------- 4 files changed, 42 insertions(+), 39 deletions(-) create mode 100644 js/config.js diff --git a/js/components/MainWindow/Marquee.js b/js/components/MainWindow/Marquee.js index d37384a4..c095402e 100644 --- a/js/components/MainWindow/Marquee.js +++ b/js/components/MainWindow/Marquee.js @@ -6,6 +6,7 @@ import { getTimeStr } from "../../utils"; import { STEP_MARQUEE } from "../../actionTypes"; import CharacterString from "../CharacterString"; +import { noMarquee } from "../../config"; const CHAR_WIDTH = 5; @@ -74,7 +75,9 @@ class Marquee extends React.Component { step(); }, 220); }; - step(); + if (!noMarquee) { + step(); + } } getText() { diff --git a/js/config.js b/js/config.js new file mode 100644 index 00000000..baa7d728 --- /dev/null +++ b/js/config.js @@ -0,0 +1,6 @@ +const { hash } = window.location; +// Turn on the incomplete playlist window +export const playlistEnabled = hash.includes("playlist"); +// Turn on the incomplete equalizer window +export const equalizerEnabled = hash.includes("equalizer"); +export const noMarquee = hash.includes("!marquee"); diff --git a/js/index.js b/js/index.js index ec9ace30..8e555a0b 100644 --- a/js/index.js +++ b/js/index.js @@ -13,13 +13,9 @@ import EqualizerWindow from "./components/EqualizerWindow"; import Winamp from "./winamp"; import Hotkeys from "./hotkeys"; import Skin from "./components/Skin"; +import { equalizerEnabled, playlistEnabled } from "./config"; if (new Browser(window).isCompatible) { - const hash = window.location.hash; - // Turn on the incomplete playlist window - const playlist = hash.includes("playlist"); - // Turn on the incomplete equalizer window - const equalizer = hash.includes("equalizer"); const winamp = Winamp; const store = getStore(winamp); @@ -33,8 +29,8 @@ if (new Browser(window).isCompatible) { - {playlist && } - {equalizer && } + {playlistEnabled && } + {equalizerEnabled && } , diff --git a/js/reducers.js b/js/reducers.js index 97728db8..89c747c1 100644 --- a/js/reducers.js +++ b/js/reducers.js @@ -34,6 +34,7 @@ import { UNSET_FOCUS, UPDATE_TIME_ELAPSED } from "./actionTypes"; +import { equalizerEnabled } from "./config"; export const userInput = (state, action) => { if (!state) { @@ -54,18 +55,17 @@ export const userInput = (state, action) => { } }; -const windows = (state, action) => { - if (!state) { - return { - focused: WINDOWS.MAIN, - equalizer: false - }; - } +const defaultWindowsState = { + focused: WINDOWS.MAIN, + equalizer: equalizerEnabled +}; + +const windows = (state = defaultWindowsState, action) => { switch (action.type) { case SET_FOCUSED_WINDOW: return { ...state, focused: action.window }; case TOGGLE_EQUALIZER_WINDOW: - if (process.env.NODE_ENV === "production") { + if (!equalizerEnabled) { return state; } return { ...state, equalizer: !state.equalizer }; @@ -76,23 +76,22 @@ const windows = (state, action) => { } }; -const display = (state, action) => { - if (!state) { - return { - doubled: false, - marqueeStep: 0, - loading: true, - llama: false, - closed: false, - shade: false, - equalizerShade: false, - working: false, - skinImages: {}, - skinColors: null, - skinPlaylistStyle: {}, - visualizerStyle: 2 - }; - } +const defaultDisplayState = { + doubled: false, + marqueeStep: 0, + loading: true, + llama: false, + closed: false, + shade: false, + equalizerShade: false, + working: false, + skinImages: {}, + skinColors: null, + skinPlaylistStyle: {}, + visualizerStyle: 2 +}; + +const display = (state = defaultDisplayState, action) => { switch (action.type) { case TOGGLE_DOUBLESIZE_MODE: return { ...state, doubled: !state.doubled }; @@ -128,12 +127,11 @@ const display = (state, action) => { } }; -const contextMenu = (state, action) => { - if (!state) { - return { - selected: false - }; - } +const defaultContextMenuState = { + selected: false +}; + +const contextMenu = (state = defaultContextMenuState, action) => { switch (action.type) { case TOGGLE_CONTEXT_MENU: return { ...state, selected: !state.selected };