import React from 'react'; import { Route, Routes, useParams, useNavigate } from 'react-router-dom'; import { useSelector, useDispatch } from 'react-redux'; import Link from './Link'; import Icon from './Icon'; import TextField from './Fields/TextField'; import { indexToArray } from '../util/arrays'; import { Button } from './Button'; import * as mopidyActions from '../services/mopidy/actions'; import { iconFromKeyword } from '../util/helpers'; import { I18n } from '../locale'; const Server = () => { const { id } = useParams(); if (!id) return null; const dispatch = useDispatch(); const current_server = useSelector((state) => state.mopidy.current_server); const server = useSelector((state) => state.mopidy.servers[id]); if (!server) return null; const remove = () => dispatch(mopidyActions.removeServer(id)); const setAsCurrent = () => dispatch(mopidyActions.setCurrentServer(server)); const isCurrent = id === current_server; return (
); }; const Menu = () => { const navigate = useNavigate(); const dispatch = useDispatch(); const servers = indexToArray(useSelector((state) => state.mopidy.servers)); const { current_server, connected: mopidyConnected, connecting: mopidyConnecting, } = useSelector((state) => state.mopidy); const { connected: pusherConnected, connecting: pusherConnecting, } = useSelector((state) => state.pusher); const addServer = () => { const action = mopidyActions.addServer(); dispatch(action); navigate(`/settings/servers/${action.server.id}`); }; return (
{servers.map((server) => { let status = ( ); if (server.id === current_server) { if (mopidyConnecting || pusherConnecting) { status = ( ); } else if (!mopidyConnected || !pusherConnected) { status = ( ); } else if (mopidyConnected && pusherConnected) { status = ( ); } } return (
{server.name}
{status}
); })}
); }; const Servers = () => (
} />
); export default Servers;