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
43
44
45
46
47
48
49
50
51
52
53
54
55
|
import { FETCH_TRENDING_FAILED, FETCH_TRENDING_SUCCESS, PROCESS_FETCH_TRENDING, UPDATE_FILTERS } from './types';
import { UPDATE_DATE_TYPE, UPDATE_LANGUAGE } from '../preference/types';
export const initialState = {
processing: false,
// Array of objects with the below format
// [
// { start: '', end: '', data: [] },
// { start: '', end: '', data: [] }
// ]
repositories: [],
filters: {},
error: null,
};
export default function reducer(state = initialState, action) {
switch (action.type) {
case PROCESS_FETCH_TRENDING:
return {
...state,
processing: true,
error: null
};
case UPDATE_DATE_TYPE:
case UPDATE_LANGUAGE:
return {
...state,
...initialState
};
case FETCH_TRENDING_SUCCESS:
return {
...state,
// Append the fetched repositories to existing list
repositories: [
...state.repositories,
action.payload
],
processing: false,
error: null
};
case FETCH_TRENDING_FAILED:
return {
...state,
processing: false,
error: action.payload
};
case UPDATE_FILTERS:
return {
...state,
filters: action.payload
};
default:
return state;
}
}
|