diff --git a/fm-google-site-search.php b/fm-google-site-search.php index 88b04d7..0a046d1 100755 --- a/fm-google-site-search.php +++ b/fm-google-site-search.php @@ -16,7 +16,7 @@ * Plugin Name: Easy Google Custom Search * Plugin URI: https://github.com/freddiemixell/wordpress-google-search * Description: This is a short description of what the plugin does. It's displayed in the WordPress admin area. - * Version: 1.1.1 + * Version: 1.2.1 * Author: Freddie Mixell * Author URI: https://github.com/freddiemixell * License: GPL-2.0+ @@ -35,7 +35,7 @@ * Start at version 1.0.0 and use SemVer - https://semver.org * Rename this for your plugin and update it as you release new versions. */ -define( 'FM_GOOGLE_SITE_SEARCH_VERSION', '1.1.1' ); +define( 'FM_GOOGLE_SITE_SEARCH_VERSION', '1.2.1' ); define( 'FM_GOOGLE_SITE_SEARCH_PATH', __DIR__ ); diff --git a/package.json b/package.json index 90a8d63..a181e35 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fm-google-site-search", - "version": "1.1.1", + "version": "1.2.1", "description": "WordPress Google Search", "main": "index.js", "license": "MIT", diff --git a/public/class-fm-google-site-search-public.php b/public/class-fm-google-site-search-public.php index ec6bb8a..9235c5f 100755 --- a/public/class-fm-google-site-search-public.php +++ b/public/class-fm-google-site-search-public.php @@ -117,6 +117,7 @@ public function register_search() { public function search_site(WP_REST_Request $request) { $query = $request['query']; + $start = isset( $request['start'] ) ? $request['start'] : null; $base_url = 'https://www.googleapis.com/customsearch/v1'; $fields = 'items(title,link,snippet),queries,searchInformation(formattedSearchTime,formattedTotalResults)'; global $wp_version; @@ -134,6 +135,10 @@ public function search_site(WP_REST_Request $request) { '&q=' . $query . '&fields=' . $fields; + if ($start !== null) { + $request = $request . '&start=' . $start; + } + $response = wp_remote_get( esc_url_raw( $request ), $args); return json_decode( wp_remote_retrieve_body( $response ), true ); diff --git a/public/dist/bundle.js b/public/dist/bundle.js index 23957cc..67b8cd8 100644 --- a/public/dist/bundle.js +++ b/public/dist/bundle.js @@ -1,4 +1,4 @@ -!function(e){var t={};function r(n){if(t[n])return t[n].exports;var a=t[n]={i:n,l:!1,exports:{}};return e[n].call(a.exports,a,a.exports,r),a.l=!0,a.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)r.d(n,a,function(t){return e[t]}.bind(null,a));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=15)}([function(e,t){e.exports=React},function(e,t){e.exports=function(e){return e&&e.__esModule?e:{default:e}}},function(e,t,r){"use strict";t.a={animationIterationCount:1,borderImageOutset:1,borderImageSlice:1,borderImageWidth:1,boxFlex:1,boxFlexGroup:1,boxOrdinalGroup:1,columnCount:1,columns:1,flex:1,flexGrow:1,flexPositive:1,flexShrink:1,flexNegative:1,flexOrder:1,gridRow:1,gridRowEnd:1,gridRowSpan:1,gridRowStart:1,gridColumn:1,gridColumnEnd:1,gridColumnSpan:1,gridColumnStart:1,msGridRow:1,msGridRowSpan:1,msGridColumn:1,msGridColumnSpan:1,fontWeight:1,lineHeight:1,opacity:1,order:1,orphans:1,tabSize:1,widows:1,zIndex:1,zoom:1,WebkitLineClamp:1,fillOpacity:1,floodOpacity:1,stopOpacity:1,strokeDasharray:1,strokeDashoffset:1,strokeMiterlimit:1,strokeOpacity:1,strokeWidth:1}},function(e,t,r){"use strict";t.a=function(e){var t={};return function(r){return void 0===t[r]&&(t[r]=e(r)),t[r]}}},function(e,t){e.exports=function(e,t){e.prototype=Object.create(t.prototype),(e.prototype.constructor=e).__proto__=t}},function(e,t,r){e.exports=function e(t){"use strict";var r=/^\0+/g,n=/[\0\r\f]/g,a=/: */g,o=/zoo|gra/,i=/([,: ])(transform)/g,s=/,+\s*(?![^(]*[)])/g,c=/ +\s*(?![^(]*[)])/g,u=/ *[\0] */g,l=/,\r+?/g,f=/([\t\r\n ])*\f?&/g,d=/:global\(((?:[^\(\)\[\]]*|\[.*\]|\([^\(\)]*\))*)\)/g,h=/\W+/g,p=/@(k\w+)\s*(\S*)\s*/,m=/::(place)/g,y=/:(read-only)/g,g=/\s+(?=[{\];=:>])/g,v=/([[}=:>])\s+/g,b=/(\{[^{]+?);(?=\})/g,w=/\s{2,}/g,k=/([^\(])(:+) */g,C=/[svh]\w+-[tblr]{2}/,S=/\(\s*(.*)\s*\)/g,A=/([\s\S]*?);/g,x=/-self|flex-/g,O=/[^]*?(:[rp][el]a[\w-]+)[^]*/,j=/stretch|:\s*\w+\-(?:conte|avail)/,_=/([^-])(image-set\()/,E="-webkit-",R="-moz-",T="-ms-",P=59,I=125,M=123,N=40,$=41,z=91,D=93,L=10,F=13,W=9,H=64,U=32,q=38,B=45,G=95,Y=42,K=44,V=58,X=39,Z=34,J=47,Q=62,ee=43,te=126,re=0,ne=12,ae=11,oe=107,ie=109,se=115,ce=112,ue=111,le=105,fe=99,de=100,he=112,pe=1,me=1,ye=0,ge=1,ve=1,be=1,we=0,ke=0,Ce=0,Se=[],Ae=[],xe=0,Oe=null,je=-2,_e=-1,Ee=0,Re=1,Te=2,Pe=3,Ie=0,Me=1,Ne="",$e="",ze="";function De(e,t,r){var n=t.trim().split(l),a=n,o=n.length,i=e.length;switch(i){case 0:case 1:for(var s=0,c=0===i?"":e[0]+" ";s"+e()+""}}function oe(e,t){return function(){var r,n=((r={})[E]=Q(t),r[R]="4.3.2",r),a=V();return a&&(n.nonce=a),c.a.createElement("style",v({},n,{dangerouslySetInnerHTML:{__html:e()}}))}}function ie(e){return function(){return Object.keys(e)}}function se(e){return document.createTextNode(re(e))}function ce(e,t,r,n,a){if(!T||r)return function e(t,r){function n(e){var t=i[e];return void 0!==t?t:i[e]=[""]}function a(){var e="";for(var t in i){var r=i[t][0];r&&(e+=re(t)+r)}return e}var o=void 0===t?Object.create(null):t,i=void 0===r?Object.create(null):r;return{clone:function(){var t=function(e){var t=Object.create(null);for(var r in e)t[r]=v({},e[r]);return t}(o),r=Object.create(null);for(var n in i)r[n]=[i[n][0]];return e(t,r)},css:a,getIds:ie(i),hasNameForId:J(o),insertMarker:n,insertRules:function(e,t,r){n(e)[0]+=t.join(" "),X(o,e,r)},removeRules:function(e){var t=i[e];void 0!==t&&(t[0]="",Z(o,e))},sealed:!1,styleTag:null,toElement:oe(a,o),toHTML:ae(a,o)}}();var o=function(e,t,r){var n=document.createElement("style");n.setAttribute(E,""),n.setAttribute(R,"4.3.2");var a=V();if(a&&n.setAttribute("nonce",a),n.appendChild(document.createTextNode("")),e&&!t)e.appendChild(n);else{if(!t||!e||!t.parentNode)throw new M(6);t.parentNode.insertBefore(n,r?t:t.nextSibling)}return n}(e,t,n);return P?function(e,t){function r(t){var r=o[t];return void 0!==r?r:(o[t]=se(t),e.appendChild(o[t]),a[t]=Object.create(null),o[t])}function n(){var e="";for(var t in o)e+=o[t].data;return e}var a=Object.create(null),o=Object.create(null),i=void 0!==t,s=!1;return{clone:function(){throw new M(5)},css:n,getIds:ie(o),hasNameForId:J(a),insertMarker:r,insertRules:function(e,n,o){for(var c=r(e),u=[],l=n.length,f=0;f>>16)&65535)<<16),n=1540483477*(65535&n)+((1540483477*(n>>>16)&65535)<<16)^(t=1540483477*(65535&(t^=t>>>24))+((1540483477*(t>>>16)&65535)<<16)),r-=4,++a;switch(r){case 3:n^=(255&e.charCodeAt(a+2))<<16;case 2:n^=(255&e.charCodeAt(a+1))<<8;case 1:n=1540483477*(65535&(n^=255&e.charCodeAt(a)))+((1540483477*(n>>>16)&65535)<<16)}return((n=1540483477*(65535&(n^=n>>>13))+((1540483477*(n>>>16)&65535)<<16))^n>>>15)>>>0}var xe=52,Oe=function(e){return String.fromCharCode(e+(25<+~=|^:(),"'`-]+/g,Ne=/(^-|-$)/g;function $e(e){return e.replace(Me,"-").replace(Ne,"")}function ze(e){return"string"==typeof e&&!0}var De={childContextTypes:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDerivedStateFromProps:!0,propTypes:!0,type:!0},Le={name:!0,length:!0,prototype:!0,caller:!0,callee:!0,arguments:!0,arity:!0},Fe=((Pe={})[l.ForwardRef]={$$typeof:!0,render:!0},Pe),We=Object.defineProperty,He=Object.getOwnPropertyNames,Ue=Object.getOwnPropertySymbols,qe=void 0===Ue?function(){return[]}:Ue,Be=Object.getOwnPropertyDescriptor,Ge=Object.getPrototypeOf,Ye=Object.prototype,Ke=Array.prototype;function Ve(e,t,r){if("string"==typeof t)return e;var n=Ge(t);n&&n!==Ye&&Ve(e,n,r);for(var a=Ke.concat(He(t),qe(t)),o=Fe[e.$$typeof]||De,i=Fe[t.$$typeof]||De,s=a.length,c=void 0,u=void 0;s--;)if(u=a[s],!(Le[u]||r&&r[u]||i&&i[u]||o&&o[u])&&(c=Be(t,u)))try{We(e,u,c)}catch(e){}return e}var Xe,Ze=Object(s.createContext)(),Je=Ze.Consumer,Qe=(Xe=s.Component,b(et,Xe),et.prototype.render=function(){return this.props.children?c.a.createElement(Ze.Consumer,null,this.renderInner):null},et.prototype.renderInner=function(e){var t=this.getContext(this.props.theme,e);return c.a.createElement(Ze.Provider,{value:t},c.a.Children.only(this.props.children))},et.prototype.getTheme=function(e,t){if(x(e))return e(t);if(null===e||Array.isArray(e)||"object"!==(void 0===e?"undefined":m(e)))throw new M(8);return v({},t,e)},et.prototype.getContext=function(e,t){return this.getTheme(e,t)},et);function et(e){y(this,et);var t=k(this,Xe.call(this,e));return t.getContext=Object(f.a)(t.getContext.bind(t)),t.renderInner=t.renderInner.bind(t),t}var tt=(rt.prototype.seal=function(){if(!this.sealed){var e=this.masterSheet.clones.indexOf(this.instance);this.masterSheet.clones.splice(e,1),this.sealed=!0}},rt.prototype.collectStyles=function(e){if(this.sealed)throw new M(2);return c.a.createElement(it,{sheet:this.instance},e)},rt.prototype.getStyleTags=function(){return this.seal(),this.instance.toHTML()},rt.prototype.getStyleElement=function(){return this.seal(),this.instance.toReactElements()},rt.prototype.interleaveWithNodeStream=function(e){throw new M(3)},rt);function rt(){y(this,rt),this.masterSheet=he.master,this.instance=this.masterSheet.clone(),this.sealed=!1}var nt,at=Object(s.createContext)(),ot=at.Consumer,it=(nt=s.Component,b(st,nt),st.prototype.getContext=function(e,t){if(e)return e;if(t)return new he(t);throw new M(4)},st.prototype.render=function(){var e=this.props,t=e.children,r=e.sheet,n=e.target;return c.a.createElement(at.Provider,{value:this.getContext(r,n)},t)},st);function st(e){y(this,st);var t=k(this,nt.call(this,e));return t.getContext=Object(f.a)(t.getContext),t}var ct,ut={},lt=(ct=s.Component,b(ft,ct),ft.prototype.render=function(){return c.a.createElement(ot,null,this.renderOuter)},ft.prototype.renderOuter=function(e){var t=0"+e()+""}}function oe(e,t){return function(){var r,n=((r={})[E]=Q(t),r[R]="4.3.2",r),a=V();return a&&(n.nonce=a),c.a.createElement("style",v({},n,{dangerouslySetInnerHTML:{__html:e()}}))}}function ie(e){return function(){return Object.keys(e)}}function se(e){return document.createTextNode(re(e))}function ce(e,t,r,n,a){if(!I||r)return function e(t,r){function n(e){var t=i[e];return void 0!==t?t:i[e]=[""]}function a(){var e="";for(var t in i){var r=i[t][0];r&&(e+=re(t)+r)}return e}var o=void 0===t?Object.create(null):t,i=void 0===r?Object.create(null):r;return{clone:function(){var t=function(e){var t=Object.create(null);for(var r in e)t[r]=v({},e[r]);return t}(o),r=Object.create(null);for(var n in i)r[n]=[i[n][0]];return e(t,r)},css:a,getIds:ie(i),hasNameForId:J(o),insertMarker:n,insertRules:function(e,t,r){n(e)[0]+=t.join(" "),X(o,e,r)},removeRules:function(e){var t=i[e];void 0!==t&&(t[0]="",Z(o,e))},sealed:!1,styleTag:null,toElement:oe(a,o),toHTML:ae(a,o)}}();var o=function(e,t,r){var n=document.createElement("style");n.setAttribute(E,""),n.setAttribute(R,"4.3.2");var a=V();if(a&&n.setAttribute("nonce",a),n.appendChild(document.createTextNode("")),e&&!t)e.appendChild(n);else{if(!t||!e||!t.parentNode)throw new M(6);t.parentNode.insertBefore(n,r?t:t.nextSibling)}return n}(e,t,n);return P?function(e,t){function r(t){var r=o[t];return void 0!==r?r:(o[t]=se(t),e.appendChild(o[t]),a[t]=Object.create(null),o[t])}function n(){var e="";for(var t in o)e+=o[t].data;return e}var a=Object.create(null),o=Object.create(null),i=void 0!==t,s=!1;return{clone:function(){throw new M(5)},css:n,getIds:ie(o),hasNameForId:J(a),insertMarker:r,insertRules:function(e,n,o){for(var c=r(e),u=[],l=n.length,f=0;f>>16)&65535)<<16),n=1540483477*(65535&n)+((1540483477*(n>>>16)&65535)<<16)^(t=1540483477*(65535&(t^=t>>>24))+((1540483477*(t>>>16)&65535)<<16)),r-=4,++a;switch(r){case 3:n^=(255&e.charCodeAt(a+2))<<16;case 2:n^=(255&e.charCodeAt(a+1))<<8;case 1:n=1540483477*(65535&(n^=255&e.charCodeAt(a)))+((1540483477*(n>>>16)&65535)<<16)}return((n=1540483477*(65535&(n^=n>>>13))+((1540483477*(n>>>16)&65535)<<16))^n>>>15)>>>0}var xe=52,Oe=function(e){return String.fromCharCode(e+(25<+~=|^:(),"'`-]+/g,Ne=/(^-|-$)/g;function $e(e){return e.replace(Me,"-").replace(Ne,"")}function ze(e){return"string"==typeof e&&!0}var De={childContextTypes:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDerivedStateFromProps:!0,propTypes:!0,type:!0},Le={name:!0,length:!0,prototype:!0,caller:!0,callee:!0,arguments:!0,arity:!0},qe=((Pe={})[l.ForwardRef]={$$typeof:!0,render:!0},Pe),Fe=Object.defineProperty,We=Object.getOwnPropertyNames,He=Object.getOwnPropertySymbols,Ue=void 0===He?function(){return[]}:He,Be=Object.getOwnPropertyDescriptor,Ge=Object.getPrototypeOf,Ye=Object.prototype,Ke=Array.prototype;function Ve(e,t,r){if("string"==typeof t)return e;var n=Ge(t);n&&n!==Ye&&Ve(e,n,r);for(var a=Ke.concat(We(t),Ue(t)),o=qe[e.$$typeof]||De,i=qe[t.$$typeof]||De,s=a.length,c=void 0,u=void 0;s--;)if(u=a[s],!(Le[u]||r&&r[u]||i&&i[u]||o&&o[u])&&(c=Be(t,u)))try{Fe(e,u,c)}catch(e){}return e}var Xe,Ze=Object(s.createContext)(),Je=Ze.Consumer,Qe=(Xe=s.Component,b(et,Xe),et.prototype.render=function(){return this.props.children?c.a.createElement(Ze.Consumer,null,this.renderInner):null},et.prototype.renderInner=function(e){var t=this.getContext(this.props.theme,e);return c.a.createElement(Ze.Provider,{value:t},c.a.Children.only(this.props.children))},et.prototype.getTheme=function(e,t){if(x(e))return e(t);if(null===e||Array.isArray(e)||"object"!==(void 0===e?"undefined":m(e)))throw new M(8);return v({},t,e)},et.prototype.getContext=function(e,t){return this.getTheme(e,t)},et);function et(e){y(this,et);var t=k(this,Xe.call(this,e));return t.getContext=Object(f.a)(t.getContext.bind(t)),t.renderInner=t.renderInner.bind(t),t}var tt=(rt.prototype.seal=function(){if(!this.sealed){var e=this.masterSheet.clones.indexOf(this.instance);this.masterSheet.clones.splice(e,1),this.sealed=!0}},rt.prototype.collectStyles=function(e){if(this.sealed)throw new M(2);return c.a.createElement(it,{sheet:this.instance},e)},rt.prototype.getStyleTags=function(){return this.seal(),this.instance.toHTML()},rt.prototype.getStyleElement=function(){return this.seal(),this.instance.toReactElements()},rt.prototype.interleaveWithNodeStream=function(e){throw new M(3)},rt);function rt(){y(this,rt),this.masterSheet=he.master,this.instance=this.masterSheet.clone(),this.sealed=!1}var nt,at=Object(s.createContext)(),ot=at.Consumer,it=(nt=s.Component,b(st,nt),st.prototype.getContext=function(e,t){if(e)return e;if(t)return new he(t);throw new M(4)},st.prototype.render=function(){var e=this.props,t=e.children,r=e.sheet,n=e.target;return c.a.createElement(at.Provider,{value:this.getContext(r,n)},t)},st);function st(e){y(this,st);var t=k(this,nt.call(this,e));return t.getContext=Object(f.a)(t.getContext),t}var ct,ut={},lt=(ct=s.Component,b(ft,ct),ft.prototype.render=function(){return c.a.createElement(ot,null,this.renderOuter)},ft.prototype.renderOuter=function(e){var t=0])/g,v=/([[}=:>])\s+/g,b=/(\{[^{]+?);(?=\})/g,w=/\s{2,}/g,k=/([^\(])(:+) */g,C=/[svh]\w+-[tblr]{2}/,S=/\(\s*(.*)\s*\)/g,A=/([\s\S]*?);/g,x=/-self|flex-/g,O=/[^]*?(:[rp][el]a[\w-]+)[^]*/,j=/stretch|:\s*\w+\-(?:conte|avail)/,_=/([^-])(image-set\()/,E="-webkit-",R="-moz-",I="-ms-",P=59,T=125,M=123,N=40,$=41,z=91,D=93,L=10,q=13,F=9,W=64,H=32,U=38,B=45,G=95,Y=42,K=44,V=58,X=39,Z=34,J=47,Q=62,ee=43,te=126,re=0,ne=12,ae=11,oe=107,ie=109,se=115,ce=112,ue=111,le=105,fe=99,de=100,he=112,pe=1,me=1,ye=0,ge=1,ve=1,be=1,we=0,ke=0,Ce=0,Se=[],Ae=[],xe=0,Oe=null,je=-2,_e=-1,Ee=0,Re=1,Ie=2,Pe=3,Te=0,Me=1,Ne="",$e="",ze="";function De(e,t,r){var n=t.trim().split(l),a=n,o=n.length,i=e.length;switch(i){case 0:case 1:for(var s=0,c=0===i?"":e[0]+" ";s>>16)&65535)<<16),n=1540483477*(65535&n)+((1540483477*(n>>>16)&65535)<<16)^(t=1540483477*(65535&(t^=t>>>24))+((1540483477*(t>>>16)&65535)<<16)),r-=4,++a;switch(r){case 3:n^=(255&e.charCodeAt(a+2))<<16;case 2:n^=(255&e.charCodeAt(a+1))<<8;case 1:n=1540483477*(65535&(n^=255&e.charCodeAt(a)))+((1540483477*(n>>>16)&65535)<<16)}return n=1540483477*(65535&(n^=n>>>13))+((1540483477*(n>>>16)&65535)<<16),((n^=n>>>15)>>>0).toString(36)},y=r(2),g=r(3),v=/[A-Z]|^ms/g,b=/_EMO_([^_]+?)_([^]*?)_EMO_/g,w=Object(g.a)(function(e){return p(e)?e:e.replace(v,"-$&").toLowerCase()}),k=function(e,t){if(null==t||"boolean"==typeof t)return"";switch(e){case"animation":case"animationName":"string"==typeof t&&(t=t.replace(b,function(e,t,r){return S={name:t,styles:r,next:S},t}))}return 1===y.a[e]||p(e)||"number"!=typeof t||0===t?t:t+"px"};function C(e,t,r,n){if(null==r)return"";if(void 0!==r.__emotion_styles)return r;switch(typeof r){case"boolean":return"";case"object":if(1===r.anim)return S={name:r.name,styles:r.styles,next:S},r.name;if(void 0===r.styles)return function(e,t,r){var n="";if(Array.isArray(r))for(var a=0;a"):null)}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});function n(e,t){for(var r=0;r>>16)&65535)<<16),n=1540483477*(65535&n)+((1540483477*(n>>>16)&65535)<<16)^(t=1540483477*(65535&(t^=t>>>24))+((1540483477*(t>>>16)&65535)<<16)),r-=4,++a;switch(r){case 3:n^=(255&e.charCodeAt(a+2))<<16;case 2:n^=(255&e.charCodeAt(a+1))<<8;case 1:n=1540483477*(65535&(n^=255&e.charCodeAt(a)))+((1540483477*(n>>>16)&65535)<<16)}return n=1540483477*(65535&(n^=n>>>13))+((1540483477*(n>>>16)&65535)<<16),((n^=n>>>15)>>>0).toString(36)},y=r(2),g=r(3),v=/[A-Z]|^ms/g,b=/_EMO_([^_]+?)_([^]*?)_EMO_/g,w=Object(g.a)(function(e){return p(e)?e:e.replace(v,"-$&").toLowerCase()}),k=function(e,t){if(null==t||"boolean"==typeof t)return"";switch(e){case"animation":case"animationName":"string"==typeof t&&(t=t.replace(b,function(e,t,r){return S={name:t,styles:r,next:S},t}))}return 1===y.a[e]||p(e)||"number"!=typeof t||0===t?t:t+"px"};function C(e,t,r,n){if(null==r)return"";if(void 0!==r.__emotion_styles)return r;switch(typeof r){case"boolean":return"";case"object":if(1===r.anim)return S={name:r.name,styles:r.styles,next:S},r.name;if(void 0===r.styles)return function(e,t,r){var n="";if(Array.isArray(r))for(var a=0;a ({ type: "button", @@ -9,30 +13,44 @@ const Button = styled.button.attrs(() => ({ function Pagination(props) { let nextIndex = null; let prevIndex = null; + let pageButtons = []; + const { setIndex } = props; // Finding Next Page Start Index if (props.results !== null && typeof props.results.queries.nextPage !== 'undefined') { nextIndex = props.results.queries.nextPage[0].startIndex; - console.log(nextIndex); } // Finding Prev Page Start Index if (props.results !== null && typeof props.results.queries.previousPage !== 'undefined') { prevIndex = props.results.queries.previousPage[0].startIndex; - console.log(prevIndex); + } else { + prevIndex = null; + } + + // Setting Total Results + if (props.results !== null && typeof props.results.queries.request !== 'undefined') { + const totalResults = parseInt(props.results.queries.request[0].totalResults); + let totalPages = Math.round(totalResults / 10); + totalPages = totalPages > 10 ? 10 : totalPages; + + for (let i = 1; i <= totalPages; i++) { + let startIndex = 1 + (i - 1) * 10; + const currentButton = ; + + pageButtons = [...pageButtons, currentButton]; + } } return ( - - { prevIndex !== null - ? - : null - } + + + { pageButtons } { nextIndex !== null - ? + ? : null } - + ); } diff --git a/public/js/withData.js b/public/js/withData.js index 836e4c5..ccbe7ec 100644 --- a/public/js/withData.js +++ b/public/js/withData.js @@ -9,8 +9,10 @@ function withData(WrappedComponent) { this.state = { query: null, results: null, + start: null, handleChange: this.handleChange.bind(this), searchSite: this.searchSite.bind(this), + setIndex: this.setIndex.bind(this), error: null, loading: false, } @@ -33,9 +35,15 @@ function withData(WrappedComponent) { await this.setState({query: event.target.value}); } + setIndex(index) { + this.setState({start: index}, () => this.searchSite()); + } + searchSite(event) { - event.preventDefault(); - const { query } = this.state; + if (typeof event !== 'undefined') { + event.preventDefault(); + } + const { query, start } = this.state; if (query === null) { this.setState({error: 1}); return; @@ -43,7 +51,7 @@ function withData(WrappedComponent) { this.setState({loading: true}); - fetch(`/wp-json/fm-google-site-search/v1/search_site/?query=${query}`) + fetch(`/wp-json/fm-google-site-search/v1/search_site/?query=${query}${start !== null ? "&start=" + start : ""}`) .then(res => res.json()) .then(results => this.setState({results, query, error: null, loading: false})) .catch(() => this.setState({error: 2}))