import React, { memo, useCallback } from 'react'; import { useStore, useDispatch } from 'react-redux' import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; import Link from './Link'; import Icon from './Icon'; import URILink from './URILink'; import TextField from './Fields/TextField'; import { indexToArray } from '../util/arrays'; import * as uiActions from '../services/ui/actions'; import * as coreActions from '../services/core/actions'; import * as mopidyActions from '../services/mopidy/actions'; import { iconFromKeyword } from '../util/helpers'; const Servers = ({ match: { params: { id: serverId } }, history, }) => { const store = useStore(); const dispatch = useDispatch(); const { mopidy: { servers, current_server, connected: mopidyConnected, connecting: mopidyConnecting, }, pusher: { connected: pusherConnected, connecting: pusherConnecting, }, } = store.getState(); const addServer = () => { const action = mopidyActions.addServer(); dispatch(action); history.push(`/settings/servers/${action.server.id}`); }; const renderMenu = () => (
{indexToArray(servers).map((server) => { let status = Inactive; if (server.id === current_server) { if (mopidyConnecting || pusherConnecting) { status = Connecting } else if (!mopidyConnected || !pusherConnected) { status = Disconnected } else if (mopidyConnected && pusherConnected) { status = Connected } } return (
{server.name}
{status}
); })}
Add
New server
); const renderServer = () => { if (!serverId) return null; const server = servers[serverId]; if (!server) return null; const remove = () => { dispatch(mopidyActions.removeServer(server.id)); }; const setAsCurrent = () => { dispatch(mopidyActions.setCurrentServer(server)); }; return (