From 1c3a6246738a8fa1a2bce401ab29d8d0d2f23231 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 10 Nov 2022 18:00:21 -0600 Subject: split navigation into mode-specific versions --- src/web/src/components/App.js | 225 +++++++++++++++++++++++++----------------- 1 file changed, 137 insertions(+), 88 deletions(-) (limited to 'src/web') diff --git a/src/web/src/components/App.js b/src/web/src/components/App.js index ea24924a..c55ab830 100644 --- a/src/web/src/components/App.js +++ b/src/web/src/components/App.js @@ -116,10 +116,20 @@ class App extends Component { render = () => { const { login, applicationState = {}, applicationOptions = {}, error, initialized, retriesExhausted } = this.state; - const { version = {}, server, pendingReconnect, pendingRestart, shares = {}, user } = applicationState; + const { + version = {}, + network = {}, + server, + pendingReconnect, + pendingRestart, + shares = {}, + user, + } = applicationState; const { isUpdateAvailable, current, latest } = version; const { scanPending: pendingShareRescan } = shares; + const { mode } = network; + if (!initialized) { return ; } @@ -148,6 +158,129 @@ class App extends Component { ); } + const ModeSpecificNavigation = ({ mode }) => { + if (mode === 'Agent') { + return + + Agent + + ; + } else { + return <> + + + Search + + + + + Downloads + + + + + Uploads + + + + + Rooms + + + + + Chat + + + + + Users + + + + + Browse + + + ; + } + }; + + const ModeSpecificConnectButton = ({ mode, server }) => { + if (mode === 'Agent') { + return <>; + } else { + return <> + {server?.isConnected && disconnect()} + > + + + {user?.privileges?.isPrivileged && + } + Connected + } + {(!server?.isConnected) && connect()} + > + + + + Disconnected + } + {(pendingReconnect || pendingRestart || pendingShareRescan) && + + + + + Pending Action + }; + } + }; + + const ModeSpecificRoutes = ({ mode }) => { + if (mode === 'Agent') { + return <> + this.withTokenCheck( + + ) + }/> + + ; + } else { + return <> + + this.withTokenCheck(
+ +
)} + /> + this.withTokenCheck()}/> + this.withTokenCheck()}/> + this.withTokenCheck()}/> + this.withTokenCheck()}/> + + this.withTokenCheck(
) + }/> + + this.withTokenCheck(
+ +
) + }/> + this.withTokenCheck( + + ) + }/> + ; + } + }; + return ( <> @@ -164,66 +297,9 @@ class App extends Component { {version.isCanary && Canary } - - - Search - - - - - Downloads - - - - - Uploads - - - - - Rooms - - - - - Chat - - - - - Users - - - - - Browse - - + - {server?.isConnected && disconnect()} - > - - - {user?.privileges?.isPrivileged && - } - Connected - } - {(!server?.isConnected) && connect()} - > - - - - Disconnected - } - {(pendingReconnect || pendingRestart || pendingShareRescan) && - - - - - Pending Action - } + {isUpdateAvailable && @@ -271,34 +347,7 @@ class App extends Component { - - this.withTokenCheck(
- -
)} - /> - this.withTokenCheck()}/> - this.withTokenCheck()}/> - this.withTokenCheck()}/> - this.withTokenCheck()}/> - - this.withTokenCheck(
) - }/> - - this.withTokenCheck(
- -
) - }/> - this.withTokenCheck( - - ) - }/> - +
-- cgit v1.2.3 From ee32613a71707dd49f14e60c0bf0a2f356bc15f4 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 11 Nov 2022 17:39:22 -0600 Subject: add network lib --- src/web/src/lib/network.js | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/web/src/lib/network.js (limited to 'src/web') diff --git a/src/web/src/lib/network.js b/src/web/src/lib/network.js new file mode 100644 index 00000000..07ed89e3 --- /dev/null +++ b/src/web/src/lib/network.js @@ -0,0 +1,9 @@ +import api from './api'; + +export const connect = () => { + return api.put('/network'); +}; + +export const disconnect = () => { + return api.delete('/network'); +}; \ No newline at end of file -- cgit v1.2.3 From 7bc7e55208118ea622d72950648d09ccc6c816ee Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 11 Nov 2022 17:40:02 -0600 Subject: add agent navigation ui --- src/web/src/components/App.js | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'src/web') diff --git a/src/web/src/components/App.js b/src/web/src/components/App.js index c55ab830..0439943b 100644 --- a/src/web/src/components/App.js +++ b/src/web/src/components/App.js @@ -5,6 +5,7 @@ import { ToastContainer } from 'react-toastify'; import 'react-toastify/dist/ReactToastify.css'; import * as session from '../lib/session'; +import * as networkAPI from '../lib/network'; import { connect, disconnect } from '../lib/server'; import { urlBase } from '../config'; @@ -128,7 +129,7 @@ class App extends Component { const { isUpdateAvailable, current, latest } = version; const { scanPending: pendingShareRescan } = shares; - const { mode } = network; + const { mode, controller } = network; if (!initialized) { return ; @@ -160,11 +161,9 @@ class App extends Component { const ModeSpecificNavigation = ({ mode }) => { if (mode === 'Agent') { - return - - Agent - - ; + return + Agent Mode + ; } else { return <> @@ -206,9 +205,21 @@ class App extends Component { } }; - const ModeSpecificConnectButton = ({ mode, server }) => { + const ModeSpecificConnectButton = ({ mode, server, controller = {} }) => { if (mode === 'Agent') { - return <>; + const isConnected = controller?.state === 'Connected'; + const isTransitioning = ['Connecting', 'Reconnecting'].includes(controller?.state); + + return <> + isConnected ? networkAPI.connect() : networkAPI.disconnect()} + > + + + {!isConnected && } + Controller {controller?.state} + + ; } else { return <> {server?.isConnected && } - + {isUpdateAvailable && -- cgit v1.2.3 From 46c76a768f515214dfaf3b58b79bc0ca48aa8a71 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 15 Nov 2022 10:18:47 -0600 Subject: update network references --- src/web/src/components/App.js | 8 ++++---- src/web/src/lib/network.js | 9 --------- src/web/src/lib/relay.js | 9 +++++++++ 3 files changed, 13 insertions(+), 13 deletions(-) delete mode 100644 src/web/src/lib/network.js create mode 100644 src/web/src/lib/relay.js (limited to 'src/web') diff --git a/src/web/src/components/App.js b/src/web/src/components/App.js index 0439943b..8e31741c 100644 --- a/src/web/src/components/App.js +++ b/src/web/src/components/App.js @@ -5,7 +5,7 @@ import { ToastContainer } from 'react-toastify'; import 'react-toastify/dist/ReactToastify.css'; import * as session from '../lib/session'; -import * as networkAPI from '../lib/network'; +import * as relay from '../lib/relay'; import { connect, disconnect } from '../lib/server'; import { urlBase } from '../config'; @@ -119,7 +119,7 @@ class App extends Component { const { login, applicationState = {}, applicationOptions = {}, error, initialized, retriesExhausted } = this.state; const { version = {}, - network = {}, + relay = {}, server, pendingReconnect, pendingRestart, @@ -129,7 +129,7 @@ class App extends Component { const { isUpdateAvailable, current, latest } = version; const { scanPending: pendingShareRescan } = shares; - const { mode, controller } = network; + const { mode, controller } = relay; if (!initialized) { return ; @@ -212,7 +212,7 @@ class App extends Component { return <> isConnected ? networkAPI.connect() : networkAPI.disconnect()} + onClick={() => isConnected ? relay.connect() : relay.disconnect()} > diff --git a/src/web/src/lib/network.js b/src/web/src/lib/network.js deleted file mode 100644 index 07ed89e3..00000000 --- a/src/web/src/lib/network.js +++ /dev/null @@ -1,9 +0,0 @@ -import api from './api'; - -export const connect = () => { - return api.put('/network'); -}; - -export const disconnect = () => { - return api.delete('/network'); -}; \ No newline at end of file diff --git a/src/web/src/lib/relay.js b/src/web/src/lib/relay.js new file mode 100644 index 00000000..b20d0af2 --- /dev/null +++ b/src/web/src/lib/relay.js @@ -0,0 +1,9 @@ +import api from './api'; + +export const connect = () => { + return api.put('/relay'); +}; + +export const disconnect = () => { + return api.delete('/relay'); +}; \ No newline at end of file -- cgit v1.2.3 From 17d635f9471747de03f2cf98d2a3bd9474182dbc Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 15 Nov 2022 10:26:16 -0600 Subject: add default route back --- src/web/src/components/App.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/web') diff --git a/src/web/src/components/App.js b/src/web/src/components/App.js index 8e31741c..9380f19d 100644 --- a/src/web/src/components/App.js +++ b/src/web/src/components/App.js @@ -5,7 +5,7 @@ import { ToastContainer } from 'react-toastify'; import 'react-toastify/dist/ReactToastify.css'; import * as session from '../lib/session'; -import * as relay from '../lib/relay'; +import * as relayAPI from '../lib/relay'; import { connect, disconnect } from '../lib/server'; import { urlBase } from '../config'; @@ -212,7 +212,7 @@ class App extends Component { return <> isConnected ? relay.connect() : relay.disconnect()} + onClick={() => isConnected ? relayAPI.connect() : relayAPI.disconnect()} > @@ -288,6 +288,7 @@ class App extends Component { ) }/> + ; } }; -- cgit v1.2.3 From 01b5eb5a02cc54d316cbdcba65f9ba5ae94526da Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Wed, 16 Nov 2022 09:18:27 -0600 Subject: fix rerender issue --- src/web/src/components/App.js | 200 ++++++++++++++++++++---------------------- 1 file changed, 97 insertions(+), 103 deletions(-) (limited to 'src/web') diff --git a/src/web/src/components/App.js b/src/web/src/components/App.js index 9380f19d..66fa3945 100644 --- a/src/web/src/components/App.js +++ b/src/web/src/components/App.js @@ -158,64 +158,23 @@ class App extends Component { /> ); } - - const ModeSpecificNavigation = ({ mode }) => { - if (mode === 'Agent') { - return - Agent Mode - ; - } else { - return <> - - - Search - - - - - Downloads - - - - - Uploads - - - - - Rooms - - - - - Chat - - - - - Users - - - - - Browse - - - ; - } - }; - + const ModeSpecificConnectButton = ({ mode, server, controller = {} }) => { - if (mode === 'Agent') { + if (mode !== 'Agent') { const isConnected = controller?.state === 'Connected'; const isTransitioning = ['Connecting', 'Reconnecting'].includes(controller?.state); return <> isConnected ? relayAPI.connect() : relayAPI.disconnect()} + onClick={() => isConnected ? relayAPI.disconnect() : relayAPI.connect()} > - + {!isConnected && } Controller {controller?.state} @@ -239,60 +198,12 @@ class App extends Component { Disconnected } - {(pendingReconnect || pendingRestart || pendingShareRescan) && - - - - - Pending Action - }; - } - }; - - const ModeSpecificRoutes = ({ mode }) => { - if (mode === 'Agent') { - return <> - this.withTokenCheck( - - ) - }/> - - ; - } else { - return <> - - this.withTokenCheck(
- -
)} - /> - this.withTokenCheck()}/> - this.withTokenCheck()}/> - this.withTokenCheck()}/> - this.withTokenCheck()}/> - - this.withTokenCheck(
) - }/> - - this.withTokenCheck(
- -
) - }/> - this.withTokenCheck( - - ) - }/> - ; } }; + const isAgent = mode !== 'Agent'; + return ( <> @@ -309,9 +220,55 @@ class App extends Component { {version.isCanary && Canary } - + {isAgent ? + Agent Mode + : + <> + + + Search + + + + + Downloads + + + + + Uploads + + + + + Rooms + + + + + Chat + + + + + Users + + + + + Browse + + + } - + + {(pendingReconnect || pendingRestart || pendingShareRescan) && + + + + + Pending Action + } {isUpdateAvailable && @@ -359,7 +316,44 @@ class App extends Component { - + {isAgent ? <> + this.withTokenCheck( + + ) + }/> + + : + <> + + this.withTokenCheck(
+ +
)} + /> + this.withTokenCheck()}/> + this.withTokenCheck()}/> + this.withTokenCheck()}/> + this.withTokenCheck()}/> + + this.withTokenCheck(
) + }/> + + this.withTokenCheck(
+ +
) + }/> + this.withTokenCheck( + + ) + }/> + + }
-- cgit v1.2.3 From a382bac1eb8bc1c8abeaef545b06c0d7ea48c358 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Wed, 16 Nov 2022 09:29:38 -0600 Subject: remove debugging --- src/web/src/components/App.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/web') diff --git a/src/web/src/components/App.js b/src/web/src/components/App.js index 66fa3945..df65bc20 100644 --- a/src/web/src/components/App.js +++ b/src/web/src/components/App.js @@ -160,7 +160,7 @@ class App extends Component { } const ModeSpecificConnectButton = ({ mode, server, controller = {} }) => { - if (mode !== 'Agent') { + if (mode === 'Agent') { const isConnected = controller?.state === 'Connected'; const isTransitioning = ['Connecting', 'Reconnecting'].includes(controller?.state); @@ -202,7 +202,7 @@ class App extends Component { } }; - const isAgent = mode !== 'Agent'; + const isAgent = mode === 'Agent'; return ( <> -- cgit v1.2.3