mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-03 17:02:40 +00:00
remove prop drilling
This commit is contained in:
@@ -466,7 +466,6 @@ const Editor = createClass({
|
|||||||
rerenderParent={this.rerenderParent} />
|
rerenderParent={this.rerenderParent} />
|
||||||
<MetadataEditor
|
<MetadataEditor
|
||||||
metadata={this.props.brew}
|
metadata={this.props.brew}
|
||||||
isOwner={this.props.isOwner}
|
|
||||||
themeBundle={this.props.themeBundle}
|
themeBundle={this.props.themeBundle}
|
||||||
onChange={this.props.onMetaChange}
|
onChange={this.props.onMetaChange}
|
||||||
reportError={this.props.reportError}
|
reportError={this.props.reportError}
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ const MetadataEditor = createClass({
|
|||||||
|
|
||||||
getInitialState : function(){
|
getInitialState : function(){
|
||||||
return {
|
return {
|
||||||
|
isOwner : global.account?.username && global.account?.username === this.props.metadata?.authors[0],
|
||||||
showThumbnail : true
|
showThumbnail : true
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@@ -212,7 +213,7 @@ const MetadataEditor = createClass({
|
|||||||
if(authors && authors.length){
|
if(authors && authors.length){
|
||||||
text = authors.join(', ');
|
text = authors.join(', ');
|
||||||
}
|
}
|
||||||
if(!this.props.isOwner || authors.length < 2) return (
|
if(!this.state.isOwner || authors.length < 2) return (
|
||||||
<div className='field authors'>
|
<div className='field authors'>
|
||||||
<label>authors</label>
|
<label>authors</label>
|
||||||
<div className='value'>
|
<div className='value'>
|
||||||
|
|||||||
@@ -39,8 +39,7 @@ const Homebrew = (props)=>{
|
|||||||
lang : ''
|
lang : ''
|
||||||
},
|
},
|
||||||
userThemes,
|
userThemes,
|
||||||
brews,
|
brews
|
||||||
isOwner,
|
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
global.account = account;
|
global.account = account;
|
||||||
@@ -53,7 +52,7 @@ const Homebrew = (props)=>{
|
|||||||
<Router location={url}>
|
<Router location={url}>
|
||||||
<div className='homebrew'>
|
<div className='homebrew'>
|
||||||
<Routes>
|
<Routes>
|
||||||
<Route path='/edit/:id' element={<WithRoute el={EditPage} isOwner={isOwner} brew={brew} userThemes={userThemes}/>} />
|
<Route path='/edit/:id' element={<WithRoute el={EditPage} brew={brew} userThemes={userThemes}/>} />
|
||||||
<Route path='/share/:id' element={<WithRoute el={SharePage} brew={brew} />} />
|
<Route path='/share/:id' element={<WithRoute el={SharePage} brew={brew} />} />
|
||||||
<Route path='/new/:id' element={<WithRoute el={NewPage} brew={brew} userThemes={userThemes}/>} />
|
<Route path='/new/:id' element={<WithRoute el={NewPage} brew={brew} userThemes={userThemes}/>} />
|
||||||
<Route path='/new' element={<WithRoute el={NewPage} userThemes={userThemes}/> } />
|
<Route path='/new' element={<WithRoute el={NewPage} userThemes={userThemes}/> } />
|
||||||
|
|||||||
@@ -491,7 +491,6 @@ const EditPage = createClass({
|
|||||||
<Editor
|
<Editor
|
||||||
ref={this.editor}
|
ref={this.editor}
|
||||||
brew={this.state.brew}
|
brew={this.state.brew}
|
||||||
isOwner={this.props.isOwner}
|
|
||||||
onTextChange={this.handleTextChange}
|
onTextChange={this.handleTextChange}
|
||||||
onStyleChange={this.handleStyleChange}
|
onStyleChange={this.handleStyleChange}
|
||||||
onSnipChange={this.handleSnipChange}
|
onSnipChange={this.handleSnipChange}
|
||||||
|
|||||||
@@ -378,7 +378,6 @@ app.get('/edit/:id', asyncHandler(getBrew('edit')), asyncHandler(async(req, res,
|
|||||||
req.brew = req.brew.toObject ? req.brew.toObject() : req.brew;
|
req.brew = req.brew.toObject ? req.brew.toObject() : req.brew;
|
||||||
|
|
||||||
req.userThemes = await(getUsersBrewThemes(req.account?.username));
|
req.userThemes = await(getUsersBrewThemes(req.account?.username));
|
||||||
req.isOwner = req.account && (req.account.username == req.brew.authors[0]);
|
|
||||||
req.ogMeta = { ...defaultMetaTags,
|
req.ogMeta = { ...defaultMetaTags,
|
||||||
title : req.brew.title || 'Untitled Brew',
|
title : req.brew.title || 'Untitled Brew',
|
||||||
description : req.brew.description || 'No description.',
|
description : req.brew.description || 'No description.',
|
||||||
@@ -566,7 +565,6 @@ const renderPage = async (req, res)=>{
|
|||||||
config : configuration,
|
config : configuration,
|
||||||
ogMeta : req.ogMeta,
|
ogMeta : req.ogMeta,
|
||||||
userThemes : req.userThemes,
|
userThemes : req.userThemes,
|
||||||
isOwner : req.isOwner,
|
|
||||||
};
|
};
|
||||||
const title = req.brew ? req.brew.title : '';
|
const title = req.brew ? req.brew.title : '';
|
||||||
const page = await templateFn('homebrew', title, props)
|
const page = await templateFn('homebrew', title, props)
|
||||||
|
|||||||
Reference in New Issue
Block a user