forked from mozilla/pontoon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactions.ts
More file actions
42 lines (37 loc) · 1.12 KB
/
Copy pathactions.ts
File metadata and controls
42 lines (37 loc) · 1.12 KB
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
41
42
import { LocaleOption } from '~/api/other-locales';
import { fetchProject, Tag } from '~/api/project';
import type { AppDispatch } from '~/store';
export const RECEIVE = 'project/RECEIVE';
export const REQUEST = 'project/REQUEST';
export type Action = ReceiveAction | RequestAction;
/** Notify that project data is being fetched. */
type RequestAction = {
readonly type: typeof REQUEST;
};
/** Receive project data. */
type ReceiveAction = {
readonly type: typeof RECEIVE;
readonly slug: string;
readonly name: string;
readonly info: string;
readonly tags: Tag[];
readonly locales: LocaleOption[];
};
/**
* Get data about the current project.
*/
export const getProject = (slug: string) => async (dispatch: AppDispatch) => {
// When 'all-projects' are selected, we do not fetch data.
if (slug !== 'all-projects') {
dispatch({ type: REQUEST });
const { info, name, slug: slug_, tags, locales } = await fetchProject(slug);
dispatch({
type: RECEIVE,
slug: slug_,
name: name,
info: info,
tags: tags.sort((a, b) => b.priority - a.priority),
locales: locales,
});
}
};