aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/communityRecipes/store.ts
blob: afd7d0f0158eaad6da2b4413f85e389b7c250986 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { computed } from 'mobx';
import { FeatureStore } from '../utils/FeatureStore';

// TODO: Go back to 'debug' from 'console.log' when https://github.com/electron/electron/issues/31689 is fixed
// const debug = require('debug')('Ferdium:feature:communityRecipes:store');

export class CommunityRecipesStore extends FeatureStore {
  stores: any;

  actions: any;

  start(stores: any, actions: any) {
    console.log('start');
    this.stores = stores;
    this.actions = actions;
  }

  stop() {
    console.log('stop');
    super.stop();
  }

  @computed get communityRecipes() {
    if (!this.stores) return [];

    return this.stores.recipePreviews.dev.map(
      (recipePreview: { isDevRecipe: boolean; author: any[] }) => {
        // TODO: Need to figure out if this is even necessary/used
        recipePreview.isDevRecipe = !!recipePreview.author.some(
          (author: { email: string }) =>
            author.email === this.stores.user.data.email,
        );

        return recipePreview;
      },
    );
  }
}

export default CommunityRecipesStore;