0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-29 13:22:40 +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');
const React = require('react');
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 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 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({
displayName : 'Homebrewery',
getDefaultProps : function() {
@@ -43,25 +59,23 @@ const Homebrew = createClass({
},
render : function (){
return (
<Router location={this.props.url}>
<div className='homebrew'>
<Switch>
<Route path='/edit/:id' component={(routeProps)=><EditPage id={routeProps.match.params.id} brew={this.props.brew} />}/>
<Route path='/share/:id' component={(routeProps)=><SharePage id={routeProps.match.params.id} brew={this.props.brew} />}/>
<Route path='/new/:id' component={(routeProps)=><NewPage id={routeProps.match.params.id} brew={this.props.brew} />}/>
<Route path='/new' exact component={(routeProps)=><NewPage />}/>
<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' component={(routeProps)=><PrintPage brew={this.props.brew} query={queryString.parse(routeProps.location.search)} />}/>
<Route path='/print' exact component={(routeProps)=><PrintPage query={queryString.parse(routeProps.location.search)} />}/>
<Route path='/changelog' exact component={()=><SharePage brew={this.props.brew} />}/>
<Route path='/faq' exact component={()=><SharePage brew={this.props.brew} />}/>
<Route path='/v3_preview' exact component={()=><HomePage brew={this.props.brew} />}/>
<Route path='/' component={()=><HomePage brew={this.props.brew} />}/>
</Switch>
</div>
</Router>
);
return <Router location={this.props.url}>
<div className='homebrew'>
<Routes>
<Route path='/edit/:id' element={<WithRoute el={EditPage} brew={this.props.brew} />} />
<Route path='/share/:id' element={<WithRoute el={SharePage} brew={this.props.brew} />} />
<Route path='/new/:id' element={<WithRoute el={NewPage} brew={this.props.brew} />} />
<Route path='/new' element={<WithRoute el={NewPage}/>} />
<Route path='/user/:username' element={<WithRoute el={UserPage} brews={this.props.brews} additionalPropsFn={({ location })=>({ query: queryString.parse(location.search) })} />} />
<Route path='/print/:id' element={<WithRoute el={PrintPage} brew={this.props.brew} additionalPropsFn={({ location })=>({ query: queryString.parse(location.search) })} />} />
<Route path='/print' element={<WithRoute el={PrintPage} additionalPropsFn={({ location })=>({ query: queryString.parse(location.search) })} />} />
<Route path='/changelog' element={<WithRoute el={SharePage} brew={this.props.brew} />} />
<Route path='/faq' element={<WithRoute el={SharePage} brew={this.props.brew} />} />
<Route path='/v3_preview' element={<WithRoute el={HomePage} brew={this.props.brew} />} />
<Route path='/' element={<WithRoute el={HomePage} brew={this.props.brew} />} />
</Routes>
</div>
</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-dom": "^16.14.0",
"react-frame-component": "4.1.3",
"react-router-dom": "5.3.0",
"react-router-dom": "6.3.0",
"sanitize-filename": "1.6.3",
"superagent": "^6.1.0",
"vitreum": "git+https://git@github.com/calculuschild/vitreum.git"