Skip to content

Commit 03a0cd9

Browse files
committed
fix: Fix ingredients state on print view when sorting by tag or category
1 parent f27e7bb commit 03a0cd9

File tree

3 files changed

+223
-209
lines changed

3 files changed

+223
-209
lines changed

src/components/recipe-generator-modal/index.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,22 @@ class RecipeGeneratorModalNotExtended extends React.Component {
1717
mdParser = new MarkdownIt();
1818

1919
state = {
20-
formValues: {},
2120
initialCount: +this.props.item.servings,
2221
count: +this.props.item.servings,
23-
ingredients: this.props.item.ingredients,
24-
formElements: []
22+
ingredients: this.props.item.ingredients
2523
};
2624

25+
componentDidUpdate(prevProps, prevState) {
26+
const {show} = this.props;
27+
if ( show && prevProps.show !== show ) {
28+
this.setState( {
29+
initialCount: +this.props.item.servings,
30+
count: +this.props.item.servings,
31+
ingredients: this.props.item.ingredients
32+
} );
33+
}
34+
}
35+
2736
nToBr = ( data ) => {
2837
if ( undefined === data || '' === data ) {
2938
return ' ';
@@ -61,7 +70,6 @@ class RecipeGeneratorModalNotExtended extends React.Component {
6170

6271
onClose = () => {
6372
const { onClose } = this.props;
64-
this.setState( { formValues: {} } );
6573
onClose && onClose();
6674

6775
// BUG: Lag

src/core/api.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ class Api {
4141

4242
getAllTags = () => db.get( 'recipes' ).filter( { isTrash: false } ).map( 'tags' ).value();
4343

44-
getRecipesContainsTag = tag => db.get( 'recipes' ).filter( ( t => t.tags.indexOf( tag ) > -1 && false === t.isTrash ) ).value();
44+
getRecipesContainsTag = tag => db.get( 'recipes' ).filter( ( t => t.tags.indexOf( tag ) > -1 && false === t.isTrash ) ).sortBy( 'title' ).value();
4545

4646
getAllCategories = () => db.get( 'recipes' ).filter( { isTrash: false } ).map( 'categories' ).value();
4747

48-
getRecipesContainsCategory = category => db.get( 'recipes' ).filter( ( t => t.categories.indexOf( category ) > -1 && false === t.isTrash ) ).value();
48+
getRecipesContainsCategory = category => db.get( 'recipes' ).filter( ( t => t.categories.indexOf( category ) > -1 && false === t.isTrash ) ).sortBy( 'title' ).value();
4949

5050
queryRecipe = query => db.get( 'recipes' ).filter( ( t => ( t.title.toLowerCase().indexOf( query ) > -1 ) && false === t.isTrash ) ).value();
5151
}

0 commit comments

Comments
 (0)