0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-30 02:22:49 +00:00

update based on feedback, remove query-string dependency, add/move favicon url

This commit is contained in:
Charlie Humphreys
2022-06-20 12:53:26 -05:00
parent 60a372de68
commit 755b9dcc89
5 changed files with 14 additions and 86 deletions

View File

@@ -2,8 +2,7 @@ require('./homebrew.less');
const React = require('react');
const createClass = require('create-react-class');
const { StaticRouter:Router } = require('react-router-dom/server');
const { Route, Routes, useParams, useLocation } = require('react-router-dom');
const queryString = require('query-string');
const { Route, Routes, useParams, useSearchParams } = require('react-router-dom');
const HomePage = require('./pages/homePage/homePage.jsx');
const EditPage = require('./pages/editPage/editPage.jsx');
@@ -13,19 +12,17 @@ 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 WithRoute = (props)=>{
const params = useParams();
const location = useLocation();
let additionalProps = {};
if(props.additionalPropsFn) {
additionalProps = props.additionalPropsFn({ props, params, location });
}
const searchParams = useSearchParams();
const Element = props.el;
return <Element {...{
const allProps = {
...props,
el : undefined,
additionalPropsFn : undefined
}} {...params} {...additionalProps}/>;
...params,
...searchParams,
el : undefined
};
return <Element {...allProps} />;
};
const Homebrew = createClass({
@@ -66,9 +63,9 @@ const Homebrew = createClass({
<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='/user/:username' element={<WithRoute el={UserPage} brews={this.props.brews} />} />
<Route path='/print/:id' element={<WithRoute el={PrintPage} brew={this.props.brew} />} />
<Route path='/print' element={<WithRoute el={PrintPage} />} />
<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} />} />

View File

@@ -8,7 +8,7 @@ module.exports = async(name, title = '', props = {})=>{
<link href="//use.fontawesome.com/releases/v5.15.1/css/all.css" rel="stylesheet" />
<link href="//fonts.googleapis.com/css?family=Open+Sans:400,300,600,700" rel="stylesheet" type="text/css" />
<link href=${`/${name}/bundle.css`} rel='stylesheet' />
<link rel="icon" href="/assets/homebrew/favicon.ico" type="image/x-icon" />
<link rel="icon" href="/assets/favicon.ico" type="image/x-icon" />
<meta property="og:title" content="${props.brew?.title || 'Homebrewery - Untitled Brew'}">
<meta property="og:url" content="${HOMEBREWERY_PUBLIC_URL}/${props.brew?.shareId ? `share/${props.brew.shareId}` : ''}">
<meta property="og:image" content="${props.brew?.thumbnail || `${HOMEBREWERY_PUBLIC_URL}/thumbnail.png`}">