aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2022-05-03 09:59:57 -0500
committerGitHub <noreply@github.com>2022-05-03 09:59:57 -0500
commit09adf4655f43ab6abeba1d1ac219df94d70c634c (patch)
tree06c3f12f92f1174eef8548e5d39b0f0e23d4ad7d /src
parent8ac38c8065763443dd84c5eafafe8a372de3e9db (diff)
parent12f2aded2257a7dcc9dbb00cbbd8bafc28579ad4 (diff)
downloadslskd-09adf4655f43ab6abeba1d1ac219df94d70c634c.tar.gz
Merge pull request #450 from slskd/routing
Fix bug preventing routes with more than one segment from working
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Core/API/Controllers/ApplicationController.cs11
-rw-r--r--src/web/src/components/App.js34
-rw-r--r--src/web/src/components/System/System.js51
-rw-r--r--src/web/src/lib/application.js4
4 files changed, 72 insertions, 28 deletions
diff --git a/src/slskd/Core/API/Controllers/ApplicationController.cs b/src/slskd/Core/API/Controllers/ApplicationController.cs
index 19360fe1..9f38a17f 100644
--- a/src/slskd/Core/API/Controllers/ApplicationController.cs
+++ b/src/slskd/Core/API/Controllers/ApplicationController.cs
@@ -15,6 +15,8 @@
// along with this program. If not, see https://www.gnu.org/licenses/.
// </copyright>
+using Microsoft.Extensions.Options;
+
namespace slskd.Core.API
{
using System;
@@ -37,15 +39,18 @@ namespace slskd.Core.API
public ApplicationController(
IHostApplicationLifetime lifetime,
IApplication application,
+ IOptionsMonitor<Options> optionsMonitor,
IStateMonitor<State> applicationStateMonitor)
{
Lifetime = lifetime;
Application = application;
+ OptionsMonitor = optionsMonitor;
ApplicationStateMonitor = applicationStateMonitor;
}
private IApplication Application { get; }
private IStateMonitor<State> ApplicationStateMonitor { get; }
+ private IOptionsMonitor<Options> OptionsMonitor { get; }
private IHostApplicationLifetime Lifetime { get; }
/// <summary>
@@ -146,5 +151,11 @@ namespace slskd.Core.API
return Ok();
}
+
+ [HttpGet("urlbase")]
+ public IActionResult GetUrlBase()
+ {
+ return Ok(OptionsMonitor.CurrentValue.Web.UrlBase);
+ }
}
}
diff --git a/src/web/src/components/App.js b/src/web/src/components/App.js
index 3a22e0c8..19ea8d37 100644
--- a/src/web/src/components/App.js
+++ b/src/web/src/components/App.js
@@ -1,7 +1,8 @@
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 * as application from '../lib/application';
import { connect, disconnect } from '../lib/server';
import { createApplicationHubConnection } from '../lib/hubFactory';
@@ -38,6 +39,7 @@ const initialState = {
initialized: false,
error: false,
retriesExhausted: false,
+ urlBase: '',
};
class App extends Component {
@@ -50,7 +52,12 @@ class App extends Component {
init = async () => {
this.setState({ initialized: false }, async () => {
try {
- const securityEnabled = await session.getSecurityEnabled();
+ const [urlBase, securityEnabled] = await Promise.all([
+ application.getUrlBase(),
+ session.getSecurityEnabled()]
+ );
+
+ this.setState({ urlBase });
if (!securityEnabled) {
console.debug('application security is not enabled, per api call')
@@ -109,7 +116,7 @@ class App extends Component {
};
render = () => {
- const { login, applicationState = {}, applicationOptions = {}, error, initialized, retriesExhausted } = this.state;
+ const { login, applicationState = {}, applicationOptions = {}, error, initialized, retriesExhausted, urlBase = '' } = this.state;
const { version = {}, server } = applicationState;
const { isUpdateAvailable, current, latest } = version;
@@ -150,37 +157,37 @@ class App extends Component {
{version.isCanary && <Menu.Item>
<Icon name='flask' color='yellow'/>Canary
</Menu.Item>}
- <Link to='.'>
+ <Link to={`${urlBase}`}>
<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 +228,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 +249,15 @@ class App extends Component {
</Sidebar>
<Sidebar.Pusher className='app-content'>
<Switch>
+ <Route path='*/searches' render={(props) => this.withTokenCheck(<Search {...props}/>)}/>
<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='*/system/:tab?' render={(props) => this.withTokenCheck(<System 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/lib/application.js b/src/web/src/lib/application.js
index 0c8b8319..da5bbef5 100644
--- a/src/web/src/lib/application.js
+++ b/src/web/src/lib/application.js
@@ -4,6 +4,10 @@ export const getState = async () => {
return (await api.get('/application')).data;
};
+export const getUrlBase = async () => {
+ return (await api.get('/application/urlbase')).data;
+}
+
export const restart = async () => {
return api.put('/application');
};