-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathAboutPage.store.ts
36 lines (29 loc) · 1.16 KB
/
AboutPage.store.ts
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
import { observable } from 'mobx';
import { getErrorRequest } from '../../../domains/shows/shows.services';
import { initialResponseStatus } from '../../../utils/mobx.utils';
import { ApiResponse } from '../../../utils/http/http.types';
import { getGlobalStore } from '../../shared/global-store-provider/GlobalStoreProvider';
export const AboutPageStore = () =>
observable({
globalStore: getGlobalStore(),
errorExampleResults: initialResponseStatus<null>(null),
/**
* Store initializer. Should only be called once.
*/
*init() {
yield Promise.all([this.loadSomething()]);
},
*loadSomething() {
const response: ApiResponse<null> = yield getErrorRequest();
this.errorExampleResults = {
data: this.errorExampleResults.data,
isRequesting: false,
...response, // Overwrites the default data prop or adds an error. Also adds the statusCode.
};
if (response.error) {
const message = `${response.statusCode}: ${response.error.message}`;
this.globalStore.toastStore.enqueueToast(message, 'error');
}
},
});
export type AboutPageStore = ReturnType<typeof AboutPageStore>;