aboutsummaryrefslogtreecommitdiffstats
path: root/src/web
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2022-05-02 22:36:10 -0500
committerJP Dillingham <jpdillingham@gmail.com>2022-05-02 22:36:10 -0500
commit581fa92428ec49f63421119a7bfcfef4e46df80a (patch)
tree5ec183833fcbf6a7fa7b713cba4d255e6ae909a5 /src/web
parenta87cfb19040b102cc564107e3439e5f2b9a1a745 (diff)
downloadslskd-581fa92428ec49f63421119a7bfcfef4e46df80a.tar.gz
fix routing
Diffstat (limited to 'src/web')
-rw-r--r--src/web/src/components/App.js20
-rw-r--r--src/web/src/components/Search/List/SearchListRow.js7
-rw-r--r--src/web/src/components/Search/Searches.js8
-rw-r--r--src/web/src/config.js17
-rw-r--r--src/web/src/lib/api.js6
5 files changed, 42 insertions, 16 deletions
diff --git a/src/web/src/components/App.js b/src/web/src/components/App.js
index 8fa6bcaa..75db94b2 100644
--- a/src/web/src/components/App.js
+++ b/src/web/src/components/App.js
@@ -1,5 +1,7 @@
import React, { Component } from 'react';
-import { Route, Link, Switch } from "react-router-dom";
+import { Route, Link, Switch, Redirect } from "react-router-dom";
+
+import { reactRouterBaseUrl } from '../config';
import * as session from '../lib/session';
import { connect, disconnect } from '../lib/server';
@@ -151,37 +153,37 @@ class App extends Component {
{version.isCanary && <Menu.Item>
<Icon name='flask' color='yellow'/>Canary
</Menu.Item>}
- <Link to='.'>
+ <Link to={`${reactRouterBaseUrl}/searches`}>
<Menu.Item>
<Icon name='search'/>Search
</Menu.Item>
</Link>
- <Link to='downloads'>
+ <Link to={`${reactRouterBaseUrl}/downloads`}>
<Menu.Item>
<Icon name='download'/>Downloads
</Menu.Item>
</Link>
- <Link to='uploads'>
+ <Link to={`${reactRouterBaseUrl}/uploads`}>
<Menu.Item>
<Icon name='upload'/>Uploads
</Menu.Item>
</Link>
- <Link to='rooms'>
+ <Link to={`${reactRouterBaseUrl}/rooms`}>
<Menu.Item>
<Icon name='comments'/>Rooms
</Menu.Item>
</Link>
- <Link to='chat'>
+ <Link to={`${reactRouterBaseUrl}/chat`}>
<Menu.Item>
<Icon name='comment'/>Chat
</Menu.Item>
</Link>
- <Link to='users'>
+ <Link to={`${reactRouterBaseUrl}/users`}>
<Menu.Item>
<Icon name='users'/>Users
</Menu.Item>
</Link>
- <Link to='browse'>
+ <Link to={`${reactRouterBaseUrl}/browse`}>
<Menu.Item>
<Icon name='folder open'/>Browse
</Menu.Item>
@@ -251,7 +253,7 @@ class App extends Component {
<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}/>)}/>
+ <Redirect from='*' to='/searches'/>
</Switch>
</Sidebar.Pusher>
</Sidebar.Pushable>
diff --git a/src/web/src/components/Search/List/SearchListRow.js b/src/web/src/components/Search/List/SearchListRow.js
index 24d24082..efac68a7 100644
--- a/src/web/src/components/Search/List/SearchListRow.js
+++ b/src/web/src/components/Search/List/SearchListRow.js
@@ -1,4 +1,8 @@
import React, { useState } from 'react';
+import {
+ Link,
+ useRouteMatch,
+} from "react-router-dom";
import SearchStatusIcon from './SearchStatusIcon';
import SearchActionIcon from './SearchActionIcon';
@@ -10,6 +14,7 @@ import {
const SearchListRow = ({ search, onRemove, onStop }) => {
const [working, setWorking] = useState(false);
+ const match = useRouteMatch();
const invoke = async (func) => {
setWorking(true);
@@ -27,7 +32,7 @@ const SearchListRow = ({ search, onRemove, onStop }) => {
state={search.state}
/>
</Table.Cell>
- <Table.Cell><a href={`searches/${search.id}`}>{search.searchText}</a></Table.Cell>
+ <Table.Cell><Link to={`${match.url}/${search.id}`}>{search.searchText}</Link></Table.Cell>
<Table.Cell>{search.fileCount}</Table.Cell>
<Table.Cell><Icon name="lock" color="yellow" size="small"/>{search.lockedFileCount}</Table.Cell>
<Table.Cell>{search.responseCount}</Table.Cell>
diff --git a/src/web/src/components/Search/Searches.js b/src/web/src/components/Search/Searches.js
index 8748aade..e770b829 100644
--- a/src/web/src/components/Search/Searches.js
+++ b/src/web/src/components/Search/Searches.js
@@ -1,4 +1,11 @@
import React, { useState, useEffect, useRef } from 'react';
+import {
+ BrowserRouter as Router,
+ Switch,
+ Route,
+ Link,
+ useParams
+} from "react-router-dom";
import { v4 as uuidv4 } from 'uuid';
@@ -19,6 +26,7 @@ const Searches = () => {
const [{ creating, createError }, setCreating] = useState({ creating: false, createError: false });
const [error, setError] = useState(undefined);
const [searches, setSearches] = useState({});
+ const params = useParams();
const inputRef = useRef();
const onConnecting = () => setConnected({ connected: false, connecting: true, connectError: false })
diff --git a/src/web/src/config.js b/src/web/src/config.js
index ea71e9dd..4e0781f5 100644
--- a/src/web/src/config.js
+++ b/src/web/src/config.js
@@ -1,17 +1,28 @@
const rootUrl = process.env.NODE_ENV === 'production' ? '' : 'http://localhost:5000/';
-const baseUrl = `${rootUrl}api/v0`;
+const apiBaseUrl = `${rootUrl}api/v0`;
const tokenKey = 'slskd-token';
const tokenPassthroughValue = 'n/a';
const activeChatKey = 'slskd-active-chat';
const activeRoomKey = 'slskd-active-room';
const activeUserInfoKey = 'slskd-active-user';
+// url base is the value of the url base from config;
+// the route used when behind a reverse proxy. we
+// need this value so we can be explicit with react-router.
+let reactRouterBaseUrl;
+
+const setReactRouterBaseUrl = (url) => {
+ reactRouterBaseUrl = (url === '/' ? '' : url);
+};
+
export {
rootUrl,
- baseUrl,
+ apiBaseUrl,
+ reactRouterBaseUrl,
tokenKey,
tokenPassthroughValue,
activeChatKey,
activeRoomKey,
- activeUserInfoKey
+ activeUserInfoKey,
+ setReactRouterBaseUrl,
};
diff --git a/src/web/src/lib/api.js b/src/web/src/lib/api.js
index ef1fd31a..02fe2eca 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, setUrlBase } from '../config';
+import { apiBaseUrl, setReactRouterBaseUrl } from '../config';
import * as session from './session';
-axios.defaults.baseURL = baseUrl;
+axios.defaults.baseURL = apiBaseUrl;
const api = axios.create({
withCredentials: true
@@ -24,7 +24,7 @@ api.interceptors.response.use(response => {
// when behind a reverse proxy, we need the configured url base
// so that we can be explicit with react-router. every API response
// should contain this header, and it should be the same.
- setUrlBase(response.headers['x-url-base']);
+ setReactRouterBaseUrl(response.headers['x-url-base']);
return response;
}, error => {
if (error.response.status === 401 && !['/session', '/server', '/application'].includes(error.response.config.url)) {