aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores/RecipePreviewsStore.ts
diff options
context:
space:
mode:
authorLibravatar Ricardo Cino <ricardo@cino.io>2022-06-22 22:10:39 +0200
committerLibravatar Vijay Aravamudhan <vraravam@users.noreply.github.com>2022-06-23 06:55:42 +0530
commit5dcc1aff28290fe3b7e2ed5cbe99d3034c0b6f34 (patch)
tree81f643c38eecdfa49476e0b9dac3aed9107ecf99 /src/stores/RecipePreviewsStore.ts
parentUpgrade 'electron' to '19.0.6' (diff)
downloadferdium-app-5dcc1aff28290fe3b7e2ed5cbe99d3034c0b6f34.tar.gz
ferdium-app-5dcc1aff28290fe3b7e2ed5cbe99d3034c0b6f34.tar.zst
ferdium-app-5dcc1aff28290fe3b7e2ed5cbe99d3034c0b6f34.zip
chore: recipes/request stores js => ts
Diffstat (limited to 'src/stores/RecipePreviewsStore.ts')
-rw-r--r--src/stores/RecipePreviewsStore.ts60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/stores/RecipePreviewsStore.ts b/src/stores/RecipePreviewsStore.ts
new file mode 100644
index 000000000..500f69b40
--- /dev/null
+++ b/src/stores/RecipePreviewsStore.ts
@@ -0,0 +1,60 @@
1import { action, computed, observable } from 'mobx';
2import { Actions } from 'src/actions/lib/actions';
3import { ApiInterface } from 'src/api';
4import Recipe from 'src/models/Recipe';
5import { Stores } from 'src/stores.types';
6
7import CachedRequest from './lib/CachedRequest';
8import Request from './lib/Request';
9import TypedStore from './lib/TypedStore';
10
11export default class RecipePreviewsStore extends TypedStore {
12 @observable allRecipePreviewsRequest = new CachedRequest(
13 this.api.recipePreviews,
14 'all',
15 );
16
17 @observable featuredRecipePreviewsRequest = new CachedRequest(
18 this.api.recipePreviews,
19 'featured',
20 );
21
22 @observable searchRecipePreviewsRequest = new Request(
23 this.api.recipePreviews,
24 'search',
25 );
26
27 constructor(stores: Stores, api: ApiInterface, actions: Actions) {
28 super(stores, api, actions);
29
30 // Register action handlers
31 this.actions.recipePreview.search.listen(this._search.bind(this));
32 }
33
34 async setup(): Promise<void> {
35 // Not implemented
36 }
37
38 @computed get all(): Recipe[] {
39 return this.allRecipePreviewsRequest.execute().result || [];
40 }
41
42 @computed get featured(): Recipe[] {
43 return this.featuredRecipePreviewsRequest.execute().result || [];
44 }
45
46 @computed get searchResults(): Recipe[] {
47 return this.searchRecipePreviewsRequest.result || [];
48 }
49
50 @computed get dev(): Recipe[] {
51 return this.stores.recipes.all.filter(r => r.local);
52 }
53
54 // Actions
55 @action _search({ needle }): void {
56 if (needle !== '') {
57 this.searchRecipePreviewsRequest.execute(needle);
58 }
59 }
60}