PluginProbe ʕ •ᴥ•ʔ
Starter Sites & Templates by Neve / trunk
Starter Sites & Templates by Neve vtrunk
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 / editor / src / data / block-editor / index.js
templates-patterns-collection / editor / src / data / block-editor Last commit date
index.js 1 year ago
index.js
168 lines
1 import { registerStore } from '@wordpress/data';
2
3 const DEFAULT_STATE = {
4 isFetching: true,
5 isPreview: false,
6 tab: 'library',
7 templates: [],
8 patterns: [],
9 library: {
10 items: [],
11 currentPage: 0,
12 totalPages: 0,
13 },
14 preview: {
15 type: 'templates',
16 item: {},
17 },
18 };
19
20 registerStore( 'tpc/block-editor', {
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 isPreview: false,
41 };
42 }
43
44 if ( 'UPDATE_TEMPLATES' === action.type ) {
45 return {
46 ...state,
47 templates: {
48 items: action.items,
49 currentPage: Number( action.currentPage ),
50 totalPages: Number( action.totalPages ),
51 },
52 };
53 }
54
55 if ( 'UPDATE_PATTERNS' === action.type ) {
56 return {
57 ...state,
58 patterns: action.items,
59 };
60 }
61
62 if ( 'UPDATE_LIBRARY' === action.type ) {
63 return {
64 ...state,
65 library: {
66 items: action.items,
67 currentPage: Number( action.currentPage ),
68 totalPages: Number( action.totalPages ),
69 },
70 };
71 }
72
73 if ( 'SET_PREVIEW_DATA' === action.type ) {
74 return {
75 ...state,
76 preview: action.preview,
77 };
78 }
79
80 return state;
81 },
82
83 selectors: {
84 isFetching( state ) {
85 return state.isFetching;
86 },
87
88 isPreview( state ) {
89 return state.isPreview;
90 },
91
92 getCurrentTab( state ) {
93 return state.tab;
94 },
95
96 getTemplates( state ) {
97 return state.templates;
98 },
99
100 getPatterns( state ) {
101 return state.patterns;
102 },
103
104 getLibrary( state ) {
105 return state.library;
106 },
107
108 getPreview( state ) {
109 return state.preview;
110 },
111 },
112
113 actions: {
114 setFetching( isFetching ) {
115 return {
116 type: 'SET_FETCHING',
117 isFetching,
118 };
119 },
120
121 togglePreview( isPreview ) {
122 return {
123 type: 'TOGGLE_PREVIEW',
124 isPreview,
125 };
126 },
127
128 updateCurrentTab( tab ) {
129 return {
130 type: 'UPDATE_CURRENT_TAB',
131 tab,
132 };
133 },
134
135 updateTemplates( items, currentPage, totalPages ) {
136 return {
137 type: 'UPDATE_TEMPLATES',
138 items,
139 currentPage,
140 totalPages,
141 };
142 },
143
144 updatePatterns( items ) {
145 return {
146 type: 'UPDATE_PATTERNS',
147 items,
148 };
149 },
150
151 updateLibrary( items, currentPage, totalPages ) {
152 return {
153 type: 'UPDATE_LIBRARY',
154 items,
155 currentPage,
156 totalPages,
157 };
158 },
159
160 setPreviewData( preview ) {
161 return {
162 type: 'SET_PREVIEW_DATA',
163 preview,
164 };
165 },
166 },
167 } );
168