{"size": 1113, "ext": "js", "max_stars_repo_path": "src/store/ui/uiActions.js", "max_stars_repo_name": "MaxUser99/AnnaSugar_frontend", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/store/ui/uiActions.js", "max_issues_repo_name": "MaxUser99/AnnaSugar_frontend", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/store/ui/uiActions.js", "max_forks_repo_name": "MaxUser99/AnnaSugar_frontend", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 31.8, "max_line_length": 106, "alphanum_fraction": 0.5884995508}
import { staticTextUrl, getLangHeader } from '../api';

export const OPEN_MODAL = 'OPEN_MODAL';
export const CHANGE_LANGUAGE = 'CHANGE_LANGUAGE';
export const SET_TEXT = 'SET_TEXT';

export const openModal = (modalName, state = null) => ({type: OPEN_MODAL, payload: { modalName, state }});
export const changeLanguage = (lang) => ({ type: CHANGE_LANGUAGE, payload: lang });
export const setText = (texts) => ({ type: SET_TEXT, payload: texts });

export const loadStatic = () => {
  return async (dispatch, getState, api) => {
    const { ui: { language } } = getState();
    const url = staticTextUrl();
    const headers = getLangHeader(language);
    const payload = await api.get(url, { headers })
      .then(({ data: { data: { home: { intro_pt1, intro_pt2 } } } }) => {
        console.log({ intro_pt1, intro_pt2 });
        return {
          text1: intro_pt1 || null,
          text2: intro_pt2 || null,
        };
      })
      .catch(() => {
        console.error('fetch error');
        return {
          text1: null,
          text2: null
        };
      });

    dispatch(setText(payload));
  }
}
