Move gen window indexing into App

This commit is contained in:
Jordan Eldredge 2018-05-13 09:17:16 -07:00
parent 7b7af6b06e
commit 67e1e1f587
2 changed files with 9 additions and 12 deletions

View file

@ -19,18 +19,12 @@ const App = ({
genWindowsInfo,
container,
filePickers,
genWindows = []
genWindowComponents
}) => {
if (closed) {
return null;
}
// Index genWindows by id
const genWindowComponents = genWindows.reduce(
(comps, gen) => ({ ...comps, [gen.id]: gen }),
{}
);
const windows = objectMap(genWindowsInfo, (w, id) => {
switch (id) {
case "main":
@ -45,10 +39,10 @@ const App = ({
if (!w.generic) {
throw new Error("Tried to render an unknown window:", id);
}
const { Component, title } = genWindowComponents[id];
const Component = genWindowComponents[id];
return (
w.open && (
<GenWindow title={title} windowId={id}>
<GenWindow title={w.title} windowId={id}>
{({ height, width }) => (
<Component
analyser={media._analyser}
@ -80,8 +74,6 @@ App.propTypes = {
const mapStateToProps = state => ({
closed: state.display.closed,
mainWindow: state.windows.mainWindow,
equalizer: state.windows.equalizer,
genWindowsInfo: state.windows.genWindows
});

View file

@ -135,13 +135,18 @@ class Winamp {
// Wait for the skin to load.
await storeHas(this.store, state => !state.display.loading);
const genWindowComponents = {};
this.genWindows.forEach(w => {
genWindowComponents[w.id] = w.Component;
});
render(
<Provider store={this.store}>
<App
media={this.media}
container={this.options.container}
filePickers={this.options.filePickers}
genWindows={this.genWindows}
genWindowComponents={genWindowComponents}
/>
</Provider>,
node