mirror of
https://github.com/Permissionless-Software-Foundation/psf-memo-client.git
synced 2026-09-21 16:52:02 -07:00
fix(router): Refactored to add browser router functionality
This commit is contained in:
Generated
+2
@@ -12799,6 +12799,8 @@
|
||||
"node_modules/node-fetch": {
|
||||
"name": "@achingbrain/node-fetch",
|
||||
"version": "2.6.7",
|
||||
"resolved": "https://registry.npmjs.org/@achingbrain/node-fetch/-/node-fetch-2.6.7.tgz",
|
||||
"integrity": "sha512-iTASGs+HTFK5E4ZqcMsHmeJ4zodyq8L38lZV33jwqcBJYoUt3HjN4+ot+O9/0b+ke8ddE7UgOtVuZN/OkV19/g==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
|
||||
@@ -21,8 +21,13 @@
|
||||
|
||||
.nav-link-active {
|
||||
color: white !important;
|
||||
text-decoration: none;
|
||||
padding: 0.5rem;
|
||||
}
|
||||
|
||||
.nav-link-inactive {
|
||||
color: gray !important;
|
||||
text-decoration: none;
|
||||
padding: 0.5rem;
|
||||
|
||||
}
|
||||
|
||||
+2
-4
@@ -9,7 +9,6 @@ import React, { useEffect, useCallback } from 'react'
|
||||
import './App.css'
|
||||
import LoadScripts from './components/load-scripts'
|
||||
import AsyncLoad from './services/async-load'
|
||||
import SelectServerButton from './components/app-body/servers/select-server-button'
|
||||
import Footer from './components/footer'
|
||||
import NavMenu from './components/nav-menu'
|
||||
import useAppState from './hooks/state'
|
||||
@@ -92,14 +91,13 @@ function App (props) {
|
||||
<LoadScripts />
|
||||
<div className='app-container'>
|
||||
<NavMenu appData={appData} />
|
||||
{/** Define View to show */}
|
||||
<div className='main-content'>
|
||||
{/** Define View to show */}
|
||||
<div className='main-content'>
|
||||
{
|
||||
appData.showStartModal
|
||||
? (<UninitializedView appData={appData} />)
|
||||
: (<InitializedView menuState={appData.menuState} appData={appData} />)
|
||||
}
|
||||
<SelectServerButton appData={appData} />
|
||||
</div>
|
||||
<Footer appData={appData} />
|
||||
</div>
|
||||
|
||||
@@ -8,30 +8,32 @@
|
||||
|
||||
// Global npm libraries
|
||||
import React from 'react'
|
||||
import { BrowserRouter, Route, Routes } from 'react-router-dom'
|
||||
import { Route, Routes } from 'react-router-dom'
|
||||
|
||||
// Local libraries
|
||||
import GetBalance from './balance'
|
||||
import Placeholder2 from './placeholder2'
|
||||
import Placeholder3 from './placeholder3'
|
||||
import ServerSelectView from './servers/select-server-view'
|
||||
import SelectServerButton from './servers/select-server-button'
|
||||
|
||||
function AppBody (props) {
|
||||
// Dependency injection through props
|
||||
const appData = props.appData
|
||||
// const menuState = props.menuState
|
||||
// Dependency injection through props
|
||||
const appData = props.appData
|
||||
|
||||
return (
|
||||
<BrowserRouter>
|
||||
<Routes>
|
||||
<Route path='/' element={<GetBalance wallet={appData.wallet} />} />
|
||||
<Route path='/balance' element={<GetBalance wallet={appData.wallet} />} />
|
||||
<Route path='/placeholder2' element={<Placeholder2 />} />
|
||||
<Route path='/placeholder3' element={<Placeholder3 />} />
|
||||
<Route path='/servers' element={<ServerSelectView appData={appData} />} />
|
||||
</Routes>
|
||||
</BrowserRouter>
|
||||
)
|
||||
return (
|
||||
<>
|
||||
<Routes>
|
||||
<Route path='/' element={<GetBalance wallet={appData.wallet} />} />
|
||||
<Route path='/balance' element={<GetBalance wallet={appData.wallet} />} />
|
||||
<Route path='/placeholder2' element={<Placeholder2 />} />
|
||||
<Route path='/placeholder3' element={<Placeholder3 />} />
|
||||
<Route path='/servers' element={<ServerSelectView appData={appData} />} />
|
||||
</Routes>
|
||||
{/** Show in all paths except the servers view */}
|
||||
{appData.currentPath !== '/servers' && <SelectServerButton linkTo='/servers' />}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export default AppBody
|
||||
|
||||
@@ -6,32 +6,39 @@
|
||||
// Global npm libraries
|
||||
import React from 'react'
|
||||
import { Container, Row, Col, Button } from 'react-bootstrap'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
|
||||
const ServerSelect = (props) => {
|
||||
const { appData } = props
|
||||
const { linkTo } = props
|
||||
|
||||
// Use the navigate function to navigate to the servers view
|
||||
const navigate = useNavigate()
|
||||
|
||||
// This is a click handler for the server select button. It brings up the
|
||||
// server selection View.
|
||||
const handleServerSelect = () => {
|
||||
console.log('This function should navigate to the server selection view.')
|
||||
appData.setMenuState(100)
|
||||
navigate(linkTo)
|
||||
}
|
||||
|
||||
return (
|
||||
<Container>
|
||||
<hr />
|
||||
<Row>
|
||||
<Col style={{ textAlign: 'center', padding: '25px' }}>
|
||||
<br />
|
||||
<h5>
|
||||
Having trouble loading? Try selecting a different back-end server.
|
||||
</h5>
|
||||
<Button variant='warning' onClick={handleServerSelect}>
|
||||
Select a different back end server
|
||||
</Button>
|
||||
<br />
|
||||
</Col>
|
||||
</Row>
|
||||
<>
|
||||
<hr />
|
||||
<Row>
|
||||
<Col style={{ textAlign: 'center', padding: '25px' }}>
|
||||
<br />
|
||||
<h5>
|
||||
Having trouble loading? Try selecting a different back-end server.
|
||||
</h5>
|
||||
<Button variant='warning' onClick={handleServerSelect}>
|
||||
Select a different back end server
|
||||
</Button>
|
||||
<br />
|
||||
</Col>
|
||||
|
||||
</Row>
|
||||
</>
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -6,20 +6,29 @@
|
||||
*/
|
||||
|
||||
// Global npm libraries
|
||||
import React from 'react'
|
||||
import { Nav, Navbar, Image } from 'react-bootstrap'
|
||||
import React, { useState } from 'react'
|
||||
import { Nav, Navbar, Image } from 'react-bootstrap' // Used for Navbar Style and Layouts .
|
||||
import { NavLink } from 'react-router-dom' // Used to navigate between routes
|
||||
|
||||
// Assets
|
||||
import Logo from './psf-logo.png'
|
||||
|
||||
function NavMenu (props) {
|
||||
const selectedMenu = props.appData.menuState
|
||||
// const handleClickEvent = (menuItem) => {
|
||||
// // Pass the selected menu item up to the parent component.
|
||||
// props.appData.setMenuState(menuItem)
|
||||
// }
|
||||
// Get the current path
|
||||
const { currentPath } = props.appData
|
||||
|
||||
// Navbar state
|
||||
const [expanded, setExpanded] = useState(false)
|
||||
|
||||
// Handle click event
|
||||
const handleClickEvent = () => {
|
||||
// Collapse the navbar
|
||||
setExpanded(false)
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Navbar collapseOnSelect expand='xxxl' bg='dark' variant='dark' style={{ paddingRight: '20px' }}>
|
||||
<Navbar expanded={expanded} onToggle={setExpanded} expand='xxxl' bg='dark' variant='dark' style={{ paddingRight: '20px' }}>
|
||||
<Navbar.Brand href='#home' style={{ paddingLeft: '20px' }}>
|
||||
<Image src={Logo} thumbnail width='50' />{' '}
|
||||
PSF Web3 Demo
|
||||
@@ -28,24 +37,28 @@ function NavMenu (props) {
|
||||
<Navbar.Toggle aria-controls='responsive-navbar-nav' />
|
||||
<Navbar.Collapse id='responsive-navbar-nav'>
|
||||
<Nav className='mr-auto'>
|
||||
<Nav.Link
|
||||
className={selectedMenu === 0 ? 'nav-link-active' : 'nav-link-inactive'}
|
||||
href='/balance'
|
||||
<NavLink
|
||||
className={(currentPath === '/balance' || currentPath === '/') ? 'nav-link-active' : 'nav-link-inactive'}
|
||||
to='/balance'
|
||||
onClick={handleClickEvent}
|
||||
>
|
||||
Check Balance
|
||||
</Nav.Link>
|
||||
<Nav.Link
|
||||
className={selectedMenu === 1 ? 'nav-link-active' : 'nav-link-inactive'}
|
||||
href='/placeholder2'
|
||||
</NavLink>
|
||||
<NavLink
|
||||
className={currentPath === '/placeholder2' ? 'nav-link-active' : 'nav-link-inactive'}
|
||||
to='/placeholder2'
|
||||
onClick={handleClickEvent}
|
||||
|
||||
>
|
||||
Placeholder2
|
||||
</Nav.Link>
|
||||
<Nav.Link
|
||||
className={selectedMenu === 2 ? 'nav-link-active' : 'nav-link-inactive'}
|
||||
href='/placeholder3'
|
||||
</NavLink>
|
||||
<NavLink
|
||||
className={currentPath === '/placeholder3' ? 'nav-link-active' : 'nav-link-inactive'}
|
||||
to='/placeholder3'
|
||||
onClick={handleClickEvent}
|
||||
>
|
||||
Placeholder 3
|
||||
</Nav.Link>
|
||||
</NavLink>
|
||||
</Nav>
|
||||
</Navbar.Collapse>
|
||||
</Navbar>
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
import React from 'react'
|
||||
import WaitingModal from './waiting-modal'
|
||||
import AppBody from './app-body'
|
||||
|
||||
// This is rendered *before* the BCH wallet is initialized.
|
||||
export function UninitializedView (props = {}) {
|
||||
// console.log('UninitializedView props: ', props)
|
||||
|
||||
+6
-2
@@ -1,7 +1,9 @@
|
||||
import { useState } from 'react'
|
||||
import { useQueryParam, StringParam } from 'use-query-params'
|
||||
|
||||
import { useLocation } from 'react-router-dom'
|
||||
function useAppState () {
|
||||
const location = useLocation()
|
||||
|
||||
// Get the CashStack URL from query parameter or use default
|
||||
let [restURL] = useQueryParam('restURL', StringParam)
|
||||
if (!restURL) restURL = 'https://free-bch.fullstack.cash'
|
||||
@@ -44,7 +46,9 @@ function useAppState () {
|
||||
hideSpinner,
|
||||
setHideSpinner,
|
||||
denyClose,
|
||||
setDenyClose
|
||||
setDenyClose,
|
||||
currentPath: location.pathname
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-1
@@ -8,12 +8,16 @@ import { QueryParamProvider } from 'use-query-params'
|
||||
|
||||
// Importing the Bootstrap CSS
|
||||
import 'bootstrap/dist/css/bootstrap.min.css'
|
||||
import { BrowserRouter } from 'react-router-dom'
|
||||
|
||||
const root = ReactDOM.createRoot(document.getElementById('root'))
|
||||
|
||||
root.render(
|
||||
<QueryParamProvider>
|
||||
<App />
|
||||
{/* <BrowserRouter> should be wrap all the components that use react-router-dom */}
|
||||
<BrowserRouter>
|
||||
<App />
|
||||
</BrowserRouter>
|
||||
</QueryParamProvider>
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user