PluginProbe ʕ •ᴥ•ʔ
Starter Sites & Templates by Neve / 1.4.1
Starter Sites & Templates by Neve v1.4.1
1.4.1 1.4.0 1.3.0 1.2.29 1.2.28 1.2.6 1.2.7 1.2.8 1.2.9 trunk 1.0.10 1.0.11 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 1.1.20 1.1.21 1.1.22 1.1.23 1.1.24 1.1.25 1.1.26 1.1.27 1.1.28 1.1.29 1.1.3 1.1.30 1.1.31 1.1.32 1.1.33 1.1.34 1.1.35 1.1.36 1.1.37 1.1.38 1.1.39 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.3 1.2.4 1.2.5
templates-patterns-collection / beaver / src / data / store / index.js
templates-patterns-collection / beaver / src / data / store Last commit date
index.js 1 year ago
index.js
149 lines
1 import { registerStore } from '@wordpress/data';
2
3 const DEFAULT_STATE = {
4 isFetching: true,
5 isPreview: false,
6 tab: 'library',
7 templates: {
8 items: [],
9 currentPage: 0,
10 totalPages: 0,
11 },
12 library: {
13 items: [],
14 currentPage: 0,
15 totalPages: 0,
16 },
17 preview: {},
18 };
19
20 registerStore( 'tpc/beaver', {
21 reducer( state = DEFAULT_STATE, action ) {
22 if ( 'SET_FETCHING' === action.type ) {
23 return {
24 ...state,
25 isFetching: action.isFetching,
26 };
27 }
28
29 if ( 'TOGGLE_PREVIEW' === action.type ) {
30 return {
31 ...state,
32 isPreview: ! state.isPreview,
33 };
34 }
35
36 if ( 'UPDATE_CURRENT_TAB' === action.type ) {
37 return {
38 ...state,
39 tab: action.tab,
40 };
41 }
42
43 if ( 'UPDATE_TEMPLATES' === action.type ) {
44 return {
45 ...state,
46 templates: {
47 items: action.items,
48 currentPage: Number( action.currentPage ),
49 totalPages: Number( action.totalPages ),
50 },
51 };
52 }
53
54 if ( 'UPDATE_LIBRARY' === action.type ) {
55 return {
56 ...state,
57 library: {
58 items: action.items,
59 currentPage: Number( action.currentPage ),
60 totalPages: Number( action.totalPages ),
61 },
62 };
63 }
64
65 if ( 'SET_PREVIEW_DATA' === action.type ) {
66 return {
67 ...state,
68 preview: action.preview,
69 };
70 }
71
72 return state;
73 },
74
75 selectors: {
76 isFetching( state ) {
77 return state.isFetching;
78 },
79
80 isPreview( state ) {
81 return state.isPreview;
82 },
83
84 getCurrentTab( state ) {
85 return state.tab;
86 },
87
88 getTemplates( state ) {
89 return state.templates;
90 },
91
92 getLibrary( state ) {
93 return state.library;
94 },
95
96 getPreview( state ) {
97 return state.preview;
98 },
99 },
100
101 actions: {
102 setFetching( isFetching ) {
103 return {
104 type: 'SET_FETCHING',
105 isFetching,
106 };
107 },
108
109 togglePreview( isPreview ) {
110 return {
111 type: 'TOGGLE_PREVIEW',
112 isPreview,
113 };
114 },
115
116 updateCurrentTab( tab ) {
117 return {
118 type: 'UPDATE_CURRENT_TAB',
119 tab,
120 };
121 },
122
123 updateTemplates( items, currentPage, totalPages ) {
124 return {
125 type: 'UPDATE_TEMPLATES',
126 items,
127 currentPage,
128 totalPages,
129 };
130 },
131
132 updateLibrary( items, currentPage, totalPages ) {
133 return {
134 type: 'UPDATE_LIBRARY',
135 items,
136 currentPage,
137 totalPages,
138 };
139 },
140
141 setPreviewData( preview ) {
142 return {
143 type: 'SET_PREVIEW_DATA',
144 preview,
145 };
146 },
147 },
148 } );
149