public.ts 1.54 KB
Newer Older
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
1
// constants
2
import { LOADING_SLUG, RECEIVE_ARTICLE, RECEIVE_DOCUMENTATION, RECEIVE_MENU } from 'cms/constants';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
3
4
5
// model
import Article from 'model/cms/Article';
import Menu from 'model/cms/Menu';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
6
import ADoc from 'model/cms/ADoc';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
7
8
// service
import CmsService from 'service/genesys/CmsService';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
9
import AsciiDocService from 'service/genesys/AsciiDocService';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
10

11
12
13
14
15
const loadingSlug = (slug: string) => ({
  type: LOADING_SLUG,
  payload: {slug},
});

Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
16
17
18
19
20
21
const receiveArticle = (slug: string, article: Article) => ({
  type: RECEIVE_ARTICLE,
  payload: {slug, article},
});

export const loadArticle = (locale: string, slug: string) => (dispatch) => {
22
23
  dispatch(loadingSlug(slug));
  return CmsService.getArticleBySlugAndLang(locale, slug)
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
24
25
26
    .then((article) => dispatch(receiveArticle(slug, article)));
};

27
28
29
30
export const loadArticlePromise = (locale: string, slug: string) => (dispatch) => {
  return CmsService.getGlobalArticle(locale, slug);
};

Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
31
32
33
34
35
36
const receiveDocumentation = (slug: string, documentation: ADoc) => ({
  type: RECEIVE_DOCUMENTATION,
  payload: {slug, documentation},
});

export const loadDocumentation = (slug: string) => (dispatch) => {
37
38
  dispatch(loadingSlug(slug));
  return AsciiDocService.viewDoc(slug)
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
39
40
41
    .then((article) => dispatch(receiveDocumentation(slug, article)));
};

Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
42
43
44
45
46
47
48
49
50
const receiveMenu = (menuKey: string, menuItem: Menu) => ({
  type: RECEIVE_MENU,
  payload: {menuKey, menuItem},
});

export const loadMenu = (menuKey: string) => (dispatch) => {
  CmsService.getMenu(menuKey)
    .then((menuItem) => dispatch(receiveMenu(menuKey, menuItem)));
};