0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-13 23:52:42 +00:00

update react-router-dom to 6.3.0, add WithRoute function component wrapper

This commit is contained in:
Charlie Humphreys
2022-06-18 16:20:51 -05:00
parent 8ea58d22ba
commit 60a372de68
3 changed files with 22356 additions and 22485 deletions

View File

@@ -1,7 +1,8 @@
require('./homebrew.less'); require('./homebrew.less');
const React = require('react'); const React = require('react');
const createClass = require('create-react-class'); const createClass = require('create-react-class');
const { StaticRouter:Router, Switch, Route } = require('react-router-dom'); const { StaticRouter:Router } = require('react-router-dom/server');
const { Route, Routes, useParams, useLocation } = require('react-router-dom');
const queryString = require('query-string'); const queryString = require('query-string');
const HomePage = require('./pages/homePage/homePage.jsx'); const HomePage = require('./pages/homePage/homePage.jsx');
@@ -12,6 +13,21 @@ const NewPage = require('./pages/newPage/newPage.jsx');
//const ErrorPage = require('./pages/errorPage/errorPage.jsx'); //const ErrorPage = require('./pages/errorPage/errorPage.jsx');
const PrintPage = require('./pages/printPage/printPage.jsx'); const PrintPage = require('./pages/printPage/printPage.jsx');
const WithRoute = (props)=>{ //(Element, additionalPropsFn)=>{
const params = useParams();
const location = useLocation();
let additionalProps = {};
if(props.additionalPropsFn) {
additionalProps = props.additionalPropsFn({ props, params, location });
}
const Element = props.el;
return <Element {...{
...props,
el : undefined,
additionalPropsFn : undefined
}} {...params} {...additionalProps}/>;
};
const Homebrew = createClass({ const Homebrew = createClass({
displayName : 'Homebrewery', displayName : 'Homebrewery',
getDefaultProps : function() { getDefaultProps : function() {
@@ -43,25 +59,23 @@ const Homebrew = createClass({
}, },
render : function (){ render : function (){
return ( return <Router location={this.props.url}>
<Router location={this.props.url}> <div className='homebrew'>
<div className='homebrew'> <Routes>
<Switch> <Route path='/edit/:id' element={<WithRoute el={EditPage} brew={this.props.brew} />} />
<Route path='/edit/:id' component={(routeProps)=><EditPage id={routeProps.match.params.id} brew={this.props.brew} />}/> <Route path='/share/:id' element={<WithRoute el={SharePage} brew={this.props.brew} />} />
<Route path='/share/:id' component={(routeProps)=><SharePage id={routeProps.match.params.id} brew={this.props.brew} />}/> <Route path='/new/:id' element={<WithRoute el={NewPage} brew={this.props.brew} />} />
<Route path='/new/:id' component={(routeProps)=><NewPage id={routeProps.match.params.id} brew={this.props.brew} />}/> <Route path='/new' element={<WithRoute el={NewPage}/>} />
<Route path='/new' exact component={(routeProps)=><NewPage />}/> <Route path='/user/:username' element={<WithRoute el={UserPage} brews={this.props.brews} additionalPropsFn={({ location })=>({ query: queryString.parse(location.search) })} />} />
<Route path='/user/:username' component={(routeProps)=><UserPage username={routeProps.match.params.username} brews={this.props.brews} query={queryString.parse(routeProps.location.search)}/>}/> <Route path='/print/:id' element={<WithRoute el={PrintPage} brew={this.props.brew} additionalPropsFn={({ location })=>({ query: queryString.parse(location.search) })} />} />
<Route path='/print/:id' component={(routeProps)=><PrintPage brew={this.props.brew} query={queryString.parse(routeProps.location.search)} />}/> <Route path='/print' element={<WithRoute el={PrintPage} additionalPropsFn={({ location })=>({ query: queryString.parse(location.search) })} />} />
<Route path='/print' exact component={(routeProps)=><PrintPage query={queryString.parse(routeProps.location.search)} />}/> <Route path='/changelog' element={<WithRoute el={SharePage} brew={this.props.brew} />} />
<Route path='/changelog' exact component={()=><SharePage brew={this.props.brew} />}/> <Route path='/faq' element={<WithRoute el={SharePage} brew={this.props.brew} />} />
<Route path='/faq' exact component={()=><SharePage brew={this.props.brew} />}/> <Route path='/v3_preview' element={<WithRoute el={HomePage} brew={this.props.brew} />} />
<Route path='/v3_preview' exact component={()=><HomePage brew={this.props.brew} />}/> <Route path='/' element={<WithRoute el={HomePage} brew={this.props.brew} />} />
<Route path='/' component={()=><HomePage brew={this.props.brew} />}/> </Routes>
</Switch> </div>
</div> </Router>;
</Router>
);
} }
}); });

44785
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -81,7 +81,7 @@
"react": "^16.14.0", "react": "^16.14.0",
"react-dom": "^16.14.0", "react-dom": "^16.14.0",
"react-frame-component": "4.1.3", "react-frame-component": "4.1.3",
"react-router-dom": "5.3.0", "react-router-dom": "6.3.0",
"sanitize-filename": "1.6.3", "sanitize-filename": "1.6.3",
"superagent": "^6.1.0", "superagent": "^6.1.0",
"vitreum": "git+https://git@github.com/calculuschild/vitreum.git" "vitreum": "git+https://git@github.com/calculuschild/vitreum.git"