diff options
Diffstat (limited to 'src/web')
| -rw-r--r-- | src/web/src/components/App.js | 36 | ||||
| -rw-r--r-- | src/web/src/components/System/System.js | 51 | ||||
| -rw-r--r-- | src/web/src/components/Users/Users.js | 2 | ||||
| -rw-r--r-- | src/web/src/config.js | 10 | ||||
| -rw-r--r-- | src/web/src/lib/api.js | 4 | ||||
| -rw-r--r-- | src/web/src/lib/hubFactory.js | 6 | ||||
| -rw-r--r-- | src/web/src/lib/rooms.js | 10 | ||||
| -rw-r--r-- | src/web/src/lib/users.js | 12 |
8 files changed, 79 insertions, 52 deletions
diff --git a/src/web/src/components/App.js b/src/web/src/components/App.js index 3a22e0c8..09f3f742 100644 --- a/src/web/src/components/App.js +++ b/src/web/src/components/App.js @@ -1,8 +1,9 @@ import React, { Component } from 'react'; -import { Route, Link, Switch } from "react-router-dom"; +import { Route, Link, Switch, Redirect } from "react-router-dom"; import * as session from '../lib/session'; import { connect, disconnect } from '../lib/server'; +import { urlBase } from '../config'; import { createApplicationHubConnection } from '../lib/hubFactory'; @@ -150,37 +151,37 @@ class App extends Component { {version.isCanary && <Menu.Item> <Icon name='flask' color='yellow'/>Canary </Menu.Item>} - <Link to='.'> + <Link to={`${urlBase}/searches`}> <Menu.Item> <Icon name='search'/>Search </Menu.Item> </Link> - <Link to='downloads'> + <Link to={`${urlBase}/downloads`}> <Menu.Item> <Icon name='download'/>Downloads </Menu.Item> </Link> - <Link to='uploads'> + <Link to={`${urlBase}/uploads`}> <Menu.Item> <Icon name='upload'/>Uploads </Menu.Item> </Link> - <Link to='rooms'> + <Link to={`${urlBase}/rooms`}> <Menu.Item> <Icon name='comments'/>Rooms </Menu.Item> </Link> - <Link to='chat'> + <Link to={`${urlBase}/chat`}> <Menu.Item> <Icon name='comment'/>Chat </Menu.Item> </Link> - <Link to='users'> + <Link to={`${urlBase}/users`}> <Menu.Item> <Icon name='users'/>Users </Menu.Item> </Link> - <Link to='browse'> + <Link to={`${urlBase}/browse`}> <Menu.Item> <Icon name='folder open'/>Browse </Menu.Item> @@ -221,7 +222,7 @@ class App extends Component { href="https://github.com/slskd/slskd/releases">See Release Notes</Button> </Modal.Actions> </Modal>} - <Link to='system'> + <Link to={`${urlBase}/system`}> <Menu.Item> <Icon name='cogs'/>System </Menu.Item> @@ -242,14 +243,15 @@ class App extends Component { </Sidebar> <Sidebar.Pusher className='app-content'> <Switch> - <Route path='*/browse' render={(props) => this.withTokenCheck(<Browse {...props}/>)}/> - <Route path='*/users' render={(props) => this.withTokenCheck(<Users {...props}/>)}/> - <Route path='*/chat' render={(props) => this.withTokenCheck(<Chat {...props}/>)}/> - <Route path='*/rooms' render={(props) => this.withTokenCheck(<Rooms {...props}/>)}/> - <Route path='*/uploads' render={(props) => this.withTokenCheck(<Transfers {...props} direction='upload'/>)}/> - <Route path='*/downloads' render={(props) => this.withTokenCheck(<Transfers {...props} direction='download'/>)}/> - <Route path='*/system' render={(props) => this.withTokenCheck(<System state={applicationState} options={applicationOptions}/>)}/> - <Route path='*/' render={(props) => this.withTokenCheck(<Search {...props}/>)}/> + <Route path={`${urlBase}/searches`} render={(props) => this.withTokenCheck(<Search {...props}/>)}/> + <Route path={`${urlBase}/browse`} render={(props) => this.withTokenCheck(<Browse {...props}/>)}/> + <Route path={`${urlBase}/users`} render={(props) => this.withTokenCheck(<Users {...props}/>)}/> + <Route path={`${urlBase}/chat`} render={(props) => this.withTokenCheck(<Chat {...props}/>)}/> + <Route path={`${urlBase}/rooms`} render={(props) => this.withTokenCheck(<Rooms {...props}/>)}/> + <Route path={`${urlBase}/uploads`} render={(props) => this.withTokenCheck(<Transfers {...props} direction='upload'/>)}/> + <Route path={`${urlBase}/downloads`} render={(props) => this.withTokenCheck(<Transfers {...props} direction='download'/>)}/> + <Route path={`${urlBase}/system/:tab?`} render={(props) => this.withTokenCheck(<System {...props} state={applicationState} options={applicationOptions}/>)}/> + <Redirect from='*' to={`${urlBase}/searches`}/> </Switch> </Sidebar.Pusher> </Sidebar.Pushable> diff --git a/src/web/src/components/System/System.js b/src/web/src/components/System/System.js index 8b0ea4d4..ca88c50d 100644 --- a/src/web/src/components/System/System.js +++ b/src/web/src/components/System/System.js @@ -1,24 +1,45 @@ -import React, { Component } from 'react'; +import React from 'react'; +import { useRouteMatch, useHistory, Redirect } from "react-router-dom"; + import { Segment, Tab } from 'semantic-ui-react'; + import './System.css'; + import Info from './Info'; import Logs from './Logs'; import Options from './Options'; -class System extends Component { - render = () => { - return ( - <div className='system'> - <Segment raised> - <Tab panes={[ - { menuItem: 'Info', render: () => <Tab.Pane><Info state={this.props.state}/></Tab.Pane> }, - { menuItem: 'Options', render: () => <Tab.Pane className='full-height'><Options options={this.props.options}/></Tab.Pane> }, - { menuItem: 'Logs', render: () => <Tab.Pane><Logs/></Tab.Pane> }, - ]}/> - </Segment> - </div> - ); +const System = ({ state = {}, options = {} }) => { + const { params: { tab }, ...route } = useRouteMatch(); + const history = useHistory(); + + const panes = [ + { route: 'info', menuItem: 'Info', render: () => <Tab.Pane><Info state={state}/></Tab.Pane> }, + { route: 'options', menuItem: 'Options', render: () => <Tab.Pane className='full-height'><Options options={options}/></Tab.Pane> }, + { route: 'logs', menuItem: 'Logs', render: () => <Tab.Pane><Logs/></Tab.Pane> }, + ] + + const activeIndex = panes.findIndex(pane => pane.route === tab) + + const onTabChange = (e, { activeIndex }) => { + history.push(panes[activeIndex].route) + } + + if (tab === undefined) { + return <Redirect to={`${route.url}/${panes[0].route}`}/> } -} + + return ( + <div className='system'> + <Segment raised> + <Tab + activeIndex={activeIndex > -1 ? activeIndex : 0} + panes={panes} + onTabChange={onTabChange} + /> + </Segment> + </div> + ); +}; export default System;
\ No newline at end of file diff --git a/src/web/src/components/Users/Users.js b/src/web/src/components/Users/Users.js index d07772e7..7927b718 100644 --- a/src/web/src/components/Users/Users.js +++ b/src/web/src/components/Users/Users.js @@ -45,7 +45,7 @@ const Users = (props) => { try { const [info, status, endpoint] = await Promise.all([ - users.getInfo({ username: selectedUsername, bypassCache: true }), + users.getInfo({ username: selectedUsername }), users.getStatus({ username: selectedUsername }), users.getEndpoint({ username: selectedUsername }) ]); diff --git a/src/web/src/config.js b/src/web/src/config.js index ea71e9dd..6f899564 100644 --- a/src/web/src/config.js +++ b/src/web/src/config.js @@ -1,5 +1,7 @@ -const rootUrl = process.env.NODE_ENV === 'production' ? '' : 'http://localhost:5000/'; -const baseUrl = `${rootUrl}api/v0`; +const urlBase = (window.urlBase === '/' ? '' : window.urlBase) || ''; +const rootUrl = process.env.NODE_ENV === 'production' ? urlBase : `http://localhost:5000/${urlBase}`; +const apiBaseUrl = `${rootUrl}/api/v0`; +const hubBaseUrl = `${rootUrl}/hub`; const tokenKey = 'slskd-token'; const tokenPassthroughValue = 'n/a'; const activeChatKey = 'slskd-active-chat'; @@ -7,8 +9,10 @@ const activeRoomKey = 'slskd-active-room'; const activeUserInfoKey = 'slskd-active-user'; export { + urlBase, rootUrl, - baseUrl, + apiBaseUrl, + hubBaseUrl, tokenKey, tokenPassthroughValue, activeChatKey, diff --git a/src/web/src/lib/api.js b/src/web/src/lib/api.js index 73e75373..0e7d8050 100644 --- a/src/web/src/lib/api.js +++ b/src/web/src/lib/api.js @@ -1,8 +1,8 @@ import axios from 'axios'; -import { baseUrl } from '../config'; +import { apiBaseUrl } from '../config'; import * as session from './session'; -axios.defaults.baseURL = baseUrl; +axios.defaults.baseURL = apiBaseUrl; const api = axios.create({ withCredentials: true diff --git a/src/web/src/lib/hubFactory.js b/src/web/src/lib/hubFactory.js index a64c5c40..246e9d03 100644 --- a/src/web/src/lib/hubFactory.js +++ b/src/web/src/lib/hubFactory.js @@ -4,7 +4,7 @@ import { LogLevel } from '@microsoft/signalr' -import { rootUrl } from '../config'; +import { hubBaseUrl } from '../config'; import * as session from '../lib/session'; export const createHubConnection = ({ url }) => @@ -18,6 +18,6 @@ export const createHubConnection = ({ url }) => .configureLogging(LogLevel.Warning) .build(); -export const createApplicationHubConnection = () => createHubConnection({ url: `${rootUrl}hub/application` }); +export const createApplicationHubConnection = () => createHubConnection({ url: `${hubBaseUrl}/application` }); -export const createLogsHubConnection = () => createHubConnection({ url: `${rootUrl}hub/logs` });
\ No newline at end of file +export const createLogsHubConnection = () => createHubConnection({ url: `${hubBaseUrl}/logs` });
\ No newline at end of file diff --git a/src/web/src/lib/rooms.js b/src/web/src/lib/rooms.js index c2a36187..c30a7a15 100644 --- a/src/web/src/lib/rooms.js +++ b/src/web/src/lib/rooms.js @@ -23,7 +23,7 @@ export const getJoined = async () => { }; export const getMessages = async ({ roomName }) => { - const response = (await api.get(`/rooms/joined/${roomName}/messages`)).data; + const response = (await api.get(`/rooms/joined/${encodeURIComponent(roomName)}/messages`)).data; if (!Array.isArray(response)) { console.warn('got non-array response from rooms API', response) @@ -34,7 +34,7 @@ export const getMessages = async ({ roomName }) => { }; export const getUsers = async ({ roomName }) => { - const response = (await api.get(`/rooms/joined/${roomName}/users`)).data; + const response = (await api.get(`/rooms/joined/${encodeURIComponent(roomName)}/users`)).data; if (!Array.isArray(response)) { console.warn('got non-array response from rooms API', response) @@ -45,13 +45,13 @@ export const getUsers = async ({ roomName }) => { }; export const join = async ({ roomName }) => { - return api.post(`/rooms/joined/${roomName}`); + return api.post('/rooms/joined', roomName); }; export const leave = async ({ roomName }) => { - return api.delete(`/rooms/joined/${roomName}`); + return api.delete(`/rooms/joined/${encodeURIComponent(roomName)}`); }; export const sendMessage = async ({ roomName, message }) => { - return api.post(`/rooms/joined/${roomName}/messages`, JSON.stringify(message)); + return api.post(`/rooms/joined/${encodeURIComponent(roomName)}/messages`, JSON.stringify(message)); };
\ No newline at end of file diff --git a/src/web/src/lib/users.js b/src/web/src/lib/users.js index a8cd4f88..f79cea20 100644 --- a/src/web/src/lib/users.js +++ b/src/web/src/lib/users.js @@ -1,21 +1,21 @@ import api from './api'; -export const getInfo = ({ username, bypassCache = false }) => { - return api.get(`/users/${username}/info?bypassCache=${bypassCache}`); +export const getInfo = ({ username }) => { + return api.get(`/users/${encodeURIComponent(username)}/info`); }; export const getStatus = ({ username }) => { - return api.get(`/users/${username}/status`); + return api.get(`/users/${encodeURIComponent(username)}/status`); }; export const getEndpoint = ({ username }) => { - return api.get(`/users/${username}/endpoint`); + return api.get(`/users/${encodeURIComponent(username)}/endpoint`); }; export const browse = async ({ username }) => { - return (await api.get(`/users/${username}/browse`)).data; + return (await api.get(`/users/${encodeURIComponent(username)}/browse`)).data; }; export const getBrowseStatus = ({ username }) => { - return api.get(`/users/${username}/browse/status`); + return api.get(`/users/${encodeURIComponent(username)}/browse/status`); };
\ No newline at end of file |
