diff --git a/README.md b/README.md new file mode 100644 index 0000000..abff702 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# Other-instances +A differents web apps for learning purpurose its include MERN stack the most time for full-stack dev. + +Hi there, I left some examples when learning web app content ;) diff --git a/app.js b/app.js new file mode 100644 index 0000000..056eda6 --- /dev/null +++ b/app.js @@ -0,0 +1,74 @@ +const path = require('path'); +const express = require('express'); +const bodyParser = require('body-parser'); +const session = require('express-session'); +const cors = require('cors'); +const errorHandler = require('errorhandler'); +const mongoose = require('mongoose'); + +const app = express(); + +mongoose.promise = global.Promise; + +const isProduction = process.env.NODE_ENV === 'production'; + +const db = require('./config/keys').mongoURI; + +mongoose.connect(db) +.then(() => console.log('Połączony...')) +.catch(err => console.log(err) ); + +require('./models/Articles.js'); +routes = require('./routes/index.js'); + + +app.use(cors()); +app.use(require('morgan')('dev')); +app.use(bodyParser.urlencoded({ extended: false })); +app.use(bodyParser.json()); +app.use(express.static(path.join(__dirname, 'public'))); +app.use(session({ secret: 'MałyBlog', cookie: { maxAge: 60000 }, resave: false, saveUninitialized: false })); + +if(!isProduction) { + app.use(errorHandler()); +} + + +mongoose.set('debug', true); + + +app.use(require('./routes')); + + +app.use((req, res, next) => { + const err = new Error('Not Found') + err.status = 404 + next(err) +}); + +if (!isProduction) { + app.use((err, req, res) => { + res.status(err.status || 500); + + res.json({ + errors: { + message: err.message, + error: err, + }, + }); + }); +} + +app.use((err, req, res) => { + res.status(err.status || 500); + + res.json({ + errors: { + message: err.message, + error: {}, + }, + }); +}); + +const port = process.env.PORT || 8000; +app.listen(port, () => console.log('Server działa na http://localhost:8000')); \ No newline at end of file diff --git a/client/dist/index.html b/client/dist/index.html new file mode 100644 index 0000000..1042177 --- /dev/null +++ b/client/dist/index.html @@ -0,0 +1 @@ + MałyBlog
\ No newline at end of file diff --git a/client/dist/main.js b/client/dist/main.js new file mode 100644 index 0000000..7670626 --- /dev/null +++ b/client/dist/main.js @@ -0,0 +1,29 @@ +!function(e){var t={};function n(r){if(t[r])return t[r].exports;var a=t[r]={i:r,l:!1,exports:{}};return e[r].call(a.exports,a,a.exports,n),a.l=!0,a.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)n.d(r,a,function(t){return e[t]}.bind(null,a));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="/",n(n.s=526)}([function(e,t,n){var r=n(5),a=n(28),i=n(19),o=n(18),s=n(27),u=function(e,t,n){var d,l,c,f,_=e&u.F,m=e&u.G,h=e&u.S,p=e&u.P,y=e&u.B,M=m?r:h?r[t]||(r[t]={}):(r[t]||{}).prototype,v=m?a:a[t]||(a[t]={}),g=v.prototype||(v.prototype={});for(d in m&&(n=t),n)c=((l=!_&&M&&void 0!==M[d])?M:n)[d],f=y&&l?s(c,r):p&&"function"==typeof c?s(Function.call,c):c,M&&o(M,d,c,e&u.U),v[d]!=c&&i(v,d,f),p&&g[d]!=c&&(g[d]=c)};r.core=a,u.F=1,u.G=2,u.S=4,u.P=8,u.B=16,u.W=32,u.U=64,u.R=128,e.exports=u},function(e,t,n){(function(e){e.exports=function(){"use strict";var t,r;function a(){return t.apply(null,arguments)}function i(e){return e instanceof Array||"[object Array]"===Object.prototype.toString.call(e)}function o(e){return null!=e&&"[object Object]"===Object.prototype.toString.call(e)}function s(e){return void 0===e}function u(e){return"number"==typeof e||"[object Number]"===Object.prototype.toString.call(e)}function d(e){return e instanceof Date||"[object Date]"===Object.prototype.toString.call(e)}function l(e,t){var n,r=[];for(n=0;n>>0,r=0;r0)for(n=0;n=0;return(i?n?"+":"":"-")+Math.pow(10,Math.max(0,a)).toString().substr(1)+r}var W=/(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|YYYYYY|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g,I=/(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g,z={},U={};function J(e,t,n,r){var a=r;"string"==typeof r&&(a=function(){return this[r]()}),e&&(U[e]=a),t&&(U[t[0]]=function(){return N(a.apply(this,arguments),t[1],t[2])}),n&&(U[n]=function(){return this.localeData().ordinal(a.apply(this,arguments),e)})}function B(e){return e.match(/\[[\s\S]/)?e.replace(/^\[|\]$/g,""):e.replace(/\\/g,"")}function V(e,t){return e.isValid()?(t=G(t,e.localeData()),z[t]=z[t]||function(e){var t,n,r=e.match(W);for(t=0,n=r.length;t=0&&I.test(e);)e=e.replace(I,r),I.lastIndex=0,n-=1;return e}var q=/\d/,$=/\d\d/,K=/\d{3}/,Q=/\d{4}/,Z=/[+-]?\d{6}/,X=/\d\d?/,ee=/\d\d\d\d?/,te=/\d\d\d\d\d\d?/,ne=/\d{1,3}/,re=/\d{1,4}/,ae=/[+-]?\d{1,6}/,ie=/\d+/,oe=/[+-]?\d+/,se=/Z|[+-]\d\d:?\d\d/gi,ue=/Z|[+-]\d\d(?::?\d\d)?/gi,de=/[0-9]{0,256}['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFF07\uFF10-\uFFEF]{1,256}|[\u0600-\u06FF\/]{1,256}(\s*?[\u0600-\u06FF]{1,256}){1,2}/i,le={};function ce(e,t,n){le[e]=j(t)?t:function(e,r){return e&&n?n:t}}function fe(e,t){return c(le,e)?le[e](t._strict,t._locale):new RegExp(function(e){return _e(e.replace("\\","").replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g,function(e,t,n,r,a){return t||n||r||a}))}(e))}function _e(e){return e.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")}var me={};function he(e,t){var n,r=t;for("string"==typeof e&&(e=[e]),u(t)&&(r=function(e,n){n[t]=w(e)}),n=0;n68?1900:2e3)};var xe,je=Ee("FullYear",!0);function Ee(e,t){return function(n){return null!=n?(Pe(this,e,n),a.updateOffset(this,t),this):Oe(this,e)}}function Oe(e,t){return e.isValid()?e._d["get"+(e._isUTC?"UTC":"")+t]():NaN}function Pe(e,t,n){e.isValid()&&!isNaN(n)&&("FullYear"===t&&Se(e.year())&&1===e.month()&&29===e.date()?e._d["set"+(e._isUTC?"UTC":"")+t](n,e.month(),He(n,e.month())):e._d["set"+(e._isUTC?"UTC":"")+t](n))}function He(e,t){if(isNaN(e)||isNaN(t))return NaN;var n=function(e,t){return(e%t+t)%t}(t,12);return e+=(t-n)/12,1===n?Se(e)?29:28:31-n%7%2}xe=Array.prototype.indexOf?Array.prototype.indexOf:function(e){var t;for(t=0;t=0&&isFinite(t.getUTCFullYear())&&t.setUTCFullYear(e),t}function Je(e,t,n){var r=7+t-n,a=(7+Ue(e,0,r).getUTCDay()-t)%7;return-a+r-1}function Be(e,t,n,r,a){var i,o,s=(7+n-r)%7,u=Je(e,r,a),d=1+7*(t-1)+s+u;return d<=0?o=De(i=e-1)+d:d>De(e)?(i=e+1,o=d-De(e)):(i=e,o=d),{year:i,dayOfYear:o}}function Ve(e,t,n){var r,a,i=Je(e.year(),t,n),o=Math.floor((e.dayOfYear()-i-1)/7)+1;return o<1?(a=e.year()-1,r=o+Ge(a,t,n)):o>Ge(e.year(),t,n)?(r=o-Ge(e.year(),t,n),a=e.year()+1):(a=e.year(),r=o),{week:r,year:a}}function Ge(e,t,n){var r=Je(e,t,n),a=Je(e+1,t,n);return(De(e)-r+a)/7}J("w",["ww",2],"wo","week"),J("W",["WW",2],"Wo","isoWeek"),H("week","w"),H("isoWeek","W"),R("week",5),R("isoWeek",5),ce("w",X),ce("ww",X,$),ce("W",X),ce("WW",X,$),pe(["w","ww","W","WW"],function(e,t,n,r){t[r.substr(0,1)]=w(e)}),J("d",0,"do","day"),J("dd",0,0,function(e){return this.localeData().weekdaysMin(this,e)}),J("ddd",0,0,function(e){return this.localeData().weekdaysShort(this,e)}),J("dddd",0,0,function(e){return this.localeData().weekdays(this,e)}),J("e",0,0,"weekday"),J("E",0,0,"isoWeekday"),H("day","d"),H("weekday","e"),H("isoWeekday","E"),R("day",11),R("weekday",11),R("isoWeekday",11),ce("d",X),ce("e",X),ce("E",X),ce("dd",function(e,t){return t.weekdaysMinRegex(e)}),ce("ddd",function(e,t){return t.weekdaysShortRegex(e)}),ce("dddd",function(e,t){return t.weekdaysRegex(e)}),pe(["dd","ddd","dddd"],function(e,t,n,r){var a=n._locale.weekdaysParse(e,r,n._strict);null!=a?t.d=a:m(n).invalidWeekday=e}),pe(["d","e","E"],function(e,t,n,r){t[r]=w(e)});var qe="Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),$e="Sun_Mon_Tue_Wed_Thu_Fri_Sat".split("_"),Ke="Su_Mo_Tu_We_Th_Fr_Sa".split("_"),Qe=de,Ze=de,Xe=de;function et(){function e(e,t){return t.length-e.length}var t,n,r,a,i,o=[],s=[],u=[],d=[];for(t=0;t<7;t++)n=_([2e3,1]).day(t),r=this.weekdaysMin(n,""),a=this.weekdaysShort(n,""),i=this.weekdays(n,""),o.push(r),s.push(a),u.push(i),d.push(r),d.push(a),d.push(i);for(o.sort(e),s.sort(e),u.sort(e),d.sort(e),t=0;t<7;t++)s[t]=_e(s[t]),u[t]=_e(u[t]),d[t]=_e(d[t]);this._weekdaysRegex=new RegExp("^("+d.join("|")+")","i"),this._weekdaysShortRegex=this._weekdaysRegex,this._weekdaysMinRegex=this._weekdaysRegex,this._weekdaysStrictRegex=new RegExp("^("+u.join("|")+")","i"),this._weekdaysShortStrictRegex=new RegExp("^("+s.join("|")+")","i"),this._weekdaysMinStrictRegex=new RegExp("^("+o.join("|")+")","i")}function tt(){return this.hours()%12||12}function nt(e,t){J(e,0,0,function(){return this.localeData().meridiem(this.hours(),this.minutes(),t)})}function rt(e,t){return t._meridiemParse}J("H",["HH",2],0,"hour"),J("h",["hh",2],0,tt),J("k",["kk",2],0,function(){return this.hours()||24}),J("hmm",0,0,function(){return""+tt.apply(this)+N(this.minutes(),2)}),J("hmmss",0,0,function(){return""+tt.apply(this)+N(this.minutes(),2)+N(this.seconds(),2)}),J("Hmm",0,0,function(){return""+this.hours()+N(this.minutes(),2)}),J("Hmmss",0,0,function(){return""+this.hours()+N(this.minutes(),2)+N(this.seconds(),2)}),nt("a",!0),nt("A",!1),H("hour","h"),R("hour",13),ce("a",rt),ce("A",rt),ce("H",X),ce("h",X),ce("k",X),ce("HH",X,$),ce("hh",X,$),ce("kk",X,$),ce("hmm",ee),ce("hmmss",te),ce("Hmm",ee),ce("Hmmss",te),he(["H","HH"],Le),he(["k","kk"],function(e,t,n){var r=w(e);t[Le]=24===r?0:r}),he(["a","A"],function(e,t,n){n._isPm=n._locale.isPM(e),n._meridiem=e}),he(["h","hh"],function(e,t,n){t[Le]=w(e),m(n).bigHour=!0}),he("hmm",function(e,t,n){var r=e.length-2;t[Le]=w(e.substr(0,r)),t[Ye]=w(e.substr(r)),m(n).bigHour=!0}),he("hmmss",function(e,t,n){var r=e.length-4,a=e.length-2;t[Le]=w(e.substr(0,r)),t[Ye]=w(e.substr(r,2)),t[we]=w(e.substr(a)),m(n).bigHour=!0}),he("Hmm",function(e,t,n){var r=e.length-2;t[Le]=w(e.substr(0,r)),t[Ye]=w(e.substr(r))}),he("Hmmss",function(e,t,n){var r=e.length-4,a=e.length-2;t[Le]=w(e.substr(0,r)),t[Ye]=w(e.substr(r,2)),t[we]=w(e.substr(a))});var at,it=Ee("Hours",!0),ot={calendar:{sameDay:"[Today at] LT",nextDay:"[Tomorrow at] LT",nextWeek:"dddd [at] LT",lastDay:"[Yesterday at] LT",lastWeek:"[Last] dddd [at] LT",sameElse:"L"},longDateFormat:{LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"},invalidDate:"Invalid date",ordinal:"%d",dayOfMonthOrdinalParse:/\d{1,2}/,relativeTime:{future:"in %s",past:"%s ago",s:"a few seconds",ss:"%d seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"},months:Ae,monthsShort:Fe,week:{dow:0,doy:6},weekdays:qe,weekdaysMin:Ke,weekdaysShort:$e,meridiemParse:/[ap]\.?m?\.?/i},st={},ut={};function dt(e){return e?e.toLowerCase().replace("_","-"):e}function lt(t){var r=null;if(!st[t]&&void 0!==e&&e&&e.exports)try{r=at._abbr,n(280)("./"+t),ct(r)}catch(e){}return st[t]}function ct(e,t){var n;return e&&((n=s(t)?_t(e):ft(e,t))?at=n:"undefined"!=typeof console&&console.warn&&console.warn("Locale "+e+" not found. Did you forget to load it?")),at._abbr}function ft(e,t){if(null!==t){var n,r=ot;if(t.abbr=e,null!=st[e])x("defineLocaleOverride","use moment.updateLocale(localeName, config) to change an existing locale. moment.defineLocale(localeName, config) should only be used for creating a new locale See http://momentjs.com/guides/#/warnings/define-locale/ for more info."),r=st[e]._config;else if(null!=t.parentLocale)if(null!=st[t.parentLocale])r=st[t.parentLocale]._config;else{if(null==(n=lt(t.parentLocale)))return ut[t.parentLocale]||(ut[t.parentLocale]=[]),ut[t.parentLocale].push({name:e,config:t}),null;r=n._config}return st[e]=new O(E(r,t)),ut[e]&&ut[e].forEach(function(e){ft(e.name,e.config)}),ct(e),st[e]}return delete st[e],null}function _t(e){var t;if(e&&e._locale&&e._locale._abbr&&(e=e._locale._abbr),!e)return at;if(!i(e)){if(t=lt(e))return t;e=[e]}return function(e){for(var t,n,r,a,i=0;i0;){if(r=lt(a.slice(0,t).join("-")))return r;if(n&&n.length>=t&&b(a,n,!0)>=t-1)break;t--}i++}return at}(e)}function mt(e){var t,n=e._a;return n&&-2===m(e).overflow&&(t=n[ve]<0||n[ve]>11?ve:n[ge]<1||n[ge]>He(n[Me],n[ve])?ge:n[Le]<0||n[Le]>24||24===n[Le]&&(0!==n[Ye]||0!==n[we]||0!==n[be])?Le:n[Ye]<0||n[Ye]>59?Ye:n[we]<0||n[we]>59?we:n[be]<0||n[be]>999?be:-1,m(e)._overflowDayOfYear&&(tge)&&(t=ge),m(e)._overflowWeeks&&-1===t&&(t=ke),m(e)._overflowWeekday&&-1===t&&(t=Te),m(e).overflow=t),e}function ht(e,t,n){return null!=e?e:null!=t?t:n}function pt(e){var t,n,r,i,o,s=[];if(!e._d){for(r=function(e){var t=new Date(a.now());return e._useUTC?[t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate()]:[t.getFullYear(),t.getMonth(),t.getDate()]}(e),e._w&&null==e._a[ge]&&null==e._a[ve]&&function(e){var t,n,r,a,i,o,s,u;if(null!=(t=e._w).GG||null!=t.W||null!=t.E)i=1,o=4,n=ht(t.GG,e._a[Me],Ve(Et(),1,4).year),r=ht(t.W,1),((a=ht(t.E,1))<1||a>7)&&(u=!0);else{i=e._locale._week.dow,o=e._locale._week.doy;var d=Ve(Et(),i,o);n=ht(t.gg,e._a[Me],d.year),r=ht(t.w,d.week),null!=t.d?((a=t.d)<0||a>6)&&(u=!0):null!=t.e?(a=t.e+i,(t.e<0||t.e>6)&&(u=!0)):a=i}r<1||r>Ge(n,i,o)?m(e)._overflowWeeks=!0:null!=u?m(e)._overflowWeekday=!0:(s=Be(n,r,a,i,o),e._a[Me]=s.year,e._dayOfYear=s.dayOfYear)}(e),null!=e._dayOfYear&&(o=ht(e._a[Me],r[Me]),(e._dayOfYear>De(o)||0===e._dayOfYear)&&(m(e)._overflowDayOfYear=!0),n=Ue(o,0,e._dayOfYear),e._a[ve]=n.getUTCMonth(),e._a[ge]=n.getUTCDate()),t=0;t<3&&null==e._a[t];++t)e._a[t]=s[t]=r[t];for(;t<7;t++)e._a[t]=s[t]=null==e._a[t]?2===t?1:0:e._a[t];24===e._a[Le]&&0===e._a[Ye]&&0===e._a[we]&&0===e._a[be]&&(e._nextDay=!0,e._a[Le]=0),e._d=(e._useUTC?Ue:function(e,t,n,r,a,i,o){var s=new Date(e,t,n,r,a,i,o);return e<100&&e>=0&&isFinite(s.getFullYear())&&s.setFullYear(e),s}).apply(null,s),i=e._useUTC?e._d.getUTCDay():e._d.getDay(),null!=e._tzm&&e._d.setUTCMinutes(e._d.getUTCMinutes()-e._tzm),e._nextDay&&(e._a[Le]=24),e._w&&void 0!==e._w.d&&e._w.d!==i&&(m(e).weekdayMismatch=!0)}}var yt=/^\s*((?:[+-]\d{6}|\d{4})-(?:\d\d-\d\d|W\d\d-\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?::\d\d(?::\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?$/,Mt=/^\s*((?:[+-]\d{6}|\d{4})(?:\d\d\d\d|W\d\d\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?:\d\d(?:\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?$/,vt=/Z|[+-]\d\d(?::?\d\d)?/,gt=[["YYYYYY-MM-DD",/[+-]\d{6}-\d\d-\d\d/],["YYYY-MM-DD",/\d{4}-\d\d-\d\d/],["GGGG-[W]WW-E",/\d{4}-W\d\d-\d/],["GGGG-[W]WW",/\d{4}-W\d\d/,!1],["YYYY-DDD",/\d{4}-\d{3}/],["YYYY-MM",/\d{4}-\d\d/,!1],["YYYYYYMMDD",/[+-]\d{10}/],["YYYYMMDD",/\d{8}/],["GGGG[W]WWE",/\d{4}W\d{3}/],["GGGG[W]WW",/\d{4}W\d{2}/,!1],["YYYYDDD",/\d{7}/]],Lt=[["HH:mm:ss.SSSS",/\d\d:\d\d:\d\d\.\d+/],["HH:mm:ss,SSSS",/\d\d:\d\d:\d\d,\d+/],["HH:mm:ss",/\d\d:\d\d:\d\d/],["HH:mm",/\d\d:\d\d/],["HHmmss.SSSS",/\d\d\d\d\d\d\.\d+/],["HHmmss,SSSS",/\d\d\d\d\d\d,\d+/],["HHmmss",/\d\d\d\d\d\d/],["HHmm",/\d\d\d\d/],["HH",/\d\d/]],Yt=/^\/?Date\((\-?\d+)/i;function wt(e){var t,n,r,a,i,o,s=e._i,u=yt.exec(s)||Mt.exec(s);if(u){for(m(e).iso=!0,t=0,n=gt.length;t0&&m(e).unusedInput.push(o),s=s.slice(s.indexOf(n)+n.length),d+=n.length),U[i]?(n?m(e).empty=!1:m(e).unusedTokens.push(i),ye(i,n,e)):e._strict&&!n&&m(e).unusedTokens.push(i);m(e).charsLeftOver=u-d,s.length>0&&m(e).unusedInput.push(s),e._a[Le]<=12&&!0===m(e).bigHour&&e._a[Le]>0&&(m(e).bigHour=void 0),m(e).parsedDateParts=e._a.slice(0),m(e).meridiem=e._meridiem,e._a[Le]=function(e,t,n){var r;return null==n?t:null!=e.meridiemHour?e.meridiemHour(t,n):null!=e.isPM?((r=e.isPM(n))&&t<12&&(t+=12),r||12!==t||(t=0),t):t}(e._locale,e._a[Le],e._meridiem),pt(e),mt(e)}else Dt(e);else wt(e)}function xt(e){var t=e._i,n=e._f;return e._locale=e._locale||_t(e._l),null===t||void 0===n&&""===t?p({nullInput:!0}):("string"==typeof t&&(e._i=t=e._locale.preparse(t)),L(t)?new g(mt(t)):(d(t)?e._d=t:i(n)?function(e){var t,n,r,a,i;if(0===e._f.length)return m(e).invalidFormat=!0,void(e._d=new Date(NaN));for(a=0;athis?this:e:p()});function Ht(e,t){var n,r;if(1===t.length&&i(t[0])&&(t=t[0]),!t.length)return Et();for(n=t[0],r=1;ri&&(t=i),function(e,t,n,r,a){var i=Be(e,t,n,r,a),o=Ue(i.year,0,i.dayOfYear);return this.year(o.getUTCFullYear()),this.month(o.getUTCMonth()),this.date(o.getUTCDate()),this}.call(this,e,t,n,r,a))}J(0,["gg",2],0,function(){return this.weekYear()%100}),J(0,["GG",2],0,function(){return this.isoWeekYear()%100}),an("gggg","weekYear"),an("ggggg","weekYear"),an("GGGG","isoWeekYear"),an("GGGGG","isoWeekYear"),H("weekYear","gg"),H("isoWeekYear","GG"),R("weekYear",1),R("isoWeekYear",1),ce("G",oe),ce("g",oe),ce("GG",X,$),ce("gg",X,$),ce("GGGG",re,Q),ce("gggg",re,Q),ce("GGGGG",ae,Z),ce("ggggg",ae,Z),pe(["gggg","ggggg","GGGG","GGGGG"],function(e,t,n,r){t[r.substr(0,2)]=w(e)}),pe(["gg","GG"],function(e,t,n,r){t[r]=a.parseTwoDigitYear(e)}),J("Q",0,"Qo","quarter"),H("quarter","Q"),R("quarter",7),ce("Q",q),he("Q",function(e,t){t[ve]=3*(w(e)-1)}),J("D",["DD",2],"Do","date"),H("date","D"),R("date",9),ce("D",X),ce("DD",X,$),ce("Do",function(e,t){return e?t._dayOfMonthOrdinalParse||t._ordinalParse:t._dayOfMonthOrdinalParseLenient}),he(["D","DD"],ge),he("Do",function(e,t){t[ge]=w(e.match(X)[0])});var sn=Ee("Date",!0);J("DDD",["DDDD",3],"DDDo","dayOfYear"),H("dayOfYear","DDD"),R("dayOfYear",4),ce("DDD",ne),ce("DDDD",K),he(["DDD","DDDD"],function(e,t,n){n._dayOfYear=w(e)}),J("m",["mm",2],0,"minute"),H("minute","m"),R("minute",14),ce("m",X),ce("mm",X,$),he(["m","mm"],Ye);var un=Ee("Minutes",!1);J("s",["ss",2],0,"second"),H("second","s"),R("second",15),ce("s",X),ce("ss",X,$),he(["s","ss"],we);var dn,ln=Ee("Seconds",!1);for(J("S",0,0,function(){return~~(this.millisecond()/100)}),J(0,["SS",2],0,function(){return~~(this.millisecond()/10)}),J(0,["SSS",3],0,"millisecond"),J(0,["SSSS",4],0,function(){return 10*this.millisecond()}),J(0,["SSSSS",5],0,function(){return 100*this.millisecond()}),J(0,["SSSSSS",6],0,function(){return 1e3*this.millisecond()}),J(0,["SSSSSSS",7],0,function(){return 1e4*this.millisecond()}),J(0,["SSSSSSSS",8],0,function(){return 1e5*this.millisecond()}),J(0,["SSSSSSSSS",9],0,function(){return 1e6*this.millisecond()}),H("millisecond","ms"),R("millisecond",16),ce("S",ne,q),ce("SS",ne,$),ce("SSS",ne,K),dn="SSSS";dn.length<=9;dn+="S")ce(dn,ie);function cn(e,t){t[be]=w(1e3*("0."+e))}for(dn="S";dn.length<=9;dn+="S")he(dn,cn);var fn=Ee("Milliseconds",!1);J("z",0,0,"zoneAbbr"),J("zz",0,0,"zoneName");var _n=g.prototype;function mn(e){return e}_n.add=Zt,_n.calendar=function(e,t){var n=e||Et(),r=zt(n,this).startOf("day"),i=a.calendarFormat(this,r)||"sameElse",o=t&&(j(t[i])?t[i].call(this,n):t[i]);return this.format(o||this.localeData().calendar(i,this,Et(n)))},_n.clone=function(){return new g(this)},_n.diff=function(e,t,n){var r,a,i;if(!this.isValid())return NaN;if(!(r=zt(e,this)).isValid())return NaN;switch(a=6e4*(r.utcOffset()-this.utcOffset()),t=C(t)){case"year":i=en(this,r)/12;break;case"month":i=en(this,r);break;case"quarter":i=en(this,r)/3;break;case"second":i=(this-r)/1e3;break;case"minute":i=(this-r)/6e4;break;case"hour":i=(this-r)/36e5;break;case"day":i=(this-r-a)/864e5;break;case"week":i=(this-r-a)/6048e5;break;default:i=this-r}return n?i:Y(i)},_n.endOf=function(e){return void 0===(e=C(e))||"millisecond"===e?this:("date"===e&&(e="day"),this.startOf(e).add(1,"isoWeek"===e?"week":e).subtract(1,"ms"))},_n.format=function(e){e||(e=this.isUtc()?a.defaultFormatUtc:a.defaultFormat);var t=V(this,e);return this.localeData().postformat(t)},_n.from=function(e,t){return this.isValid()&&(L(e)&&e.isValid()||Et(e).isValid())?Gt({to:this,from:e}).locale(this.locale()).humanize(!t):this.localeData().invalidDate()},_n.fromNow=function(e){return this.from(Et(),e)},_n.to=function(e,t){return this.isValid()&&(L(e)&&e.isValid()||Et(e).isValid())?Gt({from:this,to:e}).locale(this.locale()).humanize(!t):this.localeData().invalidDate()},_n.toNow=function(e){return this.to(Et(),e)},_n.get=function(e){return j(this[e=C(e)])?this[e]():this},_n.invalidAt=function(){return m(this).overflow},_n.isAfter=function(e,t){var n=L(e)?e:Et(e);return!(!this.isValid()||!n.isValid())&&("millisecond"===(t=C(s(t)?"millisecond":t))?this.valueOf()>n.valueOf():n.valueOf()9999?V(n,t?"YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]":"YYYYYY-MM-DD[T]HH:mm:ss.SSSZ"):j(Date.prototype.toISOString)?t?this.toDate().toISOString():new Date(this.valueOf()+60*this.utcOffset()*1e3).toISOString().replace("Z",V(n,"Z")):V(n,t?"YYYY-MM-DD[T]HH:mm:ss.SSS[Z]":"YYYY-MM-DD[T]HH:mm:ss.SSSZ")},_n.inspect=function(){if(!this.isValid())return"moment.invalid(/* "+this._i+" */)";var e="moment",t="";this.isLocal()||(e=0===this.utcOffset()?"moment.utc":"moment.parseZone",t="Z");var n="["+e+'("]',r=0<=this.year()&&this.year()<=9999?"YYYY":"YYYYYY",a=t+'[")]';return this.format(n+r+"-MM-DD[T]HH:mm:ss.SSS"+a)},_n.toJSON=function(){return this.isValid()?this.toISOString():null},_n.toString=function(){return this.clone().locale("en").format("ddd MMM DD YYYY HH:mm:ss [GMT]ZZ")},_n.unix=function(){return Math.floor(this.valueOf()/1e3)},_n.valueOf=function(){return this._d.valueOf()-6e4*(this._offset||0)},_n.creationData=function(){return{input:this._i,format:this._f,locale:this._locale,isUTC:this._isUTC,strict:this._strict}},_n.year=je,_n.isLeapYear=function(){return Se(this.year())},_n.weekYear=function(e){return on.call(this,e,this.week(),this.weekday(),this.localeData()._week.dow,this.localeData()._week.doy)},_n.isoWeekYear=function(e){return on.call(this,e,this.isoWeek(),this.isoWeekday(),1,4)},_n.quarter=_n.quarters=function(e){return null==e?Math.ceil((this.month()+1)/3):this.month(3*(e-1)+this.month()%3)},_n.month=Ne,_n.daysInMonth=function(){return He(this.year(),this.month())},_n.week=_n.weeks=function(e){var t=this.localeData().week(this);return null==e?t:this.add(7*(e-t),"d")},_n.isoWeek=_n.isoWeeks=function(e){var t=Ve(this,1,4).week;return null==e?t:this.add(7*(e-t),"d")},_n.weeksInYear=function(){var e=this.localeData()._week;return Ge(this.year(),e.dow,e.doy)},_n.isoWeeksInYear=function(){return Ge(this.year(),1,4)},_n.date=sn,_n.day=_n.days=function(e){if(!this.isValid())return null!=e?this:NaN;var t=this._isUTC?this._d.getUTCDay():this._d.getDay();return null!=e?(e=function(e,t){return"string"!=typeof e?e:isNaN(e)?"number"==typeof(e=t.weekdaysParse(e))?e:null:parseInt(e,10)}(e,this.localeData()),this.add(e-t,"d")):t},_n.weekday=function(e){if(!this.isValid())return null!=e?this:NaN;var t=(this.day()+7-this.localeData()._week.dow)%7;return null==e?t:this.add(e-t,"d")},_n.isoWeekday=function(e){if(!this.isValid())return null!=e?this:NaN;if(null!=e){var t=function(e,t){return"string"==typeof e?t.weekdaysParse(e)%7||7:isNaN(e)?null:e}(e,this.localeData());return this.day(this.day()%7?t:t-7)}return this.day()||7},_n.dayOfYear=function(e){var t=Math.round((this.clone().startOf("day")-this.clone().startOf("year"))/864e5)+1;return null==e?t:this.add(e-t,"d")},_n.hour=_n.hours=it,_n.minute=_n.minutes=un,_n.second=_n.seconds=ln,_n.millisecond=_n.milliseconds=fn,_n.utcOffset=function(e,t,n){var r,i=this._offset||0;if(!this.isValid())return null!=e?this:NaN;if(null!=e){if("string"==typeof e){if(null===(e=It(ue,e)))return this}else Math.abs(e)<16&&!n&&(e*=60);return!this._isUTC&&t&&(r=Ut(this)),this._offset=e,this._isUTC=!0,null!=r&&this.add(r,"m"),i!==e&&(!t||this._changeInProgress?Qt(this,Gt(e-i,"m"),1,!1):this._changeInProgress||(this._changeInProgress=!0,a.updateOffset(this,!0),this._changeInProgress=null)),this}return this._isUTC?i:Ut(this)},_n.utc=function(e){return this.utcOffset(0,e)},_n.local=function(e){return this._isUTC&&(this.utcOffset(0,e),this._isUTC=!1,e&&this.subtract(Ut(this),"m")),this},_n.parseZone=function(){if(null!=this._tzm)this.utcOffset(this._tzm,!1,!0);else if("string"==typeof this._i){var e=It(se,this._i);null!=e?this.utcOffset(e):this.utcOffset(0,!0)}return this},_n.hasAlignedHourOffset=function(e){return!!this.isValid()&&(e=e?Et(e).utcOffset():0,(this.utcOffset()-e)%60==0)},_n.isDST=function(){return this.utcOffset()>this.clone().month(0).utcOffset()||this.utcOffset()>this.clone().month(5).utcOffset()},_n.isLocal=function(){return!!this.isValid()&&!this._isUTC},_n.isUtcOffset=function(){return!!this.isValid()&&this._isUTC},_n.isUtc=Jt,_n.isUTC=Jt,_n.zoneAbbr=function(){return this._isUTC?"UTC":""},_n.zoneName=function(){return this._isUTC?"Coordinated Universal Time":""},_n.dates=T("dates accessor is deprecated. Use date instead.",sn),_n.months=T("months accessor is deprecated. Use month instead",Ne),_n.years=T("years accessor is deprecated. Use year instead",je),_n.zone=T("moment().zone is deprecated, use moment().utcOffset instead. http://momentjs.com/guides/#/warnings/zone/",function(e,t){return null!=e?("string"!=typeof e&&(e=-e),this.utcOffset(e,t),this):-this.utcOffset()}),_n.isDSTShifted=T("isDSTShifted is deprecated. See http://momentjs.com/guides/#/warnings/dst-shifted/ for more information",function(){if(!s(this._isDSTShifted))return this._isDSTShifted;var e={};if(M(e,this),(e=xt(e))._a){var t=e._isUTC?_(e._a):Et(e._a);this._isDSTShifted=this.isValid()&&b(e._a,t.toArray())>0}else this._isDSTShifted=!1;return this._isDSTShifted});var hn=O.prototype;function pn(e,t,n,r){var a=_t(),i=_().set(r,t);return a[n](i,e)}function yn(e,t,n){if(u(e)&&(t=e,e=void 0),e=e||"",null!=t)return pn(e,t,n,"month");var r,a=[];for(r=0;r<12;r++)a[r]=pn(e,r,n,"month");return a}function Mn(e,t,n,r){"boolean"==typeof e?(u(t)&&(n=t,t=void 0),t=t||""):(n=t=e,e=!1,u(t)&&(n=t,t=void 0),t=t||"");var a,i=_t(),o=e?i._week.dow:0;if(null!=n)return pn(t,(n+o)%7,r,"day");var s=[];for(a=0;a<7;a++)s[a]=pn(t,(a+o)%7,r,"day");return s}hn.calendar=function(e,t,n){var r=this._calendar[e]||this._calendar.sameElse;return j(r)?r.call(t,n):r},hn.longDateFormat=function(e){var t=this._longDateFormat[e],n=this._longDateFormat[e.toUpperCase()];return t||!n?t:(this._longDateFormat[e]=n.replace(/MMMM|MM|DD|dddd/g,function(e){return e.slice(1)}),this._longDateFormat[e])},hn.invalidDate=function(){return this._invalidDate},hn.ordinal=function(e){return this._ordinal.replace("%d",e)},hn.preparse=mn,hn.postformat=mn,hn.relativeTime=function(e,t,n,r){var a=this._relativeTime[n];return j(a)?a(e,t,n,r):a.replace(/%d/i,e)},hn.pastFuture=function(e,t){var n=this._relativeTime[e>0?"future":"past"];return j(n)?n(t):n.replace(/%s/i,t)},hn.set=function(e){var t,n;for(n in e)j(t=e[n])?this[n]=t:this["_"+n]=t;this._config=e,this._dayOfMonthOrdinalParseLenient=new RegExp((this._dayOfMonthOrdinalParse.source||this._ordinalParse.source)+"|"+/\d{1,2}/.source)},hn.months=function(e,t){return e?i(this._months)?this._months[e.month()]:this._months[(this._months.isFormat||Ce).test(t)?"format":"standalone"][e.month()]:i(this._months)?this._months:this._months.standalone},hn.monthsShort=function(e,t){return e?i(this._monthsShort)?this._monthsShort[e.month()]:this._monthsShort[Ce.test(t)?"format":"standalone"][e.month()]:i(this._monthsShort)?this._monthsShort:this._monthsShort.standalone},hn.monthsParse=function(e,t,n){var r,a,i;if(this._monthsParseExact)return function(e,t,n){var r,a,i,o=e.toLocaleLowerCase();if(!this._monthsParse)for(this._monthsParse=[],this._longMonthsParse=[],this._shortMonthsParse=[],r=0;r<12;++r)i=_([2e3,r]),this._shortMonthsParse[r]=this.monthsShort(i,"").toLocaleLowerCase(),this._longMonthsParse[r]=this.months(i,"").toLocaleLowerCase();return n?"MMM"===t?-1!==(a=xe.call(this._shortMonthsParse,o))?a:null:-1!==(a=xe.call(this._longMonthsParse,o))?a:null:"MMM"===t?-1!==(a=xe.call(this._shortMonthsParse,o))?a:-1!==(a=xe.call(this._longMonthsParse,o))?a:null:-1!==(a=xe.call(this._longMonthsParse,o))?a:-1!==(a=xe.call(this._shortMonthsParse,o))?a:null}.call(this,e,t,n);for(this._monthsParse||(this._monthsParse=[],this._longMonthsParse=[],this._shortMonthsParse=[]),r=0;r<12;r++){if(a=_([2e3,r]),n&&!this._longMonthsParse[r]&&(this._longMonthsParse[r]=new RegExp("^"+this.months(a,"").replace(".","")+"$","i"),this._shortMonthsParse[r]=new RegExp("^"+this.monthsShort(a,"").replace(".","")+"$","i")),n||this._monthsParse[r]||(i="^"+this.months(a,"")+"|^"+this.monthsShort(a,""),this._monthsParse[r]=new RegExp(i.replace(".",""),"i")),n&&"MMMM"===t&&this._longMonthsParse[r].test(e))return r;if(n&&"MMM"===t&&this._shortMonthsParse[r].test(e))return r;if(!n&&this._monthsParse[r].test(e))return r}},hn.monthsRegex=function(e){return this._monthsParseExact?(c(this,"_monthsRegex")||ze.call(this),e?this._monthsStrictRegex:this._monthsRegex):(c(this,"_monthsRegex")||(this._monthsRegex=Ie),this._monthsStrictRegex&&e?this._monthsStrictRegex:this._monthsRegex)},hn.monthsShortRegex=function(e){return this._monthsParseExact?(c(this,"_monthsRegex")||ze.call(this),e?this._monthsShortStrictRegex:this._monthsShortRegex):(c(this,"_monthsShortRegex")||(this._monthsShortRegex=We),this._monthsShortStrictRegex&&e?this._monthsShortStrictRegex:this._monthsShortRegex)},hn.week=function(e){return Ve(e,this._week.dow,this._week.doy).week},hn.firstDayOfYear=function(){return this._week.doy},hn.firstDayOfWeek=function(){return this._week.dow},hn.weekdays=function(e,t){return e?i(this._weekdays)?this._weekdays[e.day()]:this._weekdays[this._weekdays.isFormat.test(t)?"format":"standalone"][e.day()]:i(this._weekdays)?this._weekdays:this._weekdays.standalone},hn.weekdaysMin=function(e){return e?this._weekdaysMin[e.day()]:this._weekdaysMin},hn.weekdaysShort=function(e){return e?this._weekdaysShort[e.day()]:this._weekdaysShort},hn.weekdaysParse=function(e,t,n){var r,a,i;if(this._weekdaysParseExact)return function(e,t,n){var r,a,i,o=e.toLocaleLowerCase();if(!this._weekdaysParse)for(this._weekdaysParse=[],this._shortWeekdaysParse=[],this._minWeekdaysParse=[],r=0;r<7;++r)i=_([2e3,1]).day(r),this._minWeekdaysParse[r]=this.weekdaysMin(i,"").toLocaleLowerCase(),this._shortWeekdaysParse[r]=this.weekdaysShort(i,"").toLocaleLowerCase(),this._weekdaysParse[r]=this.weekdays(i,"").toLocaleLowerCase();return n?"dddd"===t?-1!==(a=xe.call(this._weekdaysParse,o))?a:null:"ddd"===t?-1!==(a=xe.call(this._shortWeekdaysParse,o))?a:null:-1!==(a=xe.call(this._minWeekdaysParse,o))?a:null:"dddd"===t?-1!==(a=xe.call(this._weekdaysParse,o))?a:-1!==(a=xe.call(this._shortWeekdaysParse,o))?a:-1!==(a=xe.call(this._minWeekdaysParse,o))?a:null:"ddd"===t?-1!==(a=xe.call(this._shortWeekdaysParse,o))?a:-1!==(a=xe.call(this._weekdaysParse,o))?a:-1!==(a=xe.call(this._minWeekdaysParse,o))?a:null:-1!==(a=xe.call(this._minWeekdaysParse,o))?a:-1!==(a=xe.call(this._weekdaysParse,o))?a:-1!==(a=xe.call(this._shortWeekdaysParse,o))?a:null}.call(this,e,t,n);for(this._weekdaysParse||(this._weekdaysParse=[],this._minWeekdaysParse=[],this._shortWeekdaysParse=[],this._fullWeekdaysParse=[]),r=0;r<7;r++){if(a=_([2e3,1]).day(r),n&&!this._fullWeekdaysParse[r]&&(this._fullWeekdaysParse[r]=new RegExp("^"+this.weekdays(a,"").replace(".","\\.?")+"$","i"),this._shortWeekdaysParse[r]=new RegExp("^"+this.weekdaysShort(a,"").replace(".","\\.?")+"$","i"),this._minWeekdaysParse[r]=new RegExp("^"+this.weekdaysMin(a,"").replace(".","\\.?")+"$","i")),this._weekdaysParse[r]||(i="^"+this.weekdays(a,"")+"|^"+this.weekdaysShort(a,"")+"|^"+this.weekdaysMin(a,""),this._weekdaysParse[r]=new RegExp(i.replace(".",""),"i")),n&&"dddd"===t&&this._fullWeekdaysParse[r].test(e))return r;if(n&&"ddd"===t&&this._shortWeekdaysParse[r].test(e))return r;if(n&&"dd"===t&&this._minWeekdaysParse[r].test(e))return r;if(!n&&this._weekdaysParse[r].test(e))return r}},hn.weekdaysRegex=function(e){return this._weekdaysParseExact?(c(this,"_weekdaysRegex")||et.call(this),e?this._weekdaysStrictRegex:this._weekdaysRegex):(c(this,"_weekdaysRegex")||(this._weekdaysRegex=Qe),this._weekdaysStrictRegex&&e?this._weekdaysStrictRegex:this._weekdaysRegex)},hn.weekdaysShortRegex=function(e){return this._weekdaysParseExact?(c(this,"_weekdaysRegex")||et.call(this),e?this._weekdaysShortStrictRegex:this._weekdaysShortRegex):(c(this,"_weekdaysShortRegex")||(this._weekdaysShortRegex=Ze),this._weekdaysShortStrictRegex&&e?this._weekdaysShortStrictRegex:this._weekdaysShortRegex)},hn.weekdaysMinRegex=function(e){return this._weekdaysParseExact?(c(this,"_weekdaysRegex")||et.call(this),e?this._weekdaysMinStrictRegex:this._weekdaysMinRegex):(c(this,"_weekdaysMinRegex")||(this._weekdaysMinRegex=Xe),this._weekdaysMinStrictRegex&&e?this._weekdaysMinStrictRegex:this._weekdaysMinRegex)},hn.isPM=function(e){return"p"===(e+"").toLowerCase().charAt(0)},hn.meridiem=function(e,t,n){return e>11?n?"pm":"PM":n?"am":"AM"},ct("en",{dayOfMonthOrdinalParse:/\d{1,2}(th|st|nd|rd)/,ordinal:function(e){var t=e%10,n=1===w(e%100/10)?"th":1===t?"st":2===t?"nd":3===t?"rd":"th";return e+n}}),a.lang=T("moment.lang is deprecated. Use moment.locale instead.",ct),a.langData=T("moment.langData is deprecated. Use moment.localeData instead.",_t);var vn=Math.abs;function gn(e,t,n,r){var a=Gt(t,n);return e._milliseconds+=r*a._milliseconds,e._days+=r*a._days,e._months+=r*a._months,e._bubble()}function Ln(e){return e<0?Math.floor(e):Math.ceil(e)}function Yn(e){return 4800*e/146097}function wn(e){return 146097*e/4800}function bn(e){return function(){return this.as(e)}}var kn=bn("ms"),Tn=bn("s"),Dn=bn("m"),Sn=bn("h"),xn=bn("d"),jn=bn("w"),En=bn("M"),On=bn("y");function Pn(e){return function(){return this.isValid()?this._data[e]:NaN}}var Hn=Pn("milliseconds"),Cn=Pn("seconds"),An=Pn("minutes"),Fn=Pn("hours"),Rn=Pn("days"),Nn=Pn("months"),Wn=Pn("years"),In=Math.round,zn={ss:44,s:45,m:45,h:22,d:26,M:11},Un=Math.abs;function Jn(e){return(e>0)-(e<0)||+e}function Bn(){if(!this.isValid())return this.localeData().invalidDate();var e,t,n=Un(this._milliseconds)/1e3,r=Un(this._days),a=Un(this._months);e=Y(n/60),t=Y(e/60),n%=60,e%=60;var i=Y(a/12),o=a%=12,s=r,u=t,d=e,l=n?n.toFixed(3).replace(/\.?0+$/,""):"",c=this.asSeconds();if(!c)return"P0D";var f=c<0?"-":"",_=Jn(this._months)!==Jn(c)?"-":"",m=Jn(this._days)!==Jn(c)?"-":"",h=Jn(this._milliseconds)!==Jn(c)?"-":"";return f+"P"+(i?_+i+"Y":"")+(o?_+o+"M":"")+(s?m+s+"D":"")+(u||d||l?"T":"")+(u?h+u+"H":"")+(d?h+d+"M":"")+(l?h+l+"S":"")}var Vn=At.prototype;return Vn.isValid=function(){return this._isValid},Vn.abs=function(){var e=this._data;return this._milliseconds=vn(this._milliseconds),this._days=vn(this._days),this._months=vn(this._months),e.milliseconds=vn(e.milliseconds),e.seconds=vn(e.seconds),e.minutes=vn(e.minutes),e.hours=vn(e.hours),e.months=vn(e.months),e.years=vn(e.years),this},Vn.add=function(e,t){return gn(this,e,t,1)},Vn.subtract=function(e,t){return gn(this,e,t,-1)},Vn.as=function(e){if(!this.isValid())return NaN;var t,n,r=this._milliseconds;if("month"===(e=C(e))||"year"===e)return t=this._days+r/864e5,n=this._months+Yn(t),"month"===e?n:n/12;switch(t=this._days+Math.round(wn(this._months)),e){case"week":return t/7+r/6048e5;case"day":return t+r/864e5;case"hour":return 24*t+r/36e5;case"minute":return 1440*t+r/6e4;case"second":return 86400*t+r/1e3;case"millisecond":return Math.floor(864e5*t)+r;default:throw new Error("Unknown unit "+e)}},Vn.asMilliseconds=kn,Vn.asSeconds=Tn,Vn.asMinutes=Dn,Vn.asHours=Sn,Vn.asDays=xn,Vn.asWeeks=jn,Vn.asMonths=En,Vn.asYears=On,Vn.valueOf=function(){return this.isValid()?this._milliseconds+864e5*this._days+this._months%12*2592e6+31536e6*w(this._months/12):NaN},Vn._bubble=function(){var e,t,n,r,a,i=this._milliseconds,o=this._days,s=this._months,u=this._data;return i>=0&&o>=0&&s>=0||i<=0&&o<=0&&s<=0||(i+=864e5*Ln(wn(s)+o),o=0,s=0),u.milliseconds=i%1e3,e=Y(i/1e3),u.seconds=e%60,t=Y(e/60),u.minutes=t%60,n=Y(t/60),u.hours=n%24,o+=Y(n/24),a=Y(Yn(o)),s+=a,o-=Ln(wn(a)),r=Y(s/12),s%=12,u.days=o,u.months=s,u.years=r,this},Vn.clone=function(){return Gt(this)},Vn.get=function(e){return e=C(e),this.isValid()?this[e+"s"]():NaN},Vn.milliseconds=Hn,Vn.seconds=Cn,Vn.minutes=An,Vn.hours=Fn,Vn.days=Rn,Vn.weeks=function(){return Y(this.days()/7)},Vn.months=Nn,Vn.years=Wn,Vn.humanize=function(e){if(!this.isValid())return this.localeData().invalidDate();var t=this.localeData(),n=function(e,t,n){var r=Gt(e).abs(),a=In(r.as("s")),i=In(r.as("m")),o=In(r.as("h")),s=In(r.as("d")),u=In(r.as("M")),d=In(r.as("y")),l=a<=zn.ss&&["s",a]||a0,l[4]=n,function(e,t,n,r,a){return a.relativeTime(t||1,!!n,e,r)}.apply(null,l)}(this,!e,t);return e&&(n=t.pastFuture(+this,n)),t.postformat(n)},Vn.toISOString=Bn,Vn.toString=Bn,Vn.toJSON=Bn,Vn.locale=tn,Vn.localeData=rn,Vn.toIsoString=T("toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)",Bn),Vn.lang=nn,J("X",0,0,"unix"),J("x",0,0,"valueOf"),ce("x",oe),ce("X",/[+-]?\d+(\.\d{1,3})?/),he("X",function(e,t,n){n._d=new Date(1e3*parseFloat(e,10))}),he("x",function(e,t,n){n._d=new Date(w(e))}),a.version="2.22.2",function(e){t=e}(Et),a.fn=_n,a.min=function(){return Ht("isBefore",[].slice.call(arguments,0))},a.max=function(){return Ht("isAfter",[].slice.call(arguments,0))},a.now=function(){return Date.now?Date.now():+new Date},a.utc=_,a.unix=function(e){return Et(1e3*e)},a.months=function(e,t){return yn(e,t,"months")},a.isDate=d,a.locale=ct,a.invalid=p,a.duration=Gt,a.isMoment=L,a.weekdays=function(e,t,n){return Mn(e,t,n,"weekdays")},a.parseZone=function(){return Et.apply(null,arguments).parseZone()},a.localeData=_t,a.isDuration=Ft,a.monthsShort=function(e,t){return yn(e,t,"monthsShort")},a.weekdaysMin=function(e,t,n){return Mn(e,t,n,"weekdaysMin")},a.defineLocale=ft,a.updateLocale=function(e,t){if(null!=t){var n,r,a=ot;null!=(r=lt(e))&&(a=r._config),t=E(a,t),(n=new O(t)).parentLocale=st[e],st[e]=n,ct(e)}else null!=st[e]&&(null!=st[e].parentLocale?st[e]=st[e].parentLocale:null!=st[e]&&delete st[e]);return st[e]},a.locales=function(){return D(st)},a.weekdaysShort=function(e,t,n){return Mn(e,t,n,"weekdaysShort")},a.normalizeUnits=C,a.relativeTimeRounding=function(e){return void 0===e?In:"function"==typeof e&&(In=e,!0)},a.relativeTimeThreshold=function(e,t){return void 0!==zn[e]&&(void 0===t?zn[e]:(zn[e]=t,"s"===e&&(zn.ss=t-1),!0))},a.calendarFormat=function(e,t){var n=e.diff(t,"days",!0);return n<-6?"sameElse":n<-1?"lastWeek":n<0?"lastDay":n<1?"sameDay":n<2?"nextDay":n<7?"nextWeek":"sameElse"},a.prototype=_n,a.HTML5_FMT={DATETIME_LOCAL:"YYYY-MM-DDTHH:mm",DATETIME_LOCAL_SECONDS:"YYYY-MM-DDTHH:mm:ss",DATETIME_LOCAL_MS:"YYYY-MM-DDTHH:mm:ss.SSS",DATE:"YYYY-MM-DD",TIME:"HH:mm",TIME_SECONDS:"HH:mm:ss",TIME_MS:"HH:mm:ss.SSS",WEEK:"YYYY-[W]WW",MONTH:"YYYY-MM"},a}()}).call(this,n(281)(e))},function(e,t,n){e.exports=n(309)()},function(e,t,n){"use strict";e.exports=n(322)},function(e,t,n){var r=n(7);e.exports=function(e){if(!r(e))throw TypeError(e+" is not an object!");return e}},function(e,t){var n=e.exports="undefined"!=typeof window&&window.Math==Math?window:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")();"number"==typeof __g&&(__g=n)},function(e,t){e.exports=function(e){try{return!!e()}catch(e){return!0}}},function(e,t){e.exports=function(e){return"object"==typeof e?null!==e:"function"==typeof e}},function(e,t,n){var r=n(70)("wks"),a=n(47),i=n(5).Symbol,o="function"==typeof i;(e.exports=function(e){return r[e]||(r[e]=o&&i[e]||(o?i:a)("Symbol."+e))}).store=r},function(e,t,n){"use strict";e.exports=function(e,t,n,r,a,i,o,s){if(!e){var u;if(void 0===t)u=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var d=[n,r,a,i,o,s],l=0;(u=new Error(t.replace(/%s/g,function(){return d[l++]}))).name="Invariant Violation"}throw u.framesToPop=1,u}}},function(e,t,n){var r=n(31),a=Math.min;e.exports=function(e){return e>0?a(r(e),9007199254740991):0}},function(e,t,n){var r=n(4),a=n(276),i=n(33),o=Object.defineProperty;t.f=n(12)?Object.defineProperty:function(e,t,n){if(r(e),t=i(t,!0),r(n),a)try{return o(e,t,n)}catch(e){}if("get"in n||"set"in n)throw TypeError("Accessors not supported!");return"value"in n&&(e[t]=n.value),e}},function(e,t,n){e.exports=!n(6)(function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a})},function(e,t,n){"use strict";var r=function(){};e.exports=r},function(e,t,n){"use strict";e.exports=function(){}},function(e,t,n){var r=n(32);e.exports=function(e){return Object(r(e))}},function(e,t){e.exports=function(e){if("function"!=typeof e)throw TypeError(e+" is not a function!");return e}},function(e,t,n){var r=n(0),a=n(6),i=n(32),o=/"/g,s=function(e,t,n,r){var a=String(i(e)),s="<"+t;return""!==n&&(s+=" "+n+'="'+String(r).replace(o,""")+'"'),s+">"+a+""};e.exports=function(e,t){var n={};n[e]=t(s),r(r.P+r.F*a(function(){var t=""[e]('"');return t!==t.toLowerCase()||t.split('"').length>3}),"String",n)}},function(e,t,n){var r=n(5),a=n(19),i=n(24),o=n(47)("src"),s=Function.toString,u=(""+s).split("toString");n(28).inspectSource=function(e){return s.call(e)},(e.exports=function(e,t,n,s){var d="function"==typeof n;d&&(i(n,"name")||a(n,"name",t)),e[t]!==n&&(d&&(i(n,o)||a(n,o,e[t]?""+e[t]:u.join(String(t)))),e===r?e[t]=n:s?e[t]?e[t]=n:a(e,t,n):(delete e[t],a(e,t,n)))})(Function.prototype,"toString",function(){return"function"==typeof this&&this[o]||s.call(this)})},function(e,t,n){var r=n(11),a=n(48);e.exports=n(12)?function(e,t,n){return r.f(e,t,a(1,n))}:function(e,t,n){return e[t]=n,e}},function(e,t,n){"use strict";var r=n(235),a=n(299),i=Object.prototype.toString;function o(e){return"[object Array]"===i.call(e)}function s(e){return null!==e&&"object"==typeof e}function u(e){return"[object Function]"===i.call(e)}function d(e,t){if(null!==e&&void 0!==e)if("object"!=typeof e&&(e=[e]),o(e))for(var n=0,r=e.length;nL;L++)if((f||L in M)&&(p=v(h=M[L],L,y),e))if(n)Y[L]=p;else if(p)switch(e){case 3:return!0;case 5:return h;case 6:return L;case 2:Y.push(h)}else if(l)return!1;return c?-1:d||l?l:Y}}},function(e,t,n){var r=n(0),a=n(28),i=n(6);e.exports=function(e,t){var n=(a.Object||{})[e]||Object[e],o={};o[e]=t(n),r(r.S+r.F*i(function(){n(1)}),"Object",o)}},function(e,t){var n=Math.ceil,r=Math.floor;e.exports=function(e){return isNaN(e=+e)?0:(e>0?r:n)(e)}},function(e,t){e.exports=function(e){if(void 0==e)throw TypeError("Can't call method on "+e);return e}},function(e,t,n){var r=n(7);e.exports=function(e,t){if(!r(e))return e;var n,a;if(t&&"function"==typeof(n=e.toString)&&!r(a=n.call(e)))return a;if("function"==typeof(n=e.valueOf)&&!r(a=n.call(e)))return a;if(!t&&"function"==typeof(n=e.toString)&&!r(a=n.call(e)))return a;throw TypeError("Can't convert object to primitive value")}},function(e,t,n){var r=n(255),a=n(0),i=n(70)("metadata"),o=i.store||(i.store=new(n(252))),s=function(e,t,n){var a=o.get(e);if(!a){if(!n)return;o.set(e,a=new r)}var i=a.get(t);if(!i){if(!n)return;a.set(t,i=new r)}return i};e.exports={store:o,map:s,has:function(e,t,n){var r=s(t,n,!1);return void 0!==r&&r.has(e)},get:function(e,t,n){var r=s(t,n,!1);return void 0===r?void 0:r.get(e)},set:function(e,t,n,r){s(n,r,!0).set(e,t)},keys:function(e,t){var n=s(e,t,!1),r=[];return n&&n.forEach(function(e,t){r.push(t)}),r},key:function(e){return void 0===e||"symbol"==typeof e?e:String(e)},exp:function(e){a(a.S,"Reflect",e)}}},function(e,t,n){"use strict";if(n(12)){var r=n(37),a=n(5),i=n(6),o=n(0),s=n(59),u=n(76),d=n(27),l=n(41),c=n(48),f=n(19),_=n(39),m=n(31),h=n(10),p=n(250),y=n(45),M=n(33),v=n(24),g=n(53),L=n(7),Y=n(15),w=n(85),b=n(44),k=n(21),T=n(43).f,D=n(83),S=n(47),x=n(8),j=n(29),E=n(69),O=n(62),P=n(80),H=n(50),C=n(65),A=n(42),F=n(81),R=n(260),N=n(11),W=n(22),I=N.f,z=W.f,U=a.RangeError,J=a.TypeError,B=a.Uint8Array,V=Array.prototype,G=u.ArrayBuffer,q=u.DataView,$=j(0),K=j(2),Q=j(3),Z=j(4),X=j(5),ee=j(6),te=E(!0),ne=E(!1),re=P.values,ae=P.keys,ie=P.entries,oe=V.lastIndexOf,se=V.reduce,ue=V.reduceRight,de=V.join,le=V.sort,ce=V.slice,fe=V.toString,_e=V.toLocaleString,me=x("iterator"),he=x("toStringTag"),pe=S("typed_constructor"),ye=S("def_constructor"),Me=s.CONSTR,ve=s.TYPED,ge=s.VIEW,Le=j(1,function(e,t){return Te(O(e,e[ye]),t)}),Ye=i(function(){return 1===new B(new Uint16Array([1]).buffer)[0]}),we=!!B&&!!B.prototype.set&&i(function(){new B(1).set({})}),be=function(e,t){var n=m(e);if(n<0||n%t)throw U("Wrong offset!");return n},ke=function(e){if(L(e)&&ve in e)return e;throw J(e+" is not a typed array!")},Te=function(e,t){if(!(L(e)&&pe in e))throw J("It is not a typed array constructor!");return new e(t)},De=function(e,t){return Se(O(e,e[ye]),t)},Se=function(e,t){for(var n=0,r=t.length,a=Te(e,r);r>n;)a[n]=t[n++];return a},xe=function(e,t,n){I(e,t,{get:function(){return this._d[n]}})},je=function(e){var t,n,r,a,i,o,s=Y(e),u=arguments.length,l=u>1?arguments[1]:void 0,c=void 0!==l,f=D(s);if(void 0!=f&&!w(f)){for(o=f.call(s),r=[],t=0;!(i=o.next()).done;t++)r.push(i.value);s=r}for(c&&u>2&&(l=d(l,arguments[2],2)),t=0,n=h(s.length),a=Te(this,n);n>t;t++)a[t]=c?l(s[t],t):s[t];return a},Ee=function(){for(var e=0,t=arguments.length,n=Te(this,t);t>e;)n[e]=arguments[e++];return n},Oe=!!B&&i(function(){_e.call(new B(1))}),Pe=function(){return _e.apply(Oe?ce.call(ke(this)):ke(this),arguments)},He={copyWithin:function(e,t){return R.call(ke(this),e,t,arguments.length>2?arguments[2]:void 0)},every:function(e){return Z(ke(this),e,arguments.length>1?arguments[1]:void 0)},fill:function(e){return F.apply(ke(this),arguments)},filter:function(e){return De(this,K(ke(this),e,arguments.length>1?arguments[1]:void 0))},find:function(e){return X(ke(this),e,arguments.length>1?arguments[1]:void 0)},findIndex:function(e){return ee(ke(this),e,arguments.length>1?arguments[1]:void 0)},forEach:function(e){$(ke(this),e,arguments.length>1?arguments[1]:void 0)},indexOf:function(e){return ne(ke(this),e,arguments.length>1?arguments[1]:void 0)},includes:function(e){return te(ke(this),e,arguments.length>1?arguments[1]:void 0)},join:function(e){return de.apply(ke(this),arguments)},lastIndexOf:function(e){return oe.apply(ke(this),arguments)},map:function(e){return Le(ke(this),e,arguments.length>1?arguments[1]:void 0)},reduce:function(e){return se.apply(ke(this),arguments)},reduceRight:function(e){return ue.apply(ke(this),arguments)},reverse:function(){for(var e,t=ke(this).length,n=Math.floor(t/2),r=0;r1?arguments[1]:void 0)},sort:function(e){return le.call(ke(this),e)},subarray:function(e,t){var n=ke(this),r=n.length,a=y(e,r);return new(O(n,n[ye]))(n.buffer,n.byteOffset+a*n.BYTES_PER_ELEMENT,h((void 0===t?r:y(t,r))-a))}},Ce=function(e,t){return De(this,ce.call(ke(this),e,t))},Ae=function(e){ke(this);var t=be(arguments[1],1),n=this.length,r=Y(e),a=h(r.length),i=0;if(a+t>n)throw U("Wrong length!");for(;i255?255:255&r),a.v[_](n*t+a.o,r,Ye)}(this,n,e)},enumerable:!0})};v?(m=n(function(e,n,r,a){l(e,m,d,"_d");var i,o,s,u,c=0,_=0;if(L(n)){if(!(n instanceof G||"ArrayBuffer"==(u=g(n))||"SharedArrayBuffer"==u))return ve in n?Se(m,n):je.call(m,n);i=n,_=be(r,t);var y=n.byteLength;if(void 0===a){if(y%t)throw U("Wrong length!");if((o=y-_)<0)throw U("Wrong length!")}else if((o=h(a)*t)+_>y)throw U("Wrong length!");s=o/t}else s=p(n),i=new G(o=s*t);for(f(e,"_d",{b:i,o:_,l:o,e:s,v:new q(i)});cv;v++)if((p=t?M(o(m=e[v])[0],m[1]):M(e[v]))===d||p===l)return p}else for(h=y.call(e);!(m=h.next()).done;)if((p=a(h,M,m.value,t))===d||p===l)return p}).BREAK=d,t.RETURN=l},function(e,t){e.exports=function(e,t,n,r){if(!(e instanceof t)||void 0!==r&&r in e)throw TypeError(n+": incorrect invocation!");return e}},function(e,t,n){"use strict";var r=n(5),a=n(11),i=n(12),o=n(8)("species");e.exports=function(e){var t=r[e];i&&t&&!t[o]&&a.f(t,o,{configurable:!0,get:function(){return this}})}},function(e,t,n){var r=n(274),a=n(98).concat("length","prototype");t.f=Object.getOwnPropertyNames||function(e){return r(e,a)}},function(e,t,n){var r=n(4),a=n(273),i=n(98),o=n(99)("IE_PROTO"),s=function(){},u=function(){var e,t=n(101)("iframe"),r=i.length;for(t.style.display="none",n(97).appendChild(t),t.src="javascript:",(e=t.contentWindow.document).open(),e.write(" + + + + \ No newline at end of file diff --git a/client/resources/scss/style.scss b/client/resources/scss/style.scss new file mode 100644 index 0000000..06930d7 --- /dev/null +++ b/client/resources/scss/style.scss @@ -0,0 +1,9 @@ +@import url('https://fonts.googleapis.com/css?family=Nunito|Poppins:500|Open+Sans'); +@import "~bootstrap/scss/bootstrap"; + +body, html { + height: 100%; + background-color: rgba(0,0,0,.018); + color: rgba(0,0,0,.75); + font-family: 'Nunito'; +} \ No newline at end of file diff --git a/client/src/components/App/index.jsx b/client/src/components/App/index.jsx new file mode 100644 index 0000000..5e0d47d --- /dev/null +++ b/client/src/components/App/index.jsx @@ -0,0 +1,14 @@ +import React from 'react'; +import { withRouter, Switch, Route } from 'react-router-dom'; + +import { Home } from '../../components'; + +const App = (props) => { + return ( + + + + ) +} + +export default withRouter(App); diff --git a/client/src/components/Article/Form/index.jsx b/client/src/components/Article/Form/index.jsx new file mode 100644 index 0000000..9f9be85 --- /dev/null +++ b/client/src/components/Article/Form/index.jsx @@ -0,0 +1,97 @@ +import axios from 'axios'; +import React from 'react'; +import { connect } from 'react-redux'; + +class Form extends React.Component { + constructor(props) { + super(props); + + this.state = { + title: '', + body: '', + author: '', + } + + this.handleChangeField = this.handleChangeField.bind(this); + this.handleSubmit = this.handleSubmit.bind(this); + } + + componentWillReceiveProps(nextProps) { + if(nextProps.articleToEdit) { + this.setState({ + title: nextProps.articleToEdit.title, + body: nextProps.articleToEdit.body, + author: nextProps.articleToEdit.author, + }); + } + } + + handleSubmit(){ + const { onSubmit, articleToEdit, onEdit } = this.props; + const { title, body, author } = this.state; + + if(!articleToEdit) { + return axios.post('http://localhost:8000/api/articles', { + title, + body, + author, + }) + .then((res) => onSubmit(res.data)) + .then(() => this.setState({ title: '', body: '', author: '' })); + } else { + return axios.patch(`http://localhost:8000/api/articles/${articleToEdit._id}`, { + title, + body, + author, + }) + .then((res) => onEdit(res.data)) + .then(() => this.setState({ title: '', body: '', author: '' })); + } + } + + handleChangeField(key, event) { + this.setState({ + [key]: event.target.value, + }); + } + + render() { + const { articleToEdit } = this.props; + const { title, body, author } = this.state; + + return ( +
+ this.handleChangeField('title', ev)} + value={title} + className="form-control my-3" + placeholder="Tytuł Artykułu..." + /> + + this.handleChangeField('author', ev)} + value={author} + className="form-control my-3" + placeholder="Autor artykułu..." + /> + +
+ ) + } +} + +const mapDispatchToProps = dispatch => ({ + onSubmit: data => dispatch({ type: 'SUBMIT_ARTICLE', data }), + onEdit: data => dispatch({ type: 'EDIT_ARTICLE', data }), +}); + +const mapStateToProps = state => ({ + articleToEdit: state.home.articleToEdit, +}); + +export default connect(mapStateToProps, mapDispatchToProps)(Form); \ No newline at end of file diff --git a/client/src/components/Article/index.js b/client/src/components/Article/index.js new file mode 100644 index 0000000..cf70147 --- /dev/null +++ b/client/src/components/Article/index.js @@ -0,0 +1 @@ +export { default as Form } from './Form'; \ No newline at end of file diff --git a/client/src/components/Home/index.jsx b/client/src/components/Home/index.jsx new file mode 100644 index 0000000..aee30e2 --- /dev/null +++ b/client/src/components/Home/index.jsx @@ -0,0 +1,89 @@ +import React from 'react'; +import axios from 'axios'; +import moment from 'moment'; +import { connect } from 'react-redux'; + +import { Form } from '../../components/Article'; + +class Home extends React.Component { + constructor(props) { + super(props); + + this.handleDelete = this.handleDelete.bind(this); + this.handleEdit = this.handleEdit.bind(this); + } + + componentDidMount() { + const { onLoad } = this.props; + + axios('http://localhost:8000/api/articles') + .then((res) => onLoad(res.data)); + } + + handleDelete(id) { + const { onDelete } = this.props; + + return axios.delete(`http://localhost:8000/api/articles/${id}`) + .then(() => onDelete(id)); + } + + handleEdit(article) { + const { setEdit } = this.props; + + setEdit(article); + } + + render() { + const { articles } = this.props; + + return ( +
+
+
+

MałyBlog

+
+
+
+
+
+ {articles.map((article) => { + return ( +
+
+ {article.title} +
+
+ {article.body} +

{article.author} {moment(new Date(article.createdAt)).fromNow()}

+
+
+
+ + +
+
+
+ ) + })} +
+
+
+ ); + } +} + +const mapStateToProps = state => ({ + articles: state.home.articles, +}); + +const mapDispatchToProps = dispatch => ({ + onLoad: data => dispatch({ type: 'HOME_PAGE_LOADED', data }), + onDelete: id => dispatch({ type: 'DELETE_ARTICLE', id }), + setEdit: article => dispatch({ type: 'SET_EDIT', article }), +}); + +export default connect(mapStateToProps, mapDispatchToProps)(Home); \ No newline at end of file diff --git a/client/src/components/index.js b/client/src/components/index.js new file mode 100644 index 0000000..3d0ab06 --- /dev/null +++ b/client/src/components/index.js @@ -0,0 +1,3 @@ +export { default as App } from './App'; +export { default as Home } from './Home'; +export { default as Article } from './Article'; \ No newline at end of file diff --git a/client/src/index.js b/client/src/index.js new file mode 100644 index 0000000..a31c374 --- /dev/null +++ b/client/src/index.js @@ -0,0 +1,22 @@ +import React from 'react'; +import createHistory from 'history/createBrowserHistory'; +import ReactDOM from 'react-dom'; +import { Provider } from 'react-redux'; +import { Route, Switch, Router } from 'react-router-dom'; + +import store from './store'; +import { App } from './components'; + +import '../resources/scss/style.scss'; + + +ReactDOM.render( + + + + + + + , + document.getElementById('root'), +); \ No newline at end of file diff --git a/client/src/reducers/home.js b/client/src/reducers/home.js new file mode 100644 index 0000000..3848c0d --- /dev/null +++ b/client/src/reducers/home.js @@ -0,0 +1,39 @@ +export default (state={articles: []}, action) => { + switch(action.type) { + case 'HOME_PAGE_LOADED': + return { + ...state, + articles: action.data.articles, + }; + case 'SUBMIT_ARTICLE': + return { + ...state, + articles: ([action.data.article]).concat(state.articles), + }; + case 'DELETE_ARTICLE': + return { + ...state, + articles: state.articles.filter((article) => article._id !== action.id), + }; + case 'SET_EDIT': + return { + ...state, + articleToEdit: action.article, + }; + case 'EDIT_ARTICLE': + return { + ...state, + articles: state.articles.map((article) => { + if(article._id === action.data.article._id) { + return { + ...action.data.article, + } + } + return article; + }), + articleToEdit: undefined, + } + default: + return state; + } +}; \ No newline at end of file diff --git a/client/src/reducers/index.js b/client/src/reducers/index.js new file mode 100644 index 0000000..6058b13 --- /dev/null +++ b/client/src/reducers/index.js @@ -0,0 +1 @@ +export { default as home } from './home'; \ No newline at end of file diff --git a/client/src/store.js b/client/src/store.js new file mode 100644 index 0000000..b139db5 --- /dev/null +++ b/client/src/store.js @@ -0,0 +1,11 @@ +import { createStore, combineReducers } from 'redux'; + +import { home } from './reducers'; + +const reducers = combineReducers({ + home, +}); + +const store = createStore(reducers); + +export default store; \ No newline at end of file diff --git a/client/webpack.config.js b/client/webpack.config.js new file mode 100644 index 0000000..842b947 --- /dev/null +++ b/client/webpack.config.js @@ -0,0 +1,79 @@ +const HtmlWebpackPlugin = require('html-webpack-plugin'); +const ExtractTextPlugin = require('extract-text-webpack-plugin'); + +module.exports = { + entry: [ + 'babel-polyfill', + './src/index.js', + ], + + output: { + publicPath: '/', + filename: './main.js', + }, + + resolve: { + extensions: ['.js', '.jsx'], + }, + + module: { + rules: [ + { + test: /\.(js|jsx)$/, + exclude: /node_modules/, + use: ['babel-loader'], + }, + + { + test: /\.(jpe?g|png|gif|svg)$/i, + use: { + loader: 'file-loader', + options: { + name: 'public/img/[name].[ext]', + outputPath: 'dist/img/', + }, + }, + }, + + { + test: /\.scss$/, + use: ExtractTextPlugin.extract({ + fallback: 'style-loader', + use: [{ loader: 'css-loader', options: { minimize: true } }, 'sass-loader'], + }), + }, + { + test: /\.html$/, + use: { + loader: 'html-loader', + options: { + minimize: true, + }, + }, + }, + { + test: /\.(otf|ttf|eot|woff|woff2)$/, + loader: 'file-loader', + options: { + name: 'public/fonts/[name].[ext]', + outputPath: 'dist/fonts', + }, + }, + ], + }, + + plugins: [ + new ExtractTextPlugin({ filename: 'style.css' }), + new HtmlWebpackPlugin({ + template: './resources/index.html', + filename: './index.html', + hash: true, + }), + ], + + devServer: { + historyApiFallback: true, + publicPath: '/', + contentBase: './dist', + }, +}; \ No newline at end of file diff --git a/models/Articles.js b/models/Articles.js new file mode 100644 index 0000000..e4b2d29 --- /dev/null +++ b/models/Articles.js @@ -0,0 +1,23 @@ +const mongoose = require('mongoose'); + +const { Schema } = mongoose; + + +const ArticlesSchema = new Schema({ + title: String, + body: String, + author: String, +}, { timestamps: true }); + +ArticlesSchema.methods.toJSON = function() { + return { + _id: this._id, + title: this.title, + body: this.body, + author: this.author, + createdAt: this.createdAt, + updatedAt: this.updatedAt, + }; +}; + +mongoose.model('Articles', ArticlesSchema); \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..ee50392 --- /dev/null +++ b/package.json @@ -0,0 +1,27 @@ +{ + "dependencies": { + "body-parser": "^1.18.3", + "cors": "^2.8.4", + "errorhandler": "^1.5.0", + "eslint": "^5.0.1", + "express": "^4.16.3", + "express-session": "^1.15.6", + "mongoose": "^5.2.1", + "morgan": "^1.9.0", + "path": "^0.12.7" + }, + "name": "blogrn", + "version": "1.0.0", + "description": "for learning purpose", + "main": "index.js", + "devDependencies": {}, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [ + "React", + "Node" + ], + "author": "Ludwik Kowalewski", + "license": "MIT" +} diff --git a/routes/api/articles.js b/routes/api/articles.js new file mode 100644 index 0000000..e3a84f7 --- /dev/null +++ b/routes/api/articles.js @@ -0,0 +1,88 @@ +const mongoose = require('mongoose'); +const router = require('express').Router(); +const Articles = mongoose.model('Articles'); + +router.post('/', (req, res, next) => { + const { body } = req; + + if(!body.title) { + return res.status(422).json({ + errors: { + title: 'is required', + }, + }); + } + + if(!body.author) { + return res.status(422).json({ + errors: { + author: 'is required', + }, + }); + } + + if(!body.body) { + return res.status(422).json({ + errors: { + body: 'is required', + }, + }); + } + + const finalArticle = new Articles(body); + return finalArticle.save() + .then(() => res.json({ article: finalArticle.toJSON() })) + .catch(next); +}); + +router.get('/', (req, res, next) => { + return Articles.find() + .sort({ createdAt: 'descending' }) + .then((articles) => res.json({ articles: articles.map(article => article.toJSON()) })) + .catch(next); +}); + +router.param('id', (req, res, next, id) => { + return Articles.findById(id, (err, article) => { + if(err) { + return res.sendStatus(404); + } else if(article) { + req.article = article; + return next(); + } + }).catch(next); +}); + +router.get('/:id', (req, res, next) => { + return res.json({ + article: req.article.toJSON(), + }); +}); + +router.patch('/:id', (req, res, next) => { + const { body } = req; + + if(typeof body.title !== 'undefined') { + req.article.title = body.title; + } + + if(typeof body.author !== 'undefined') { + req.article.author = body.author; + } + + if(typeof body.body !== 'undefined') { + req.article.body = body.body; + } + + return req.article.save() + .then(() => res.json({ article: req.article.toJSON() })) + .catch(next); +}); + +router.delete('/:id', (req, res, next) => { + return Articles.findByIdAndRemove(req.article._id) + .then(() => res.sendStatus(200)) + .catch(next); +}); + +module.exports = router; \ No newline at end of file diff --git a/routes/api/index.js b/routes/api/index.js new file mode 100644 index 0000000..6107026 --- /dev/null +++ b/routes/api/index.js @@ -0,0 +1,5 @@ +const router = require('express').Router(); + +router.use('/articles', require('./articles')); + +module.exports = router; \ No newline at end of file diff --git a/routes/index.js b/routes/index.js new file mode 100644 index 0000000..a01866a --- /dev/null +++ b/routes/index.js @@ -0,0 +1,6 @@ +const express = require('express'); +const router = express.Router(); + +router.use('/api', require('./api')); + +module.exports = router; \ No newline at end of file