From 57454962f11af3353eedccd5f67995284a7c003a Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Mon, 14 Oct 2019 16:51:31 +0300 Subject: [PATCH 001/101] core/schedule moved to server/schedule --- pages/api/schedule.js | 2 +- src/{core => server}/schedule.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename src/{core => server}/schedule.js (98%) diff --git a/pages/api/schedule.js b/pages/api/schedule.js index 00b0a11c..3bad23c4 100644 --- a/pages/api/schedule.js +++ b/pages/api/schedule.js @@ -1,5 +1,5 @@ import { connect } from '../../src/core/db' -import { findSchedule } from '../../src/core/schedule' +import { findSchedule } from '../../src/server/schedule' import { withMiddleware } from '../../src/middlewares/withMiddleware' export default withMiddleware(async (req, res) => { diff --git a/src/core/schedule.js b/src/server/schedule.js similarity index 98% rename from src/core/schedule.js rename to src/server/schedule.js index 3e89b0dd..6bd992f5 100644 --- a/src/core/schedule.js +++ b/src/server/schedule.js @@ -1,6 +1,6 @@ import {c} from '../core/db' import {createMap} from '../utils/common' -import {getCollective} from './collective' +import {getCollective} from '../core/collective' import {scheduleDate, getPeriod as schedulePeriod, getPeriodString} from '../models/schedule' import {getCourse} from '../models/course' From 4fc424b145a4932fc30ef771cad5a78dbbec9114 Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Mon, 14 Oct 2019 17:14:45 +0300 Subject: [PATCH 002/101] core/Teacher format --- src/core/Teacher.js | 86 ++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/src/core/Teacher.js b/src/core/Teacher.js index 08883ba1..db6c66a3 100644 --- a/src/core/Teacher.js +++ b/src/core/Teacher.js @@ -1,38 +1,38 @@ const Data = require('./Data') const Image = require('./Image') -const {find, findOne} = require('../lib/store') +const { find, findOne } = require('../lib/store') const store = () => Data.getStore(Teacher) class Teacher { - static async find(query, options = {}) { - const items = await find(store(), query, options) + static async find(query, options = {}) { + const items = await find(store(), query, options) - return Promise.all(items.map(processProfile)) - } + return Promise.all(items.map(processProfile)) + } - static async findById(id) { - const data = await findOne(store(), {id}) - if (!data) return null + static async findById(id) { + const data = await findOne(store(), { id }) + if (!data) return null - return processProfile(data) - } + return processProfile(data) + } - constructor(data) { - this.id = data.id - this.post = data.post - this.file = data.file - this.edu = data.edu - this.picture = data.picture - this.preview = data.preview - this.diploma = data.diploma - this.position = data.position - this.name = data.name - this.status = data.status - this.hash = data.hash + constructor(data) { + this.id = data.id + this.post = data.post + this.file = data.file + this.edu = data.edu + this.picture = data.picture + this.preview = data.preview + this.diploma = data.diploma + this.position = data.position + this.name = data.name + this.status = data.status + this.hash = data.hash - this.url = `/teacher/${this.id}` - } + this.url = `/teacher/${this.id}` + } /** * @@ -40,12 +40,12 @@ class Teacher { * * @returns {string} */ - shortName() { - const f = i => i.replace(/^(.).+/, '$1') - const [first, middle, last] = this.splitName() + shortName() { + const f = i => i.replace(/^(.).+/, '$1') + const [first, middle, last] = this.splitName() - return `${f(first)}. ${f(middle)}. ${last}` - } + return `${f(first)}. ${f(middle)}. ${last}` + } /** * @@ -53,24 +53,24 @@ class Teacher { * * @returns {Array|{index: number, input: string}} */ - splitName() { - const name = this.name - const m = /(.+)\s(.+)\s(.+)/.exec(name) - return m.slice(1) - } + splitName() { + const name = this.name + const m = /(.+)\s(.+)\s(.+)/.exec(name) + return m.slice(1) + } } const processProfile = async profile => { - const imageId = profile.picture - const previewId = profile.preview - const picture = await Image.findById(imageId) - const preview = await Image.findById(previewId) + const imageId = profile.picture + const previewId = profile.preview + const picture = await Image.findById(imageId) + const preview = await Image.findById(previewId) - return new Teacher({ - ...profile, - picture, - preview, - }) + return new Teacher({ + ...profile, + picture, + preview, + }) } module.exports = Teacher From 285475762eb2b77e459bbce77676af1c048b6118 Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Mon, 14 Oct 2019 17:23:16 +0300 Subject: [PATCH 003/101] ArticleCardList style moved to styled jsx --- src/components/ArticleCardList.jsx | 12 ++++++++++-- src/style/components/ArticleCardList.scss | 5 ----- src/style/style.scss | 1 - 3 files changed, 10 insertions(+), 8 deletions(-) delete mode 100644 src/style/components/ArticleCardList.scss diff --git a/src/components/ArticleCardList.jsx b/src/components/ArticleCardList.jsx index bb4ca866..c9f5bf24 100644 --- a/src/components/ArticleCardList.jsx +++ b/src/components/ArticleCardList.jsx @@ -3,12 +3,20 @@ import Paginator from './Paginator' import { ArticleCard } from './ArticleCard' export const ArticleCardList = ({ articles, nextPage, prevPage }) => ( -
+
+ + {!prevPage ? null : ( )} -
+
{articles.map((article, i) => ( Date: Mon, 14 Oct 2019 17:23:27 +0300 Subject: [PATCH 004/101] server.js EOF --- src/server.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/server.js b/src/server.js index 890b1e4c..407f1411 100644 --- a/src/server.js +++ b/src/server.js @@ -43,4 +43,3 @@ app.prepare().then(async () => { console.log(`> Ready on http://localhost:${port}`) }) }) - From c77dc74965b49a099262094908090b9b87367c92 Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Mon, 14 Oct 2019 17:44:03 +0300 Subject: [PATCH 005/101] rm lib/component --- src/lib/component.js | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 src/lib/component.js diff --git a/src/lib/component.js b/src/lib/component.js deleted file mode 100644 index 6da5df89..00000000 --- a/src/lib/component.js +++ /dev/null @@ -1,15 +0,0 @@ -import React from 'react' -import {renderToStaticMarkup} from 'react-dom/server' - -import App from '../components/App' - -function renderApp({component, ...options}) { - const app = ( - - {component} - - ) - return renderToStaticMarkup(app) -} - -exports.renderApp = renderApp From 0c41bffb7582e60073548fd2dff490702915695c Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Mon, 14 Oct 2019 17:44:29 +0300 Subject: [PATCH 006/101] add to middlewares withCollection (unstable) --- src/middlewares/withCollection.js | 21 +++++++++++++++++++++ src/middlewares/withMiddleware.js | 6 +++--- 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 src/middlewares/withCollection.js diff --git a/src/middlewares/withCollection.js b/src/middlewares/withCollection.js new file mode 100644 index 00000000..a877152d --- /dev/null +++ b/src/middlewares/withCollection.js @@ -0,0 +1,21 @@ +// import { MongoClient } from 'mongodb'; +// const { connect, collection } = require('../../src/core/db') +// import {collection, connect} from '../core/db' +const core = require('../core/db') + +// const client = new MongoClient(process.env.MONGODB_URI, { useNewUrlParser: true }); + +export const withCollection = handler => async (req, res) => { + await core.connect() + + req.collection = core.collection + + // if (!client.isConnected()) { + // return client.connect().then(() => { + // req.db = client.db('nextjsmongodbapp'); + // return handler(req, res); + // }); + // } + // req.db = client.db('nextjsmongodbapp'); + return handler(req, res) +} diff --git a/src/middlewares/withMiddleware.js b/src/middlewares/withMiddleware.js index 925e3849..ce50ce6a 100644 --- a/src/middlewares/withMiddleware.js +++ b/src/middlewares/withMiddleware.js @@ -1,3 +1,3 @@ -export const withMiddleware = handler => async (req, res) => { - return handler(req, res); -}; +import { withCollection } from './withCollection' + +export const withMiddleware = handler => withCollection(handler) From ac02ab3f1ad19b16c91276ff3e6b197ba4165d2b Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Mon, 14 Oct 2019 17:45:24 +0300 Subject: [PATCH 007/101] rm unused TeacherProfile --- src/components/TeacherProfile.js | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 src/components/TeacherProfile.js diff --git a/src/components/TeacherProfile.js b/src/components/TeacherProfile.js deleted file mode 100644 index 41e6304b..00000000 --- a/src/components/TeacherProfile.js +++ /dev/null @@ -1,29 +0,0 @@ -const React = require('react') -const Share = require('./Share') -const getHtml = require('../lib/component').getHtml - -const Head = ({url, children}) => ( - !url - ?

{children}

- :

{children}

-) - -const TeacherProfile = ({picture, name, url, profile, biography, shareable}) => ( -
-
- -
- -
-
- {getHtml(biography)} -
-
- - {!shareable ? null : ( - - )} -
-) - -module.exports = TeacherProfile From c1d8ab3b97018319bafa7f32d8f16de22dacffe6 Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Mon, 14 Oct 2019 17:45:52 +0300 Subject: [PATCH 008/101] Schedule component updated imports --- src/components/Schedule.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Schedule.js b/src/components/Schedule.js index 17aaadd9..90a92e1e 100644 --- a/src/components/Schedule.js +++ b/src/components/Schedule.js @@ -1,4 +1,4 @@ -const React = require('react') +import React from 'react' const {getDates} = require('../utils/date') const {shortName} = require('../models/collective') @@ -120,4 +120,4 @@ const TimeRange = ({range}) => (

{(range || []).join(' — ')}

) -module.exports = Schedule +export default Schedule From 1f2b61cc29f210a873e6a3471fbd2998bdc8573a Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Mon, 14 Oct 2019 17:47:02 +0300 Subject: [PATCH 009/101] schedule/collective files move to server --- pages/api/schedule.js | 4 +--- src/components/ScheduleList.js | 2 +- src/core/collective.js | 17 ----------------- src/models/schedule.js | 4 +--- src/server/collective.js | 18 ++++++++++++++++++ src/server/schedule.js | 19 ++++++++++--------- 6 files changed, 31 insertions(+), 33 deletions(-) delete mode 100644 src/core/collective.js create mode 100644 src/server/collective.js diff --git a/pages/api/schedule.js b/pages/api/schedule.js index 3bad23c4..170648ad 100644 --- a/pages/api/schedule.js +++ b/pages/api/schedule.js @@ -1,13 +1,11 @@ -import { connect } from '../../src/core/db' import { findSchedule } from '../../src/server/schedule' import { withMiddleware } from '../../src/middlewares/withMiddleware' export default withMiddleware(async (req, res) => { - await connect() const period = req.query.period const semester = req.query.semester - const data = await findSchedule(period, semester) + const data = await findSchedule(req.collection, period, semester) if (data) { res.json(data) diff --git a/src/components/ScheduleList.js b/src/components/ScheduleList.js index 36fc648a..36f953e3 100644 --- a/src/components/ScheduleList.js +++ b/src/components/ScheduleList.js @@ -1,5 +1,5 @@ const React = require('react') -const text = require('../core/schedule').text +const text = require('../server/schedule').text const ScheduleList = ({schedules}) => (
diff --git a/src/core/collective.js b/src/core/collective.js deleted file mode 100644 index e802cc6c..00000000 --- a/src/core/collective.js +++ /dev/null @@ -1,17 +0,0 @@ -import {c} from '../core/db'; - -export async function getCollective(query={}) { - return await c('collective') - .find(query) - .toArray(); -} - -/** - * Find a person by it's id - * - * @param id - * @returns {Promise|*} - */ -export async function getPerson(id){ - return await c('collective').findOne({id: id}); -} diff --git a/src/models/schedule.js b/src/models/schedule.js index 76435652..7acdde25 100644 --- a/src/models/schedule.js +++ b/src/models/schedule.js @@ -38,9 +38,7 @@ export function getPeriod(i){ * @param i * @returns {*} */ -function getPeriodString(i) { +export function getPeriodString(i) { return getPeriod(i) .join('-') } - -exports.getPeriodString = getPeriodString diff --git a/src/server/collective.js b/src/server/collective.js new file mode 100644 index 00000000..93c48d6e --- /dev/null +++ b/src/server/collective.js @@ -0,0 +1,18 @@ +const { collection } = require('../core/db') +// import { collection } from '../core/db' + +export async function getCollective(query = {}) { + return await collection('collective') + .find(query) + .toArray(); +} + +/** + * Find a person by it's id + * + * @param id + * @returns {Promise|*} + */ +export async function getPerson(id) { + return await collection('collective').findOne({ id: id }); +} diff --git a/src/server/schedule.js b/src/server/schedule.js index 6bd992f5..981acb5e 100644 --- a/src/server/schedule.js +++ b/src/server/schedule.js @@ -1,6 +1,7 @@ -import {c} from '../core/db' +// import {collection} from '../core/db' +// const {collection} = require('../core/db') import {createMap} from '../utils/common' -import {getCollective} from '../core/collective' +import {getCollective} from './collective' import {scheduleDate, getPeriod as schedulePeriod, getPeriodString} from '../models/schedule' import {getCourse} from '../models/course' @@ -10,8 +11,8 @@ const sortBy = require('../lib/sort').sortBy const SCHEDULES = 'schedules' -async function findSchedule(period, semester) { - const schedule = await c(SCHEDULES).findOne({ +export async function findSchedule(collection, period, semester) { + const schedule = await collection(SCHEDULES).findOne({ $or: [ {period: period}, {period: schedulePeriod(period)} @@ -23,7 +24,7 @@ async function findSchedule(period, semester) { } async function findAllScheduleParams() { - const schedules = await c(SCHEDULES) + const schedules = await collection(SCHEDULES) .find({}, { period: 1, semester: 1, @@ -142,7 +143,7 @@ async function migrate20to30(schedule) { }) } -exports.findSchedule = findSchedule -exports.findAllScheduleParams = findAllScheduleParams -exports.findDefaultScheduleParams = findDefaultScheduleParams -exports.text = text +// exports.findSchedule = findSchedule +// exports.findAllScheduleParams = findAllScheduleParams +// exports.findDefaultScheduleParams = findDefaultScheduleParams +// exports.text = text From 7df8ec73ec16760d30b6411f13cad40c85d85d7e Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Mon, 14 Oct 2019 17:52:04 +0300 Subject: [PATCH 010/101] PersonCard export updated --- pages/collective.jsx | 2 +- src/components/PersonCard.jsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pages/collective.jsx b/pages/collective.jsx index 4371a0a2..05c33d81 100644 --- a/pages/collective.jsx +++ b/pages/collective.jsx @@ -4,7 +4,7 @@ import { get } from 'lodash' import { App } from '../src/components/App' import { Meta } from '../src/components/Meta' import { CollectiveImage } from '../src/components/CollectiveImage' -import PersonCard from '../src/components/PersonCard' +import { PersonCard } from '../src/components/PersonCard' import { CardList } from '../src/components/CardList' import menuModel from '../src/models/menu' import { buildMenu } from '../src/lib/menu' diff --git a/src/components/PersonCard.jsx b/src/components/PersonCard.jsx index f41ec159..c98b01d1 100644 --- a/src/components/PersonCard.jsx +++ b/src/components/PersonCard.jsx @@ -1,7 +1,7 @@ import React from 'react' import { Image } from './Image' -module.exports = ({ picture, name, url, profile }) => ( +export const PersonCard = ({ picture, name, url, profile }) => (
+ +

МБУДО

+

Шлиссельбургская детская художественная школа

+
) diff --git a/src/style/components/HudozkaTitle.scss b/src/style/components/HudozkaTitle.scss deleted file mode 100644 index d5820304..00000000 --- a/src/style/components/HudozkaTitle.scss +++ /dev/null @@ -1,22 +0,0 @@ -.HudozkaTitle { - --padding: var(--double-margin) 0; - - padding: var(--padding); - text-align: center; - - p { - color: var(--text-color-second); - margin-top: var(--single-margin); - font-size: var(--font-size-second); - } - - h1 { - margin-top: var(--single-margin); - } -} - -@media (max-width: var(--mobile-width)) { - .HudozkaTitle { - --padding: 0 0 var(--double-margin); - } -} diff --git a/src/style/style.scss b/src/style/style.scss index 955d578d..c2f54d58 100644 --- a/src/style/style.scss +++ b/src/style/style.scss @@ -28,7 +28,6 @@ @import "content"; @import "page-animation"; @import "main-image"; -@import "components/HudozkaTitle"; //@import "vertical-image"; @import "schedule-selector"; From b35e4e36e2212a5afc321dd9ee1276ad2e401036 Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Mon, 14 Oct 2019 23:42:43 +0300 Subject: [PATCH 025/101] unstable typescript --- .babelrc | 17 -- next-env.d.ts | 2 + package-lock.json | 356 +++++++++++++++++++++++++-- package.json | 9 +- pages/api/articles/index.js | 15 +- pages/api/pages/index.js | 3 - pages/{index.jsx => index.tsx} | 0 server.tsconfig.json | 14 ++ src/api/{articles.js => articles.ts} | 0 src/core/Article.js | 117 --------- src/core/Article.ts | 136 ++++++++++ src/core/{Data.js => Data.ts} | 4 +- src/core/Page.js | 93 ------- src/core/Page.ts | 102 ++++++++ src/core/{db.js => db.ts} | 13 +- src/lib/{store.js => store.ts} | 10 +- src/middlewares/withCollection.js | 7 +- src/{server.js => server.ts} | 17 +- tsconfig.json | 29 +++ 19 files changed, 658 insertions(+), 286 deletions(-) delete mode 100644 .babelrc create mode 100644 next-env.d.ts rename pages/{index.jsx => index.tsx} (100%) create mode 100644 server.tsconfig.json rename src/api/{articles.js => articles.ts} (100%) delete mode 100644 src/core/Article.js create mode 100644 src/core/Article.ts rename src/core/{Data.js => Data.ts} (88%) delete mode 100644 src/core/Page.js create mode 100644 src/core/Page.ts rename src/core/{db.js => db.ts} (86%) rename src/lib/{store.js => store.ts} (52%) rename src/{server.js => server.ts} (76%) create mode 100644 tsconfig.json diff --git a/.babelrc b/.babelrc deleted file mode 100644 index de974502..00000000 --- a/.babelrc +++ /dev/null @@ -1,17 +0,0 @@ -{ - "presets": [ - [ - "env", - { - "targets": { - "node": "8.5.0" - } - } - ] - ], - "plugins": [ - "transform-react-jsx", - "@babel/plugin-proposal-object-rest-spread", - "transform-class-properties" - ] -} \ No newline at end of file diff --git a/next-env.d.ts b/next-env.d.ts new file mode 100644 index 00000000..7b7aa2c7 --- /dev/null +++ b/next-env.d.ts @@ -0,0 +1,2 @@ +/// +/// diff --git a/package-lock.json b/package-lock.json index f53f6aa5..06f00aac 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1529,27 +1529,124 @@ } }, "@babel/plugin-transform-typescript": { - "version": "7.5.2", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.5.2.tgz", - "integrity": "sha512-r4zJOMbKY5puETm8+cIpaa0RQZG/sSASW1u0pj8qYklcERgVIbxVbP2wyJA7zI1//h7lEagQmXi9IL9iI5rfsA==", + "version": "7.6.3", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.6.3.tgz", + "integrity": "sha512-aiWINBrPMSC3xTXRNM/dfmyYuPNKY/aexYqBgh0HBI5Y+WO5oRAqW/oROYeYHrF4Zw12r9rK4fMk/ZlAmqx/FQ==", "requires": { - "@babel/helper-create-class-features-plugin": "^7.5.0", + "@babel/helper-create-class-features-plugin": "^7.6.0", "@babel/helper-plugin-utils": "^7.0.0", "@babel/plugin-syntax-typescript": "^7.2.0" }, "dependencies": { + "@babel/code-frame": { + "version": "7.5.5", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.5.5.tgz", + "integrity": "sha512-27d4lZoomVyo51VegxI20xZPuSHusqbQag/ztrBC7wegWoQ1nLREPVSKSW8byhTlzTKyNE4ifaTA6lCp7JjpFw==", + "requires": { + "@babel/highlight": "^7.0.0" + } + }, + "@babel/generator": { + "version": "7.6.4", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.6.4.tgz", + "integrity": "sha512-jsBuXkFoZxk0yWLyGI9llT9oiQ2FeTASmRFE32U+aaDTfoE92t78eroO7PTpU/OrYq38hlcDM6vbfLDaOLy+7w==", + "requires": { + "@babel/types": "^7.6.3", + "jsesc": "^2.5.1", + "lodash": "^4.17.13", + "source-map": "^0.5.0" + } + }, "@babel/helper-create-class-features-plugin": { - "version": "7.5.0", - "resolved": "https://registry.npmjs.org/@babel/helper-create-class-features-plugin/-/helper-create-class-features-plugin-7.5.0.tgz", - "integrity": "sha512-EAoMc3hE5vE5LNhMqDOwB1usHvmRjCDAnH8CD4PVkX9/Yr3W/tcz8xE8QvdZxfsFBDICwZnF2UTHIqslRpvxmA==", + "version": "7.6.0", + "resolved": "https://registry.npmjs.org/@babel/helper-create-class-features-plugin/-/helper-create-class-features-plugin-7.6.0.tgz", + "integrity": "sha512-O1QWBko4fzGju6VoVvrZg0RROCVifcLxiApnGP3OWfWzvxRZFCoBD81K5ur5e3bVY2Vf/5rIJm8cqPKn8HUJng==", "requires": { "@babel/helper-function-name": "^7.1.0", - "@babel/helper-member-expression-to-functions": "^7.0.0", + "@babel/helper-member-expression-to-functions": "^7.5.5", "@babel/helper-optimise-call-expression": "^7.0.0", "@babel/helper-plugin-utils": "^7.0.0", - "@babel/helper-replace-supers": "^7.4.4", + "@babel/helper-replace-supers": "^7.5.5", "@babel/helper-split-export-declaration": "^7.4.4" } + }, + "@babel/helper-member-expression-to-functions": { + "version": "7.5.5", + "resolved": "https://registry.npmjs.org/@babel/helper-member-expression-to-functions/-/helper-member-expression-to-functions-7.5.5.tgz", + "integrity": "sha512-5qZ3D1uMclSNqYcXqiHoA0meVdv+xUEex9em2fqMnrk/scphGlGgg66zjMrPJESPwrFJ6sbfFQYUSa0Mz7FabA==", + "requires": { + "@babel/types": "^7.5.5" + } + }, + "@babel/helper-replace-supers": { + "version": "7.5.5", + "resolved": "https://registry.npmjs.org/@babel/helper-replace-supers/-/helper-replace-supers-7.5.5.tgz", + "integrity": "sha512-XvRFWrNnlsow2u7jXDuH4jDDctkxbS7gXssrP4q2nUD606ukXHRvydj346wmNg+zAgpFx4MWf4+usfC93bElJg==", + "requires": { + "@babel/helper-member-expression-to-functions": "^7.5.5", + "@babel/helper-optimise-call-expression": "^7.0.0", + "@babel/traverse": "^7.5.5", + "@babel/types": "^7.5.5" + } + }, + "@babel/parser": { + "version": "7.6.4", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.6.4.tgz", + "integrity": "sha512-D8RHPW5qd0Vbyo3qb+YjO5nvUVRTXFLQ/FsDxJU2Nqz4uB5EnUN0ZQSEYpvTIbRuttig1XbHWU5oMeQwQSAA+A==" + }, + "@babel/traverse": { + "version": "7.6.3", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.6.3.tgz", + "integrity": "sha512-unn7P4LGsijIxaAJo/wpoU11zN+2IaClkQAxcJWBNCMS6cmVh802IyLHNkAjQ0iYnRS3nnxk5O3fuXW28IMxTw==", + "requires": { + "@babel/code-frame": "^7.5.5", + "@babel/generator": "^7.6.3", + "@babel/helper-function-name": "^7.1.0", + "@babel/helper-split-export-declaration": "^7.4.4", + "@babel/parser": "^7.6.3", + "@babel/types": "^7.6.3", + "debug": "^4.1.0", + "globals": "^11.1.0", + "lodash": "^4.17.13" + } + }, + "@babel/types": { + "version": "7.6.3", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.6.3.tgz", + "integrity": "sha512-CqbcpTxMcpuQTMhjI37ZHVgjBkysg5icREQIEZ0eG1yCNwg3oy+5AaLiOKmjsCj6nqOsa6Hf0ObjRVwokb7srA==", + "requires": { + "esutils": "^2.0.2", + "lodash": "^4.17.13", + "to-fast-properties": "^2.0.0" + } + }, + "debug": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", + "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", + "requires": { + "ms": "^2.1.1" + } + }, + "globals": { + "version": "11.12.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz", + "integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==" + }, + "jsesc": { + "version": "2.5.2", + "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz", + "integrity": "sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==" + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + }, + "to-fast-properties": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz", + "integrity": "sha1-3F5pjL0HkmW8c+A3doGk5Og/YW4=" } } }, @@ -1720,12 +1817,13 @@ } }, "@babel/preset-typescript": { - "version": "7.3.3", - "resolved": "https://registry.npmjs.org/@babel/preset-typescript/-/preset-typescript-7.3.3.tgz", - "integrity": "sha512-mzMVuIP4lqtn4du2ynEfdO0+RYcslwrZiJHXu4MGaC1ctJiW2fyaeDrtjJGs7R/KebZ1sgowcIoWf4uRpEfKEg==", + "version": "7.6.0", + "resolved": "https://registry.npmjs.org/@babel/preset-typescript/-/preset-typescript-7.6.0.tgz", + "integrity": "sha512-4xKw3tTcCm0qApyT6PqM9qniseCE79xGHiUnNdKGdxNsGUc2X7WwZybqIpnTmoukg3nhPceI5KPNzNqLNeIJww==", + "dev": true, "requires": { "@babel/helper-plugin-utils": "^7.0.0", - "@babel/plugin-transform-typescript": "^7.3.2" + "@babel/plugin-transform-typescript": "^7.6.0" } }, "@babel/register": { @@ -1862,12 +1960,162 @@ } } }, + "@types/accepts": { + "version": "1.3.5", + "resolved": "https://registry.npmjs.org/@types/accepts/-/accepts-1.3.5.tgz", + "integrity": "sha512-jOdnI/3qTpHABjM5cx1Hc0sKsPoYCp+DP/GJRGtDlPd7fiV9oXGGIcjW/ZOxLIvjGz8MA+uMZI9metHlgqbgwQ==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, + "@types/body-parser": { + "version": "1.17.1", + "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.17.1.tgz", + "integrity": "sha512-RoX2EZjMiFMjZh9lmYrwgoP9RTpAjSHiJxdp4oidAQVO02T7HER3xj9UKue5534ULWeqVEkujhWcyvUce+d68w==", + "dev": true, + "requires": { + "@types/connect": "*", + "@types/node": "*" + } + }, + "@types/connect": { + "version": "3.4.32", + "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.32.tgz", + "integrity": "sha512-4r8qa0quOvh7lGD0pre62CAb1oni1OO6ecJLGCezTmhQ8Fz50Arx9RUszryR8KlgK6avuSXvviL6yWyViQABOg==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, + "@types/cookies": { + "version": "0.7.4", + "resolved": "https://registry.npmjs.org/@types/cookies/-/cookies-0.7.4.tgz", + "integrity": "sha512-oTGtMzZZAVuEjTwCjIh8T8FrC8n/uwy+PG0yTvQcdZ7etoel7C7/3MSd7qrukENTgQtotG7gvBlBojuVs7X5rw==", + "dev": true, + "requires": { + "@types/connect": "*", + "@types/express": "*", + "@types/keygrip": "*", + "@types/node": "*" + } + }, + "@types/express": { + "version": "4.17.1", + "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.1.tgz", + "integrity": "sha512-VfH/XCP0QbQk5B5puLqTLEeFgR8lfCJHZJKkInZ9mkYd+u8byX0kztXEQxEk4wZXJs8HI+7km2ALXjn4YKcX9w==", + "dev": true, + "requires": { + "@types/body-parser": "*", + "@types/express-serve-static-core": "*", + "@types/serve-static": "*" + } + }, + "@types/express-serve-static-core": { + "version": "4.16.9", + "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.16.9.tgz", + "integrity": "sha512-GqpaVWR0DM8FnRUJYKlWgyARoBUAVfRIeVDZQKOttLFp5SmhhF9YFIYeTPwMd/AXfxlP7xVO2dj1fGu0Q+krKQ==", + "dev": true, + "requires": { + "@types/node": "*", + "@types/range-parser": "*" + } + }, + "@types/http-assert": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/@types/http-assert/-/http-assert-1.5.1.tgz", + "integrity": "sha512-PGAK759pxyfXE78NbKxyfRcWYA/KwW17X290cNev/qAsn9eQIxkH4shoNBafH37wewhDG/0p1cHPbK6+SzZjWQ==", + "dev": true + }, + "@types/keygrip": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@types/keygrip/-/keygrip-1.0.1.tgz", + "integrity": "sha1-/1QEYtL7TQqIRBzq8n0oewHD2Hg=", + "dev": true + }, + "@types/koa": { + "version": "2.0.50", + "resolved": "https://registry.npmjs.org/@types/koa/-/koa-2.0.50.tgz", + "integrity": "sha512-TcgOD2lh0EISSadAk1DOBYw7kNoY9XdeB3vEMOKiDDaTMYm+V54nyPsU7Ulb/htb5OBIR79RgTeCWntCcophLw==", + "dev": true, + "requires": { + "@types/accepts": "*", + "@types/cookies": "*", + "@types/http-assert": "*", + "@types/keygrip": "*", + "@types/koa-compose": "*", + "@types/node": "*" + } + }, + "@types/koa-compose": { + "version": "3.2.4", + "resolved": "https://registry.npmjs.org/@types/koa-compose/-/koa-compose-3.2.4.tgz", + "integrity": "sha512-ioou0rxkuWL+yBQYsHUQAzRTfVxAg8Y2VfMftU+Y3RA03/MzuFL0x/M2sXXj3PkfnENbHsjeHR1aMdezLYpTeA==", + "dev": true, + "requires": { + "@types/koa": "*" + } + }, + "@types/koa-route": { + "version": "3.2.4", + "resolved": "https://registry.npmjs.org/@types/koa-route/-/koa-route-3.2.4.tgz", + "integrity": "sha512-jB4I4/HppiHiSFMqQvMC2Px5Zm8CExA7Bw7xW+o60xh4v0LrNTfKV7LMCGuJNRuUuTTiRcJvF1rbq5mINgQ1UQ==", + "dev": true, + "requires": { + "@types/koa": "*", + "path-to-regexp": "^1.7.0" + } + }, + "@types/mime": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/@types/mime/-/mime-2.0.1.tgz", + "integrity": "sha512-FwI9gX75FgVBJ7ywgnq/P7tw+/o1GUbtP0KzbtusLigAOgIgNISRK0ZPl4qertvXSIE8YbsVJueQ90cDt9YYyw==", + "dev": true + }, + "@types/node": { + "version": "12.7.12", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.7.12.tgz", + "integrity": "sha512-KPYGmfD0/b1eXurQ59fXD1GBzhSQfz6/lKBxkaHX9dKTzjXbK68Zt7yGUxUsCS1jeTy/8aL+d9JEr+S54mpkWQ==", + "dev": true + }, + "@types/prop-types": { + "version": "15.7.3", + "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.3.tgz", + "integrity": "sha512-KfRL3PuHmqQLOG+2tGpRO26Ctg+Cq1E01D2DMriKEATHgWLfeNDmq9e29Q9WIky0dQ3NPkd1mzYH8Lm936Z9qw==", + "dev": true + }, "@types/q": { "version": "1.5.2", "resolved": "https://registry.npmjs.org/@types/q/-/q-1.5.2.tgz", "integrity": "sha512-ce5d3q03Ex0sy4R14722Rmt6MT07Ua+k4FwDfdcToYJcMKNtRVQvJ6JCAPdAmAnbRb6CsX6aYb9m96NGod9uTw==", "dev": true }, + "@types/range-parser": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.3.tgz", + "integrity": "sha512-ewFXqrQHlFsgc09MK5jP5iR7vumV/BYayNC6PgJO2LPe8vrnNFyjQjSppfEngITi0qvfKtzFvgKymGheFM9UOA==", + "dev": true + }, + "@types/react": { + "version": "16.9.5", + "resolved": "https://registry.npmjs.org/@types/react/-/react-16.9.5.tgz", + "integrity": "sha512-jQ12VMiFOWYlp+j66dghOWcmDDwhca0bnlcTxS4Qz/fh5gi6wpaZDthPEu/Gc/YlAuO87vbiUXL8qKstFvuOaA==", + "dev": true, + "requires": { + "@types/prop-types": "*", + "csstype": "^2.2.0" + } + }, + "@types/serve-static": { + "version": "1.13.3", + "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.13.3.tgz", + "integrity": "sha512-oprSwp094zOglVrXdlo/4bAHtKTAxX6VT8FOZlBKrmyLbNvE1zxZyJ6yikMVtHIvwP45+ZQGJn+FdXGKTozq0g==", + "dev": true, + "requires": { + "@types/express-serve-static-core": "*", + "@types/mime": "*" + } + }, "@webassemblyjs/ast": { "version": "1.8.5", "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.8.5.tgz", @@ -2282,6 +2530,12 @@ "readable-stream": "^2.0.6" } }, + "arg": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.1.tgz", + "integrity": "sha512-SlmP3fEA88MBv0PypnXZ8ZfJhwmDeIE3SP71j37AiXQBXYosPV0x6uISAaHYSlSVhmHOVkomen0tbGk6Anlebw==", + "dev": true + }, "argparse": { "version": "1.0.9", "resolved": "http://storage.mds.yandex.net/get-npm/69187/argparse-1.0.9.tgz", @@ -2559,9 +2813,9 @@ }, "dependencies": { "is-buffer": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.3.tgz", - "integrity": "sha512-U15Q7MXTuZlrbymiz95PJpZxu8IlipAp4dtS3wOdgPXx3mqBnslrWU14kxfHB+Py/+2PVKSr37dMAgM2A4uArw==" + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.4.tgz", + "integrity": "sha512-Kq1rokWXOPXWuaMAqZiJW4XxsmD9zGx9q4aePabbn3qCRGedtH7Cm+zV8WETitMfu1wdh+Rvd6w5egwSngUX2A==" } } }, @@ -5235,6 +5489,12 @@ } } }, + "csstype": { + "version": "2.6.7", + "resolved": "https://registry.npmjs.org/csstype/-/csstype-2.6.7.tgz", + "integrity": "sha512-9Mcn9sFbGBAdmimWb2gLVDtFJzeKtDGIr76TUqmjZrw9LFXBMSU70lcs+C0/7fyCd6iBDqmksUcCOUIkisPHsQ==", + "dev": true + }, "currently-unhandled": { "version": "0.4.1", "resolved": "http://storage.mds.yandex.net/get-npm/38095/currently-unhandled-0.4.1.tgz", @@ -8415,6 +8675,12 @@ } } }, + "make-error": { + "version": "1.3.5", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.5.tgz", + "integrity": "sha512-c3sIjNUow0+8swNwVpqoH4YCShKNFkMaw6oH1mNS2haDZQqkeZFlHS3dhoeEbKKmJB4vXpJucU6oH75aDYeE9g==", + "dev": true + }, "mamacro": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/mamacro/-/mamacro-0.0.3.tgz", @@ -9346,6 +9612,15 @@ "worker-farm": "1.7.0" }, "dependencies": { + "@babel/preset-typescript": { + "version": "7.3.3", + "resolved": "https://registry.npmjs.org/@babel/preset-typescript/-/preset-typescript-7.3.3.tgz", + "integrity": "sha512-mzMVuIP4lqtn4du2ynEfdO0+RYcslwrZiJHXu4MGaC1ctJiW2fyaeDrtjJGs7R/KebZ1sgowcIoWf4uRpEfKEg==", + "requires": { + "@babel/helper-plugin-utils": "^7.0.0", + "@babel/plugin-transform-typescript": "^7.3.2" + } + }, "acorn": { "version": "6.2.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.2.0.tgz", @@ -15541,6 +15816,43 @@ "integrity": "sha1-OTvnMKlEb9Hq1tpZoBQwjzbCics=", "dev": true }, + "ts-node": { + "version": "8.4.1", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-8.4.1.tgz", + "integrity": "sha512-5LpRN+mTiCs7lI5EtbXmF/HfMeCjzt7DH9CZwtkr6SywStrNQC723wG+aOWFiLNn7zT3kD/RnFqi3ZUfr4l5Qw==", + "dev": true, + "requires": { + "arg": "^4.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "source-map-support": "^0.5.6", + "yn": "^3.0.0" + }, + "dependencies": { + "diff": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.1.tgz", + "integrity": "sha512-s2+XdvhPCOF01LRQBC8hf4vhbVmI2CGS5aZnxLJlT5FtdhPCDFq80q++zK2KlrVorVDdL5BOGZ/VfLrVtYNF+Q==", + "dev": true + }, + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true + }, + "source-map-support": { + "version": "0.5.13", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.13.tgz", + "integrity": "sha512-SHSKFHadjVA5oR4PPqhtAVdcBWwRYVd6g6cAXnIbRiIwc2EhPrTuKUBdSLvlEKyIP3GCf89fltvcZiP9MMFA1w==", + "dev": true, + "requires": { + "buffer-from": "^1.0.0", + "source-map": "^0.6.0" + } + } + } + }, "tslib": { "version": "1.9.3", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz", @@ -15594,6 +15906,12 @@ "resolved": "http://storage.mds.yandex.net/get-npm/35308/typedarray-0.0.6.tgz", "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=" }, + "typescript": { + "version": "3.6.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.6.4.tgz", + "integrity": "sha512-unoCll1+l+YK4i4F8f22TaNVPRHcD9PA3yCuZ8g5e0qGqlVlJ/8FSateOLLSagn+Yg5+ZwuPkL8LFUc0Jcvksg==", + "dev": true + }, "ua-parser-js": { "version": "0.7.14", "resolved": "http://storage.mds.yandex.net/get-npm/66641/ua-parser-js-0.7.14.tgz", @@ -16617,6 +16935,12 @@ "version": "1.2.1", "resolved": "https://registry.npmjs.org/ylru/-/ylru-1.2.1.tgz", "integrity": "sha512-faQrqNMzcPCHGVC2aaOINk13K+aaBDUPjGWl0teOXywElLjyVAB6Oe2jj62jHYtwsU49jXhScYbvPENK+6zAvQ==" + }, + "yn": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", + "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", + "dev": true } } } diff --git a/package.json b/package.json index 60c7800a..069a7dd7 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "main": "src/bin/www.js", "scripts": { "start": "NODE_ENV=production node src/server.js", - "dev": "node src/server.js", + "dev": "ts-node --project server.tsconfig.json src/server.ts", "build": "next build && next export -o dist && npm run sitemap && npm run feed && npm run robots-txt", "robots-txt": "node scripts/robots-txt.js", "sitemap": "node scripts/sitemap.js", @@ -54,7 +54,12 @@ "@babel/plugin-proposal-object-rest-spread": "^7.4.4", "@babel/polyfill": "^7.0.0-beta.47", "@babel/preset-env": "^7.4.5", + "@babel/preset-typescript": "^7.6.0", "@babel/register": "^7.0.0-beta.47", + "@types/koa": "^2.0.50", + "@types/koa-route": "^3.2.4", + "@types/node": "^12.7.12", + "@types/react": "^16.9.5", "@zeit/next-css": "^1.0.1", "@zeit/next-sass": "^1.0.1", "autoprefixer": "^6.3.6", @@ -73,6 +78,8 @@ "mocha": "^6.1.4", "node-sass": "^4.12.0", "should": "^8.2.2", + "ts-node": "^8.4.1", + "typescript": "^3.6.4", "webpack": "^4.32.2" } } diff --git a/pages/api/articles/index.js b/pages/api/articles/index.js index 35347033..4a14b725 100644 --- a/pages/api/articles/index.js +++ b/pages/api/articles/index.js @@ -1,15 +1,14 @@ -import { connect } from '../../../src/core/db' -import { findArticles } from '../../../src/api/articles' +// import { findArticles } from '../../../src/api/articles' import { withMiddleware } from '../../../src/middlewares/withMiddleware' +import Article from '../../../src/core/Article' export default withMiddleware(async (req, res) => { - await connect() + // const { query } = req + // const page = parseInt(query.page) + // const pageSize = parseInt(query.pageSize) - const { query } = req - const page = parseInt(query.page) - const pageSize = parseInt(query.pageSize) - - const data = await findArticles(page, pageSize) + // const data = await findArticles(page, pageSize) + const data = await Article.find({}) if (data) { res.json(data) diff --git a/pages/api/pages/index.js b/pages/api/pages/index.js index 2977f0d2..05950b09 100644 --- a/pages/api/pages/index.js +++ b/pages/api/pages/index.js @@ -1,10 +1,7 @@ -import { connect } from '../../../src/core/db' import Page from '../../../src/core/Page' import { withMiddleware } from '../../../src/middlewares/withMiddleware' export default withMiddleware(async (req, res) => { - await connect() - const items = await Page.find({}) if (items) { diff --git a/pages/index.jsx b/pages/index.tsx similarity index 100% rename from pages/index.jsx rename to pages/index.tsx diff --git a/server.tsconfig.json b/server.tsconfig.json new file mode 100644 index 00000000..22bafc4f --- /dev/null +++ b/server.tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "noEmitOnError": false, + "target": "es5", + "module": "commonjs", + "jsx": "preserve", + "outDir": "./build", + "strict": false, + "esModuleInterop": true + }, + "include": [ + "src/**/*.ts" + ] +} \ No newline at end of file diff --git a/src/api/articles.js b/src/api/articles.ts similarity index 100% rename from src/api/articles.js rename to src/api/articles.ts diff --git a/src/core/Article.js b/src/core/Article.js deleted file mode 100644 index 7336dc91..00000000 --- a/src/core/Article.js +++ /dev/null @@ -1,117 +0,0 @@ -const Data = require('./Data') -const Image = require('./Image') -const Config = require('./Config') -const {find, findOne, total} = require('../lib/store') - -const store = () => Data.getStore(Article) - -function make(C) { - return x => new C(x) -} - -class Article { - static async find(query, options = {}) { - const items = await find(store(), query, options) - - return Promise.all(items.map(processArticle)) - } - - static async findById(id) { - const item = await findOne(store(), {id}) - - return !item - ? null - : processArticle(item) - } - - static async total(query = {}) { - return total(store(), query) - } - - static async findPinned() { - const now = new Date() - const query = {until: {$gte: now}} - - return Article.find(query, { - sort: {date: -1}, - }) - } - - constructor(data) { - this.id = data.id - this.images = data.images - this.post = data.post - this.folder = data.folder - this.date = data.date - this.title = data.title - this.until = data.until - this.tags = (data.tags || []).map(make(Tag)) - this.content = data.content - this.hash = data.hash - this.type = data.type - this.origin = data.origin - this.file = data.file - this.version = data.version - this.preview = data.preview - - this.url = `/article/${this.id}` - } - - plain() { - return { - id: this.id, - images: this.images, - post: this.post, - folder: this.folder, - date: this.date, - title: this.title, - until: this.until, - tags: this.tags, - content: this.content, - hash: this.hash, - type: this.type, - origin: this.origin, - file: this.file, - version: this.version, - preview: this.preview, - url: this.url, - } - } -} - -class Tag { - constructor(tag) { - this.name = tag; - } -} - -const previewFromImage = (imgs = []) => imgs.length - ? imgs[0] - : null - -async function resolveDefaultPreview() { - const config = await Config.findConfig() - if (!config) return null - - return Image.findByFile(config.articleCardDefaultPreview) -} - -async function processArticle(article) { - let preview = null - const previewId = article.preview - ? article.preview - : previewFromImage(article.images) - - if (previewId) { - preview = await Image.findById(previewId) - } else { - preview = await resolveDefaultPreview() - } - - return new Article({ - ...article, - preview, - }) -} - -module.exports = Article diff --git a/src/core/Article.ts b/src/core/Article.ts new file mode 100644 index 00000000..8f749d03 --- /dev/null +++ b/src/core/Article.ts @@ -0,0 +1,136 @@ +import Data from './Data' +import Image from './Image' +import Config from './Config' +import { findOne, total } from '../lib/store' +import * as libStore from '../lib/store' + +const store = () => Data.getStore(Article) + +function make(C) { + return x => new C(x) +} + +export default class Article { + static async find(query, options = {}): Promise { + return [] + // const items = await libStore.find(store(), query, options as any) + + // return Promise.all(items.map(processArticle)) + } + + static async findById(id) { + const item = await findOne(store(), { id }) + + return !item + ? null + : processArticle(item) + } + + static async total(query = {}) { + return total(store(), query) + } + + static async findPinned() { + const now = new Date() + const query = { until: { $gte: now } } + + return Article.find(query, { + sort: { date: -1 }, + }) + } + + public id: any + public images: any + public post: any + public folder: any + public date: any + public title: any + public until: any + public tags: any + public content: any + public hash: any + public type: any + public origin: any + public file: any + public version: any + public preview: any + public url: any + + constructor(data) { + this.id = data.id + this.images = data.images + this.post = data.post + this.folder = data.folder + this.date = data.date + this.title = data.title + this.until = data.until + this.tags = (data.tags || []).map(make(Tag)) + this.content = data.content + this.hash = data.hash + this.type = data.type + this.origin = data.origin + this.file = data.file + this.version = data.version + this.preview = data.preview + + this.url = `/article/${this.id}` + } + + plain() { + return { + id: this.id, + images: this.images, + post: this.post, + folder: this.folder, + date: this.date, + title: this.title, + until: this.until, + tags: this.tags, + content: this.content, + hash: this.hash, + type: this.type, + origin: this.origin, + file: this.file, + version: this.version, + preview: this.preview, + url: this.url, + } + } +} + +class Tag { + public name: string + + constructor(tag) { + this.name = tag; + } +} + +const previewFromImage = (imgs = []) => imgs.length + ? imgs[0] + : null + +async function resolveDefaultPreview() { + const config = await Config.findConfig() + if (!config) return null + + return Image.findByFile(config.articleCardDefaultPreview) +} + +async function processArticle(article) { + let preview = null + const previewId = article.preview + ? article.preview + : previewFromImage(article.images) + + if (previewId) { + preview = await Image.findById(previewId) + } else { + preview = await resolveDefaultPreview() + } + + return new Article({ + ...article, + preview, + }) +} diff --git a/src/core/Data.js b/src/core/Data.ts similarity index 88% rename from src/core/Data.js rename to src/core/Data.ts index 70388deb..97c44f88 100644 --- a/src/core/Data.js +++ b/src/core/Data.ts @@ -2,7 +2,7 @@ const db = require('./db') const store = new Map() -class Data { +export default class Data { static setStore(Class, collection) { store.set(Class, collection) } @@ -15,5 +15,3 @@ class Data { return db.collection(name) } } - -module.exports = Data diff --git a/src/core/Page.js b/src/core/Page.js deleted file mode 100644 index 388800a9..00000000 --- a/src/core/Page.js +++ /dev/null @@ -1,93 +0,0 @@ -const Data = require('./Data') -const Image = require('./Image') -const Config = require('./Config') -const {find, findOne, total} = require('../lib/store') - -const store = () => Data.getStore(Page) - -class Page { - static async find(query, options = {}) { - const items = await find(store(), query, options) - - return Promise.all(items.map(processPage)) - } - - static async findById(id) { - const item = await findOne(store(), {id}) - - return !item - ? null - : processPage(item) - } - - static async findByUrl(url) { - const item = await findOne(store(), {url}) - - return !item - ? null - : processPage(item) - } - - static async total(query = {}) { - return total(store(), query) - } - - constructor(data) { - this.id = data.id - this.hash = data.hash - this.file = data.file - this.url = data.url - this.content = data.content - this.title = data.title - this.data = data.data - this.images = data.images - this.documents = data.documents - this.preview = data.preview - } - - plain() { - return { - id: this.id, - images: this.images, - documents: this.documents, - data: this.data, - title: this.title, - content: this.content, - hash: this.hash, - file: this.file, - preview: this.preview, - url: this.url, - } - } -} - -const previewFromImage = (imgs = []) => imgs.length - ? imgs[0] - : null - -async function resolveDefaultPreview() { - const config = await Config.findConfig() - if (!config) return null - - return Image.findByFile(config.articleCardDefaultPreview) -} - -async function processPage(article) { - let preview = null - const previewId = article.preview - ? article.preview - : previewFromImage(article.images) - - if (previewId) { - preview = await Image.findById(previewId) - } else { - preview = await resolveDefaultPreview() - } - - return new Page({ - ...article, - preview, - }) -} - -module.exports = Page diff --git a/src/core/Page.ts b/src/core/Page.ts new file mode 100644 index 00000000..4505bcc1 --- /dev/null +++ b/src/core/Page.ts @@ -0,0 +1,102 @@ +import Data from './Data' +import { find as storeFind, findOne, total } from '../lib/store' +const Image = require('./Image') +const Config = require('./Config') + +const store = () => Data.getStore(Page) + +export default class Page { + static async find(query, options = {}): Promise { + const items = await storeFind(store(), query, options as any) + + return Promise.all(items.map(processPage)) + } + + static async findById(id) { + const item = await findOne(store(), { id }) + + return !item + ? null + : processPage(item) + } + + static async findByUrl(url) { + const item = await findOne(store(), { url }) + + return !item + ? null + : processPage(item) + } + + static async total(query = {}) { + return total(store(), query) + } + + public id: any + public hash: any + public file: any + public url: string + public content: any + public title: any + public data: any + public images: any + public documents: any + public preview: any + + constructor(data) { + this.id = data.id + this.hash = data.hash + this.file = data.file + this.url = data.url + this.content = data.content + this.title = data.title + this.data = data.data + this.images = data.images + this.documents = data.documents + this.preview = data.preview + } + + plain() { + return { + id: this.id, + images: this.images, + documents: this.documents, + data: this.data, + title: this.title, + content: this.content, + hash: this.hash, + file: this.file, + preview: this.preview, + url: this.url, + } + } +} + +const previewFromImage = (imgs = []) => imgs.length + ? imgs[0] + : null + +async function resolveDefaultPreview() { + const config = await Config.findConfig() + if (!config) return null + + return Image.findByFile(config.articleCardDefaultPreview) +} + +async function processPage(article) { + let preview = null + const previewId = article.preview + ? article.preview + : previewFromImage(article.images) + + if (previewId) { + preview = await Image.findById(previewId) + } else { + preview = await resolveDefaultPreview() + } + + return new Page({ + ...article, + preview, + }) +} diff --git a/src/core/db.js b/src/core/db.ts similarity index 86% rename from src/core/db.js rename to src/core/db.ts index 1b5d8c1f..40adf502 100644 --- a/src/core/db.js +++ b/src/core/db.ts @@ -1,4 +1,4 @@ -const Data = require('./Data') +import Data from './Data' const Page = require('./Page') const Article = require('./Article') const Album = require('./Album') @@ -12,7 +12,7 @@ const { MongoClient, ObjectId } = require('mongodb') var db -async function connect() { +export async function connect() { if (db) { return db } @@ -22,11 +22,11 @@ async function connect() { return db } -function collection(name) { +export function collection(name) { return db.collection(name) } -function id(i) { +export function id(i) { if (typeof i === 'string') return ObjectId(i) else if (i instanceof ObjectId) return i else if (i instanceof Object) return '_id' in i ? ObjectId(i._id) : null @@ -45,8 +45,3 @@ function init(db) { return db } - -exports.connect = connect -exports.collection = collection -exports.c = collection -exports.id = id \ No newline at end of file diff --git a/src/lib/store.js b/src/lib/store.ts similarity index 52% rename from src/lib/store.js rename to src/lib/store.ts index 1b06b64e..309848bd 100644 --- a/src/lib/store.js +++ b/src/lib/store.ts @@ -1,4 +1,4 @@ -async function find(collection, query, {sort, skip, limit}) { +export async function find(collection, query, {sort, skip, limit}) { const cursor = collection.find(query) if (sort) cursor.sort(sort) @@ -8,16 +8,12 @@ async function find(collection, query, {sort, skip, limit}) { return cursor.toArray() } -async function findOne(collection, query) { +export async function findOne(collection, query) { return collection.findOne(query) } -async function total(collection, query) { +export async function total(collection, query) { return collection .find(query) .count() } - -exports.find = find -exports.findOne = findOne -exports.total = total diff --git a/src/middlewares/withCollection.js b/src/middlewares/withCollection.js index a877152d..0fcd5b57 100644 --- a/src/middlewares/withCollection.js +++ b/src/middlewares/withCollection.js @@ -1,14 +1,13 @@ // import { MongoClient } from 'mongodb'; // const { connect, collection } = require('../../src/core/db') -// import {collection, connect} from '../core/db' -const core = require('../core/db') +import {collection, connect} from '../core/db' // const client = new MongoClient(process.env.MONGODB_URI, { useNewUrlParser: true }); export const withCollection = handler => async (req, res) => { - await core.connect() + await connect() - req.collection = core.collection + req.collection = collection // if (!client.isConnected()) { // return client.connect().then(() => { diff --git a/src/server.js b/src/server.ts similarity index 76% rename from src/server.js rename to src/server.ts index 407f1411..70b9c687 100644 --- a/src/server.js +++ b/src/server.ts @@ -1,8 +1,8 @@ -const Koa = require('koa') -const next = require('next') -const { get } = require('koa-route') -const { connect } = require('./core/db') -const Page = require('./core/Page') +import Koa from 'koa' +import next from 'next' +import { get } from 'koa-route' +import { connect } from './core/db' +import Page from './core/Page' const dev = process.env.NODE_ENV !== 'production' const app = next({ dev }) @@ -18,8 +18,9 @@ app.prepare().then(async () => { process.exit(1) } - const pages = await Page.find({}) - const pagesUrls = pages.map(x => x.url) + // const pages = await Page.find({}) + // const pagesUrls = pages.map(x => x.url) + const pagesUrls = [] const server = new Koa() server.use(async (ctx, next) => { @@ -29,7 +30,7 @@ app.prepare().then(async () => { server.use(get('*', async ctx => { const url = ctx.req.url - + if (pagesUrls.includes(url)) { await app.render(ctx.req, ctx.res, '/next', ctx.query) } else { diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000..48ca14af --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,29 @@ +{ + "compilerOptions": { + "target": "es5", + "lib": [ + "dom", + "dom.iterable", + "esnext" + ], + "allowJs": true, + "skipLibCheck": true, + "strict": false, + "forceConsistentCasingInFileNames": true, + "noEmit": true, + "esModuleInterop": true, + "module": "esnext", + "moduleResolution": "node", + "resolveJsonModule": true, + "isolatedModules": true, + "jsx": "preserve" + }, + "exclude": [ + "node_modules" + ], + "include": [ + "next-env.d.ts", + "**/*.ts", + "**/*.tsx" + ] +} From 7363d7c0ec828b435032fd6c491fd2f704bd6df3 Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Mon, 14 Oct 2019 23:46:09 +0300 Subject: [PATCH 026/101] api articles -> server articles --- src/{api => server}/articles.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/{api => server}/articles.ts (97%) diff --git a/src/api/articles.ts b/src/server/articles.ts similarity index 97% rename from src/api/articles.ts rename to src/server/articles.ts index 9870652b..5f1d8285 100644 --- a/src/api/articles.ts +++ b/src/server/articles.ts @@ -2,7 +2,7 @@ import Article from '../core/Article' import ImageArtifactType from '../core/ImageArtifactType' import { sortBy } from '../utils/sort' import { timestamp } from '../lib/date' -import { encodeImage } from './image' +import { encodeImage } from '../api/image' export const sortArticleByDate = sortBy( x => timestamp(new Date(x.date)) From 5831275b7a086f5fa00a8382d17d9cbf6ae2766d Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Tue, 15 Oct 2019 00:16:55 +0300 Subject: [PATCH 027/101] updated to make index page working --- package.json | 1 + pages/api/articles/index.js | 21 --------- pages/api/articles/index.ts | 19 ++++++++ src/core/Article.ts | 12 +++--- src/core/Config.js | 37 ---------------- src/core/Config.ts | 44 +++++++++++++++++++ src/core/Image.js | 75 -------------------------------- src/core/Image.ts | 81 +++++++++++++++++++++++++++++++++++ src/core/db.ts | 15 ++++--- src/server/articles.ts | 2 +- src/server/{lib.js => lib.ts} | 2 +- 11 files changed, 160 insertions(+), 149 deletions(-) delete mode 100644 pages/api/articles/index.js create mode 100644 pages/api/articles/index.ts delete mode 100644 src/core/Config.js create mode 100644 src/core/Config.ts delete mode 100644 src/core/Image.js create mode 100644 src/core/Image.ts rename src/server/{lib.js => lib.ts} (83%) diff --git a/package.json b/package.json index 069a7dd7..8a341663 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "scripts": { "start": "NODE_ENV=production node src/server.js", "dev": "ts-node --project server.tsconfig.json src/server.ts", + "next-dev": "next dev", "build": "next build && next export -o dist && npm run sitemap && npm run feed && npm run robots-txt", "robots-txt": "node scripts/robots-txt.js", "sitemap": "node scripts/sitemap.js", diff --git a/pages/api/articles/index.js b/pages/api/articles/index.js deleted file mode 100644 index 4a14b725..00000000 --- a/pages/api/articles/index.js +++ /dev/null @@ -1,21 +0,0 @@ -// import { findArticles } from '../../../src/api/articles' -import { withMiddleware } from '../../../src/middlewares/withMiddleware' -import Article from '../../../src/core/Article' - -export default withMiddleware(async (req, res) => { - // const { query } = req - // const page = parseInt(query.page) - // const pageSize = parseInt(query.pageSize) - - // const data = await findArticles(page, pageSize) - const data = await Article.find({}) - - if (data) { - res.json(data) - } else { - res.status(404) - res.json({ - error: `Article ${id} not found` - }) - } -}) diff --git a/pages/api/articles/index.ts b/pages/api/articles/index.ts new file mode 100644 index 00000000..3592a507 --- /dev/null +++ b/pages/api/articles/index.ts @@ -0,0 +1,19 @@ +import { findArticles } from '../../../src/server/articles' +import { withMiddleware } from '../../../src/middlewares/withMiddleware' + +export default withMiddleware(async (req, res) => { + const { query } = req + const page = parseInt(query.page) + const pageSize = parseInt(query.pageSize) + + const data = await findArticles(page, pageSize) + + if (data) { + res.json(data) + } else { + res.status(404) + res.json({ + error: `Articles not found` + }) + } +}) diff --git a/src/core/Article.ts b/src/core/Article.ts index 8f749d03..bb39d87d 100644 --- a/src/core/Article.ts +++ b/src/core/Article.ts @@ -1,10 +1,9 @@ import Data from './Data' import Image from './Image' import Config from './Config' -import { findOne, total } from '../lib/store' -import * as libStore from '../lib/store' +import { find, findOne, total } from '../lib/store' -const store = () => Data.getStore(Article) +const store = () => Data.getStore('Article') function make(C) { return x => new C(x) @@ -12,10 +11,9 @@ function make(C) { export default class Article { static async find(query, options = {}): Promise { - return [] - // const items = await libStore.find(store(), query, options as any) + const items = await find(store(), query, options as any) - // return Promise.all(items.map(processArticle)) + return Promise.all(items.map(processArticle)) } static async findById(id) { @@ -126,7 +124,7 @@ async function processArticle(article) { if (previewId) { preview = await Image.findById(previewId) } else { - preview = await resolveDefaultPreview() + // preview = await resolveDefaultPreview() } return new Article({ diff --git a/src/core/Config.js b/src/core/Config.js deleted file mode 100644 index bb900cc9..00000000 --- a/src/core/Config.js +++ /dev/null @@ -1,37 +0,0 @@ -const Data = require('./Data') -const {findOne} = require('../lib/store') - -class Config { - static get store() { - return Data.getStore(Config) - } - - static async findConfig() { - const config = await Config.findById('settings') - return config || new Config({}) - } - - static async findById(id) { - const data = await findOne(Config.store, {id}) - if (!data) return null - - return new Config(data) - } - - constructor({hash, file, ...data}) { - this.hash = hash - this.file = file - this.server = data.server - this.articlesPerPage = data.articlesPerPage || 5 - this.collectiveOrder = data.collectiveOrder || [] - this.articleCardDefaultPreview = data.articleCardDefaultPreview - this.collectiveImage = data.collectiveImage - - const redirect = data.redirect || {} - this.redirect = new Map(Object - .entries(redirect) - ) - } -} - -module.exports = Config diff --git a/src/core/Config.ts b/src/core/Config.ts new file mode 100644 index 00000000..dd6ca3f0 --- /dev/null +++ b/src/core/Config.ts @@ -0,0 +1,44 @@ +import Data from './Data' +import { findOne } from '../lib/store' + +export default class Config { + static get store() { + return Data.getStore('Settings') + } + + static async findConfig() { + const config = await Config.findById('settings') + return config || new Config({} as any) + } + + static async findById(id) { + const data = await findOne(Config.store, { id }) + if (!data) return null + + return new Config(data) + } + + public hash: any + public file: any + public server: any + public articlesPerPage: any + public collectiveOrder: any + public articleCardDefaultPreview: any + public collectiveImage: any + public redirect: any + + constructor({ hash, file, ...data }) { + this.hash = hash + this.file = file + this.server = data.server + this.articlesPerPage = data.articlesPerPage || 5 + this.collectiveOrder = data.collectiveOrder || [] + this.articleCardDefaultPreview = data.articleCardDefaultPreview + this.collectiveImage = data.collectiveImage + + const redirect = data.redirect || {} + this.redirect = new Map(Object + .entries(redirect) + ) + } +} diff --git a/src/core/Image.js b/src/core/Image.js deleted file mode 100644 index 2936f19e..00000000 --- a/src/core/Image.js +++ /dev/null @@ -1,75 +0,0 @@ -const Data = require('./Data') -const ImageArtifactType = require('./ImageArtifactType') -const {findOne} = require('../lib/store') -const { mapOf } = require('../server/lib') - -const store = () => Data.getStore(Image) - -class Image { - static async findById(id) { - const data = await findOne(store(), {_id: id}) - if (!data) return null - - const artifacts = data.data - return new Image({...data, artifacts}) - } - - static async findByFile(file) { - const data = await findOne(store(), {file}) - if (!data) return null - - const artifacts = data.data - return new Image({...data, artifacts}) - } - - constructor({hash, file, artifacts}) { - this.hash = hash - this.file = file - - this.artifacts = mapOf(ImageArtifact, artifacts) - } - - getArtifact(size) { - return this.artifacts.get(size) - } - - findArtifact(sizes) { - for (let size of sizes) { - const a = this.getArtifact(size) - if (a) return a - } - - return null - } - - getPicture(size) { - const retinaSize = ImageArtifactType.retina(size) - - const a = this.getArtifact(size) - const a2 = this.getArtifact(retinaSize) - const srcset = !a2 - ? [] - : [{ - url: a2.url, - density: ImageArtifactType.RETINA_DENSITY, - }] - - return { - src: a.url, - width: a.width, - height: a.height, - set: srcset, - } - } -} - -class ImageArtifact { - constructor({url, size, width, height}) { - this.url = url - this.size = size - this.width = width - this.height = height - } -} - -module.exports = Image diff --git a/src/core/Image.ts b/src/core/Image.ts new file mode 100644 index 00000000..79af86b4 --- /dev/null +++ b/src/core/Image.ts @@ -0,0 +1,81 @@ +import Data from './Data' +import ImageArtifactType from './ImageArtifactType' +import { findOne } from '../lib/store' +import { mapOf } from '../server/lib' + +const store = () => Data.getStore('Image') + +export default class Image { + static async findById(id) { + const data = await findOne(store(), { _id: id }) + if (!data) return null + + const artifacts = data.data + return new Image({ ...data, artifacts }) + } + + static async findByFile(file) { + const data = await findOne(store(), { file }) + if (!data) return null + + const artifacts = data.data + return new Image({ ...data, artifacts }) + } + public hash: any + public file: any + public artifacts: any + + constructor({ hash, file, artifacts }) { + this.hash = hash + this.file = file + + this.artifacts = mapOf(ImageArtifact, artifacts) + } + + getArtifact(size) { + return this.artifacts.get(size) + } + + findArtifact(sizes) { + for (let size of sizes) { + const a = this.getArtifact(size) + if (a) return a + } + + return null + } + + getPicture(size) { + const retinaSize = ImageArtifactType.retina(size) + + const a = this.getArtifact(size) + const a2 = this.getArtifact(retinaSize) + const srcset = !a2 + ? [] + : [{ + url: a2.url, + density: ImageArtifactType.RETINA_DENSITY, + }] + + return { + src: a.url, + width: a.width, + height: a.height, + set: srcset, + } + } +} + +class ImageArtifact { + public url: any + public size: any + public width: any + public height: any + + constructor({ url, size, width, height }) { + this.url = url + this.size = size + this.width = width + this.height = height + } +} diff --git a/src/core/db.ts b/src/core/db.ts index 40adf502..4d30ad8f 100644 --- a/src/core/db.ts +++ b/src/core/db.ts @@ -1,11 +1,11 @@ import Data from './Data' -const Page = require('./Page') -const Article = require('./Article') +import Page from './Page' +import Article from './Article' const Album = require('./Album') const Teacher = require('./Teacher') const Document = require('./Document') const Image = require('./Image') -const Settings = require('./Config') +import Settings from './Config' const getConfig = require('next/config').default const { MongoClient, ObjectId } = require('mongodb') @@ -34,11 +34,12 @@ export function id(i) { } function init(db) { - // Data.setStore('Page', db.collection('pages')) - Data.setStore(Page, db.collection('pages')) - Data.setStore(Article, db.collection('articles')) + console.log('INIT DB') + + Data.setStore('Page', db.collection('pages')) + Data.setStore('Article', db.collection('articles')) Data.setStore(Album, db.collection('albums')) - Data.setStore(Image, db.collection('images')) + Data.setStore('Image', db.collection('images')) Data.setStore(Teacher, db.collection('collective')) Data.setStore(Document, db.collection('documents')) Data.setStore(Settings, db.collection('settings')) diff --git a/src/server/articles.ts b/src/server/articles.ts index 5f1d8285..70131abe 100644 --- a/src/server/articles.ts +++ b/src/server/articles.ts @@ -20,7 +20,7 @@ export async function findArticlesNin(nin, skip, limit, sort) { }) } -export async function findArticles(page, pageSize) { +export async function findArticles(page: number, pageSize: number) { const limit = pageSize const skip = (page - 1) * pageSize diff --git a/src/server/lib.js b/src/server/lib.ts similarity index 83% rename from src/server/lib.js rename to src/server/lib.ts index 49261bd7..898a1080 100644 --- a/src/server/lib.js +++ b/src/server/lib.ts @@ -5,7 +5,7 @@ * @param Class * @param object */ -exports.mapOf = function mapOf(Class, object) { +export function mapOf(Class, object) { return Object .entries(object) .reduce((map, i) => ( From d4f6568269411814eec5a94cd255c45e44404106 Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Tue, 15 Oct 2019 00:24:27 +0300 Subject: [PATCH 028/101] fix ArticleCard to properly works with styled jsx. Image component inlined --- src/components/ArticleCard.jsx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/components/ArticleCard.jsx b/src/components/ArticleCard.jsx index 407120ec..b9c27e0e 100644 --- a/src/components/ArticleCard.jsx +++ b/src/components/ArticleCard.jsx @@ -1,5 +1,5 @@ import React from 'react' -import { Image } from './Image' +import cx from 'classnames' import { dateFormat } from '../lib/date' const Date = ({ children }) => ( @@ -102,11 +102,14 @@ export const ArticleCard = ({ article }) => (
{!article.preview ? null : ( - {article.title} + + {article.title} `${url} ${density}x`)} + /> + )}
From f72652440ec11ddad5ce0f176a1d92f5bb1523fd Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Tue, 15 Oct 2019 00:31:56 +0300 Subject: [PATCH 029/101] make Config working right. Article model looks restored --- src/core/Article.ts | 2 +- src/core/Config.ts | 10 ++++------ src/core/db.ts | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/core/Article.ts b/src/core/Article.ts index bb39d87d..c951dbc6 100644 --- a/src/core/Article.ts +++ b/src/core/Article.ts @@ -124,7 +124,7 @@ async function processArticle(article) { if (previewId) { preview = await Image.findById(previewId) } else { - // preview = await resolveDefaultPreview() + preview = await resolveDefaultPreview() } return new Article({ diff --git a/src/core/Config.ts b/src/core/Config.ts index dd6ca3f0..db3188ff 100644 --- a/src/core/Config.ts +++ b/src/core/Config.ts @@ -1,18 +1,16 @@ import Data from './Data' import { findOne } from '../lib/store' -export default class Config { - static get store() { - return Data.getStore('Settings') - } +const store = () => Data.getStore('Settings') +export default class Config { static async findConfig() { const config = await Config.findById('settings') return config || new Config({} as any) } - static async findById(id) { - const data = await findOne(Config.store, { id }) + static async findById(id: string) { + const data = await findOne(store(), { id }) if (!data) return null return new Config(data) diff --git a/src/core/db.ts b/src/core/db.ts index 4d30ad8f..b3da9561 100644 --- a/src/core/db.ts +++ b/src/core/db.ts @@ -42,7 +42,7 @@ function init(db) { Data.setStore('Image', db.collection('images')) Data.setStore(Teacher, db.collection('collective')) Data.setStore(Document, db.collection('documents')) - Data.setStore(Settings, db.collection('settings')) + Data.setStore('Settings', db.collection('settings')) return db } From bf1fd901335cc868f942d2d52ae248dcc4964d8c Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Tue, 15 Oct 2019 00:35:16 +0300 Subject: [PATCH 030/101] mongodb typings --- package-lock.json | 19 +++++++++++++++++++ package.json | 1 + 2 files changed, 20 insertions(+) diff --git a/package-lock.json b/package-lock.json index 06f00aac..35207942 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1979,6 +1979,15 @@ "@types/node": "*" } }, + "@types/bson": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/@types/bson/-/bson-4.0.0.tgz", + "integrity": "sha512-pq/rqJwJWkbS10crsG5bgnrisL8pML79KlMKQMoQwLUjlPAkrUHMvHJ3oGwE7WHR61Lv/nadMwXVAD2b+fpD8Q==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "@types/connect": { "version": "3.4.32", "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.32.tgz", @@ -2072,6 +2081,16 @@ "integrity": "sha512-FwI9gX75FgVBJ7ywgnq/P7tw+/o1GUbtP0KzbtusLigAOgIgNISRK0ZPl4qertvXSIE8YbsVJueQ90cDt9YYyw==", "dev": true }, + "@types/mongodb": { + "version": "3.3.6", + "resolved": "https://registry.npmjs.org/@types/mongodb/-/mongodb-3.3.6.tgz", + "integrity": "sha512-bPv0lGnkL/iOoA+GSAcS5ad9QyPc/rW547vrF5j+AKX4spaMZgpaCWQ4D6ipVSN6OKuks3ueCFEPinyJJSk2zA==", + "dev": true, + "requires": { + "@types/bson": "*", + "@types/node": "*" + } + }, "@types/node": { "version": "12.7.12", "resolved": "https://registry.npmjs.org/@types/node/-/node-12.7.12.tgz", diff --git a/package.json b/package.json index 8a341663..e7f9e674 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,7 @@ "@babel/register": "^7.0.0-beta.47", "@types/koa": "^2.0.50", "@types/koa-route": "^3.2.4", + "@types/mongodb": "^3.3.6", "@types/node": "^12.7.12", "@types/react": "^16.9.5", "@zeit/next-css": "^1.0.1", From 717540682d1fda505d2e3c6adfb4dc8209e58443 Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Tue, 15 Oct 2019 00:35:27 +0300 Subject: [PATCH 031/101] core Data typings --- src/core/Data.ts | 15 ++++++++------- src/core/Page.ts | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/core/Data.ts b/src/core/Data.ts index 97c44f88..9089302a 100644 --- a/src/core/Data.ts +++ b/src/core/Data.ts @@ -1,17 +1,18 @@ -const db = require('./db') +import { Collection } from 'mongodb' +import * as db from './db' -const store = new Map() +const store = new Map() export default class Data { - static setStore(Class, collection) { - store.set(Class, collection) + static setStore(key: string, collection: Collection) { + store.set(key, collection) } - static getStore(Class) { - return store.get(Class) + static getStore(key: string): Collection { + return store.get(key) } - static getCollection(name) { + static getCollection(name: string): Collection { return db.collection(name) } } diff --git a/src/core/Page.ts b/src/core/Page.ts index 4505bcc1..cdb2cc4f 100644 --- a/src/core/Page.ts +++ b/src/core/Page.ts @@ -3,7 +3,7 @@ import { find as storeFind, findOne, total } from '../lib/store' const Image = require('./Image') const Config = require('./Config') -const store = () => Data.getStore(Page) +const store = () => Data.getStore('Page') export default class Page { static async find(query, options = {}): Promise { From c038ef882b96a2ce5e66313ffdecb3dece35e574 Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Tue, 15 Oct 2019 00:42:35 +0300 Subject: [PATCH 032/101] Data::getStore generic --- src/core/Data.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/Data.ts b/src/core/Data.ts index 9089302a..e32c4103 100644 --- a/src/core/Data.ts +++ b/src/core/Data.ts @@ -8,7 +8,7 @@ export default class Data { store.set(key, collection) } - static getStore(key: string): Collection { + static getStore(key: string): Collection { return store.get(key) } From b0657c7fa43d18f43adca29b66bff1808377ff54 Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Tue, 15 Oct 2019 00:42:47 +0300 Subject: [PATCH 033/101] Article typings improve --- src/core/Article.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/Article.ts b/src/core/Article.ts index c951dbc6..c279f325 100644 --- a/src/core/Article.ts +++ b/src/core/Article.ts @@ -3,7 +3,7 @@ import Image from './Image' import Config from './Config' import { find, findOne, total } from '../lib/store' -const store = () => Data.getStore('Article') +const store = () => Data.getStore
('Article') function make(C) { return x => new C(x) From d1d0011cc9c72b4e25a72db1b234bfbfe80433d2 Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Tue, 15 Oct 2019 00:43:02 +0300 Subject: [PATCH 034/101] Page model fix wrong imports --- src/core/Page.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/Page.ts b/src/core/Page.ts index cdb2cc4f..996cb490 100644 --- a/src/core/Page.ts +++ b/src/core/Page.ts @@ -1,7 +1,7 @@ import Data from './Data' import { find as storeFind, findOne, total } from '../lib/store' -const Image = require('./Image') -const Config = require('./Config') +import Image from './Image' +import Config from './Config' const store = () => Data.getStore('Page') From f48f89ff1b4b4a73c4799a514d86282b47259d6b Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Tue, 15 Oct 2019 00:43:33 +0300 Subject: [PATCH 035/101] server loads all Pages on start as it was before --- src/server.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/server.ts b/src/server.ts index 70b9c687..f6f2fbc9 100644 --- a/src/server.ts +++ b/src/server.ts @@ -18,9 +18,8 @@ app.prepare().then(async () => { process.exit(1) } - // const pages = await Page.find({}) - // const pagesUrls = pages.map(x => x.url) - const pagesUrls = [] + const pages = await Page.find({}) + const pagesUrls = pages.map(x => x.url) const server = new Koa() server.use(async (ctx, next) => { From c48de3e09a2868e524f3410b83e31196fd59d183 Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Tue, 15 Oct 2019 00:47:57 +0300 Subject: [PATCH 036/101] Teacher model moved to typescript. Page can be loaded but looks ugly due to broken styled jsx --- src/core/{Teacher.js => Teacher.ts} | 27 +++++++++++++++++++-------- src/core/db.ts | 2 +- 2 files changed, 20 insertions(+), 9 deletions(-) rename src/core/{Teacher.js => Teacher.ts} (75%) diff --git a/src/core/Teacher.js b/src/core/Teacher.ts similarity index 75% rename from src/core/Teacher.js rename to src/core/Teacher.ts index db6c66a3..b02fe967 100644 --- a/src/core/Teacher.js +++ b/src/core/Teacher.ts @@ -1,12 +1,12 @@ -const Data = require('./Data') -const Image = require('./Image') -const { find, findOne } = require('../lib/store') +import Data from './Data' +import Image from './Image' +import { find, findOne } from '../lib/store' -const store = () => Data.getStore(Teacher) +const store = () => Data.getStore('Teacher') -class Teacher { +export default class Teacher { static async find(query, options = {}) { - const items = await find(store(), query, options) + const items = await find(store(), query, options as any) return Promise.all(items.map(processProfile)) } @@ -18,6 +18,19 @@ class Teacher { return processProfile(data) } + public id: any + public post: any + public file: any + public edu: any + public picture: any + public preview: any + public diploma: any + public position: any + public name: any + public status: any + public hash: any + public url: any + constructor(data) { this.id = data.id this.post = data.post @@ -72,5 +85,3 @@ const processProfile = async profile => { preview, }) } - -module.exports = Teacher diff --git a/src/core/db.ts b/src/core/db.ts index b3da9561..55321851 100644 --- a/src/core/db.ts +++ b/src/core/db.ts @@ -40,7 +40,7 @@ function init(db) { Data.setStore('Article', db.collection('articles')) Data.setStore(Album, db.collection('albums')) Data.setStore('Image', db.collection('images')) - Data.setStore(Teacher, db.collection('collective')) + Data.setStore('Teacher', db.collection('collective')) Data.setStore(Document, db.collection('documents')) Data.setStore('Settings', db.collection('settings')) From 5f637b4097994ae55ee7509eaeec5e21bc3d6689 Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Tue, 15 Oct 2019 01:02:46 +0300 Subject: [PATCH 037/101] PersonCard component fix image --- src/components/PersonCard.jsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/components/PersonCard.jsx b/src/components/PersonCard.jsx index c98b01d1..c6501625 100644 --- a/src/components/PersonCard.jsx +++ b/src/components/PersonCard.jsx @@ -1,4 +1,5 @@ import React from 'react' +import cx from 'classnames' import { Image } from './Image' export const PersonCard = ({ picture, name, url, profile }) => ( @@ -93,10 +94,14 @@ export const PersonCard = ({ picture, name, url, profile }) => (
- + + {''} `${url} ${density}x`)} + /> +
From 873c4ce65caa159b3e0c09f48dd40024ca148429 Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Tue, 15 Oct 2019 01:22:17 +0300 Subject: [PATCH 038/101] Image model findByFile typings improve --- src/core/Image.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/Image.ts b/src/core/Image.ts index 79af86b4..3e1608f2 100644 --- a/src/core/Image.ts +++ b/src/core/Image.ts @@ -14,7 +14,7 @@ export default class Image { return new Image({ ...data, artifacts }) } - static async findByFile(file) { + static async findByFile(file: string) { const data = await findOne(store(), { file }) if (!data) return null From e20636b4f1f1fb6746f421ca2f4db9ef17052a5b Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Tue, 15 Oct 2019 01:22:33 +0300 Subject: [PATCH 039/101] Image component written in ts --- src/components/Image.jsx | 21 ------------------ src/components/Image/index.tsx | 40 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 21 deletions(-) delete mode 100644 src/components/Image.jsx create mode 100644 src/components/Image/index.tsx diff --git a/src/components/Image.jsx b/src/components/Image.jsx deleted file mode 100644 index 7f38d1a2..00000000 --- a/src/components/Image.jsx +++ /dev/null @@ -1,21 +0,0 @@ -import React from 'react' -import className from 'classnames' - -export const Image = ({data, alt, opa = true}) => ( - - - - {alt} `${url} ${density}x`)} - /> - -) - -export default Image \ No newline at end of file diff --git a/src/components/Image/index.tsx b/src/components/Image/index.tsx new file mode 100644 index 00000000..68d75eea --- /dev/null +++ b/src/components/Image/index.tsx @@ -0,0 +1,40 @@ +import * as React from 'react' +import cx from 'classnames' + +export interface IImageProps { + style?: React.CSSProperties + imgStyle?: React.CSSProperties + src: string + alt: string + opa: boolean + set: Array<{ + url: string + density: number + }> +} + +export const Image: React.FC = React.memo(props => { + const srcSet = props.set + .map(({ url, density }) => `${url} ${density}x`) + .join(' ') + + return ( + + + + {props.alt} + + ) +}) From 0ff7d40cb2705ffce65248488a5024e40f6c193a Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Tue, 15 Oct 2019 01:22:46 +0300 Subject: [PATCH 040/101] CollectiveImage component fix --- src/components/CollectiveImage.jsx | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/components/CollectiveImage.jsx b/src/components/CollectiveImage.jsx index 54a3d72d..47fcf719 100644 --- a/src/components/CollectiveImage.jsx +++ b/src/components/CollectiveImage.jsx @@ -1,25 +1,22 @@ import React from 'react' -import Image from './Image' +import { Image } from './Image' export const CollectiveImage = (props) => (
- - {props.data.alt} -
+
) From b5a36e663d572df9033edd2584dc6be075cf9f27 Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Tue, 15 Oct 2019 01:23:06 +0300 Subject: [PATCH 041/101] fix wrong large image path --- pages/collective.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/collective.jsx b/pages/collective.jsx index 05c33d81..b194d5b5 100644 --- a/pages/collective.jsx +++ b/pages/collective.jsx @@ -56,7 +56,7 @@ Page.getInitialProps = wrapInitialProps(async (ctx) => { const title = 'Преподаватели Шлиссельбургской ДХШ' const imageFile = 'Images/HudozkaCollective2017.jpg' const resImage = await requestGet(createApiUrl(ctx.req, `/api/image?file=${imageFile}`), null) - const image = get(resImage, 'data.artifacts.large', null) + const image = get(resImage, 'artifacts.large', null) return { persons, From 011b24e9ae2fe83868292fd972b4f0d2dfec697f Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Tue, 15 Oct 2019 01:23:16 +0300 Subject: [PATCH 042/101] api image clean --- pages/api/image.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/pages/api/image.js b/pages/api/image.js index b7c2d270..d6ef8c08 100644 --- a/pages/api/image.js +++ b/pages/api/image.js @@ -1,11 +1,8 @@ -import { connect } from '../../src/core/db' import Image from '../../src/core/Image' import { encodeImage } from '../../src/api/image' import { withMiddleware } from '../../src/middlewares/withMiddleware' export default withMiddleware(async (req, res) => { - await connect() - const file = req.query.file const image = await Image.findByFile(file) From aa22f882bdc5d69d6d26d562994ea10fef194cd0 Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Tue, 15 Oct 2019 01:23:25 +0300 Subject: [PATCH 043/101] classnames typings --- package-lock.json | 6 ++++++ package.json | 1 + 2 files changed, 7 insertions(+) diff --git a/package-lock.json b/package-lock.json index 35207942..0420604e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1988,6 +1988,12 @@ "@types/node": "*" } }, + "@types/classnames": { + "version": "2.2.9", + "resolved": "https://registry.npmjs.org/@types/classnames/-/classnames-2.2.9.tgz", + "integrity": "sha512-MNl+rT5UmZeilaPxAVs6YaPC2m6aA8rofviZbhbxpPpl61uKodfdQVsBtgJGTqGizEf02oW3tsVe7FYB8kK14A==", + "dev": true + }, "@types/connect": { "version": "3.4.32", "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.32.tgz", diff --git a/package.json b/package.json index e7f9e674..90e1c5a0 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ "@babel/preset-env": "^7.4.5", "@babel/preset-typescript": "^7.6.0", "@babel/register": "^7.0.0-beta.47", + "@types/classnames": "^2.2.9", "@types/koa": "^2.0.50", "@types/koa-route": "^3.2.4", "@types/mongodb": "^3.3.6", From eed3a3c0079e0445ae53df4dbd465b1c2200f96d Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Tue, 15 Oct 2019 01:27:43 +0300 Subject: [PATCH 044/101] Album model to ts --- src/core/Album.js | 65 ----------------------------------------------- src/core/Album.ts | 63 +++++++++++++++++++++++++++++++++++++++++++++ src/core/db.ts | 2 +- 3 files changed, 64 insertions(+), 66 deletions(-) delete mode 100644 src/core/Album.js create mode 100644 src/core/Album.ts diff --git a/src/core/Album.js b/src/core/Album.js deleted file mode 100644 index 010811b0..00000000 --- a/src/core/Album.js +++ /dev/null @@ -1,65 +0,0 @@ -const Data = require('./Data') -const Image = require('./Image') -const ImageArtifactType = require('./ImageArtifactType') -const {find, findOne} = require('../lib/store') - -const previewTypes = [ - ImageArtifactType.SMALL, - ImageArtifactType.MEDIUM, - ImageArtifactType.BIG, - ImageArtifactType.ORIGIN, -] -const store = () => Data.getStore(Album) - -class Album { - static async find(query, options = {}) { - const items = await find(store(), query, options) - - return Promise.all(items.map(processAlbum)) - } - - static async findById(id) { - const item = await findOne(store(), {id}) - - return !item - ? null - : processAlbum(item) - } -} - -const previewFromImage = (imgs = []) => imgs.length - ? imgs[0] - : null - -const processAlbum = async album => { - let preview = {} - // { - // data: [ - // { - // url: null, - // width: 0, - // height: 0, - // } - // ] - // } - - const previewImageId = album.preview ? album.preview : previewFromImage(album.images) - if (previewImageId) { - const image = await Image.findById(previewImageId) - if (image) { - // const imageArtifacts = image.findArtifact(previewTypes) - // if (imageArtifacts) { - // preview = imageArtifacts - // } - preview = image.getPicture(ImageArtifactType.SMALL) - } - } - - return { - ...album, - preview, - url: `/album/${album.id}`, - } -} - -module.exports = Album diff --git a/src/core/Album.ts b/src/core/Album.ts new file mode 100644 index 00000000..d8dad494 --- /dev/null +++ b/src/core/Album.ts @@ -0,0 +1,63 @@ +import Data from './Data' +import Image from './Image' +import ImageArtifactType from './ImageArtifactType' +import { find, findOne } from '../lib/store' + +const previewTypes = [ + ImageArtifactType.SMALL, + ImageArtifactType.MEDIUM, + ImageArtifactType.BIG, + ImageArtifactType.ORIGIN, +] +const store = () => Data.getStore('Album') + +export default class Album { + static async find(query, options = {}) { + const items = await find(store(), query, options as any) + + return Promise.all(items.map(processAlbum)) + } + + static async findById(id) { + const item = await findOne(store(), { id }) + + return !item + ? null + : processAlbum(item) + } +} + +const previewFromImage = (imgs = []) => imgs.length + ? imgs[0] + : null + +const processAlbum = async album => { + let preview = {} + // { + // data: [ + // { + // url: null, + // width: 0, + // height: 0, + // } + // ] + // } + + const previewImageId = album.preview ? album.preview : previewFromImage(album.images) + if (previewImageId) { + const image = await Image.findById(previewImageId) + if (image) { + // const imageArtifacts = image.findArtifact(previewTypes) + // if (imageArtifacts) { + // preview = imageArtifacts + // } + preview = image.getPicture(ImageArtifactType.SMALL) + } + } + + return { + ...album, + preview, + url: `/album/${album.id}`, + } +} diff --git a/src/core/db.ts b/src/core/db.ts index 55321851..7770ed1a 100644 --- a/src/core/db.ts +++ b/src/core/db.ts @@ -38,7 +38,7 @@ function init(db) { Data.setStore('Page', db.collection('pages')) Data.setStore('Article', db.collection('articles')) - Data.setStore(Album, db.collection('albums')) + Data.setStore('Album', db.collection('albums')) Data.setStore('Image', db.collection('images')) Data.setStore('Teacher', db.collection('collective')) Data.setStore(Document, db.collection('documents')) From ed9dae3760b2fb0b48a6f995ea169ae564502258 Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Tue, 15 Oct 2019 02:12:56 +0300 Subject: [PATCH 045/101] documents page fixed --- pages/{documents.jsx => documents.tsx} | 49 +++++++++++++++-------- pages/index.tsx | 2 +- src/components/DocumentList.js | 18 --------- src/components/DocumentList/index.tsx | 22 ++++++++++ src/components/DocumentListItem.js | 23 ----------- src/components/DocumentListItem/index.tsx | 30 ++++++++++++++ src/core/{Document.js => Document.ts} | 28 +++++++++---- src/core/db.ts | 2 +- src/lib/file.js | 27 ------------- src/lib/file.ts | 23 +++++++++++ src/{next-lib.js => next-lib.ts} | 10 +++-- src/types.ts | 9 +++++ src/utils/{common.js => common.ts} | 18 +++++---- 13 files changed, 156 insertions(+), 105 deletions(-) rename pages/{documents.jsx => documents.tsx} (74%) delete mode 100644 src/components/DocumentList.js create mode 100644 src/components/DocumentList/index.tsx delete mode 100644 src/components/DocumentListItem.js create mode 100644 src/components/DocumentListItem/index.tsx rename src/core/{Document.js => Document.ts} (68%) delete mode 100644 src/lib/file.js create mode 100644 src/lib/file.ts rename src/{next-lib.js => next-lib.ts} (81%) create mode 100644 src/types.ts rename src/utils/{common.js => common.ts} (82%) diff --git a/pages/documents.jsx b/pages/documents.tsx similarity index 74% rename from pages/documents.jsx rename to pages/documents.tsx index 618a6c9c..97e82696 100644 --- a/pages/documents.jsx +++ b/pages/documents.tsx @@ -5,12 +5,19 @@ import { Meta } from '../src/components/Meta' import menuModel from '../src/models/menu' import { buildMenu } from '../src/lib/menu' import { meta } from '../src/lib/meta' +import { IDocument } from '../src/types' -import DocumentList from '../src/components/DocumentList' +import { DocumentList } from '../src/components/DocumentList' import { unique } from '../src/utils/common' -import { createApiUrl, requestGet, wrapInitialProps } from '../src/next-lib' +import { createApiUrl, requestGet, wrapInitialProps, IResponseItems } from '../src/next-lib' +import { NextPage } from 'next' -function getSorted(documents) { +interface IDocumentCategory { + name: string + items: IDocument[] +} + +function getSorted(documents: IDocument[]): IDocumentCategory[] { const compose = (...fns) => value => fns .map(fn => fn) .reverse() @@ -23,7 +30,7 @@ function getSorted(documents) { const subtract = (a, b) => a - b - const uniqueCategories = unique(i => i.category) + const uniqueCategories = unique(i => i.category) const priority = { 'Основные документы': [ @@ -53,13 +60,16 @@ function getSorted(documents) { 'Документы для поступления', ] - const sortBy = fn => (a, b) => [a, b] - .map(fn) - .reduce(subtract) + function sortBy(fn: (value: T) => number): (a: T, b: T) => number { + return (a, b) => [a, b].map(fn).reduce(subtract) + } - const getPriorityFn = (m, list) => value => list.includes(value) - ? list.indexOf(value) - : m + function getPriorityFn(m: number, list: T[]): (value: T) => number { + return (value: T) => { + const has = list.includes(value) + return has ? list.indexOf(value) : m + } + } const safeSelect = (d, store, key) => key in store ? store[key] @@ -84,7 +94,14 @@ function getSorted(documents) { }], []) } -const Page = (props) => ( +interface IProps { + collections: IDocumentCategory[] + pageUrl: string + title: string + meta: any +} + +const Page: NextPage = props => ( (
- {props.collections.map(({ name, items }, index) => ( + {props.collections.map((collection, index) => ( ))}
@@ -109,8 +126,8 @@ const Page = (props) => ( Page.getInitialProps = wrapInitialProps(async (ctx) => { const pageUrl = '/documents' - const res = await requestGet(createApiUrl(ctx.req, '/api/files'), {}) - const files = res.items || [] + const res = await requestGet>(createApiUrl(ctx.req, '/api/files'), { items: [] }) + const files = res.items const title = 'Документы' const collections = getSorted(files) diff --git a/pages/index.tsx b/pages/index.tsx index df3e7fa4..af7215cc 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -36,7 +36,7 @@ Page.getInitialProps = wrapInitialProps(async (ctx) => { const pageUrl = '/' const page = 1 const pageSize = ctx.query.pageSize || 15 - const res = await requestGet(createApiUrl(ctx.req, `/api/articles?page=${page}&pageSize=${pageSize}`), {}) + const res = await requestGet(createApiUrl(ctx.req, `/api/articles?page=${page}&pageSize=${pageSize}`), {}) as any const articles = res.items || [] const nextPage = res.nextPage const prevPage = res.prevPage diff --git a/src/components/DocumentList.js b/src/components/DocumentList.js deleted file mode 100644 index bc33069d..00000000 --- a/src/components/DocumentList.js +++ /dev/null @@ -1,18 +0,0 @@ -const React = require('react') -const Document = require('./DocumentListItem') - -const DocumentList = ({documents, name}) => ( -
-
-

{name}

-
- -
- {documents.map((d, i) => ( - - ))} -
-
-) - -module.exports = DocumentList diff --git a/src/components/DocumentList/index.tsx b/src/components/DocumentList/index.tsx new file mode 100644 index 00000000..541e1d12 --- /dev/null +++ b/src/components/DocumentList/index.tsx @@ -0,0 +1,22 @@ +import * as React from 'react' +import { IDocument } from '../../types' +import { DocumentListItem } from '../DocumentListItem' + +export interface IDocumentListProps { + documents: IDocument[] + name: string +} + +export const DocumentList: React.FC = props => ( +
+
+

{props.name}

+
+ +
+ {props.documents.map((d, i) => ( + + ))} +
+
+) diff --git a/src/components/DocumentListItem.js b/src/components/DocumentListItem.js deleted file mode 100644 index 21ef96d2..00000000 --- a/src/components/DocumentListItem.js +++ /dev/null @@ -1,23 +0,0 @@ -const React = require('react') -const {ext, size} = require('../lib/file') -const {titleCase} = require('../lib/string') - -const Document = ({title, url, imageUrl, fileUrl, fileName, fileSize}) => ( -
-) - -module.exports = Document diff --git a/src/components/DocumentListItem/index.tsx b/src/components/DocumentListItem/index.tsx new file mode 100644 index 00000000..04090a36 --- /dev/null +++ b/src/components/DocumentListItem/index.tsx @@ -0,0 +1,30 @@ +import * as React from 'react' +import { ext, size } from '../../lib/file' +import { titleCase } from '../../lib/string' + +export interface IDocumentListItemProps { + title: string + url: string + imageUrl: string + fileUrl: string + fileName: string + fileSize: number +} + +export const DocumentListItem: React.FC = props => ( + +) diff --git a/src/core/Document.js b/src/core/Document.ts similarity index 68% rename from src/core/Document.js rename to src/core/Document.ts index 27e9e558..6c19aae1 100644 --- a/src/core/Document.js +++ b/src/core/Document.ts @@ -1,12 +1,12 @@ -const Data = require('./Data') -const Image = require('./Image') -const { find, findOne } = require('../lib/store') +import Data from './Data' +import Image from './Image' +import { find, findOne } from '../lib/store' -const store = () => Data.getStore(Document) +const store = () => Data.getStore('Document') -class Document { +export default class Document { static async find(query, options = {}) { - const items = await find(store(), query, options) + const items = await find(store(), query, options as any) return Promise.all(items.map(processDocument)) } @@ -18,6 +18,17 @@ class Document { return processDocument(data) } + public id: any + public hash: any + public file: any + public fileInfo: any + public type: any + public title: any + public category: any + public url: any + public preview: any + public viewUrl: any + constructor(data) { this.id = data.id this.hash = data.hash @@ -37,6 +48,9 @@ class Document { } class DocumentFile { + public name: any + public size: any + constructor(data) { this.name = data.name this.size = data.size @@ -52,5 +66,3 @@ const processDocument = async data => { preview, }) } - -module.exports = Document diff --git a/src/core/db.ts b/src/core/db.ts index 7770ed1a..4c4b5acb 100644 --- a/src/core/db.ts +++ b/src/core/db.ts @@ -41,7 +41,7 @@ function init(db) { Data.setStore('Album', db.collection('albums')) Data.setStore('Image', db.collection('images')) Data.setStore('Teacher', db.collection('collective')) - Data.setStore(Document, db.collection('documents')) + Data.setStore('Document', db.collection('documents')) Data.setStore('Settings', db.collection('settings')) return db diff --git a/src/lib/file.js b/src/lib/file.js deleted file mode 100644 index 4079f9b8..00000000 --- a/src/lib/file.js +++ /dev/null @@ -1,27 +0,0 @@ -function ext(filname) { - let getExt = name => /\.(\w+)$/.exec(name)[1] - let defaultExt = ext => ext.toUpperCase() - - const exts = ['png', 'pdf', 'jpg', 'jpeg', 'gif', 'doc'] - const extd = ['ПНГ', 'ПДФ', 'ЖПГ', 'ЖПГ', 'ГИФ', 'ДОК'] - - let ext = getExt(filname) - const i = exts.indexOf(ext) - - return i > -1 - ? extd[i] - : defaultExt(ext) -} - -function size(bytes, precision = 1) { - if (isNaN(parseFloat(bytes)) || !isFinite(bytes)) return '' - - const units = ['байт', 'КБ', 'МБ', 'ГБ', 'ТБ', 'ПБ'] - const number = Math.floor(Math.log(bytes) / Math.log(1024)) - - const size = (bytes / Math.pow(1024, Math.floor(number))).toFixed(precision) - return `${size} ${units[number]}` -} - -exports.ext = ext -exports.size = size diff --git a/src/lib/file.ts b/src/lib/file.ts new file mode 100644 index 00000000..504cc26d --- /dev/null +++ b/src/lib/file.ts @@ -0,0 +1,23 @@ +const getExt = (name: string) => /\.(\w+)$/.exec(name)[1] +const defaultExt = (ext: string) => ext.toUpperCase() +const exts = ['png', 'pdf', 'jpg', 'jpeg', 'gif', 'doc'] +const extd = ['ПНГ', 'ПДФ', 'ЖПГ', 'ЖПГ', 'ГИФ', 'ДОК'] +const units = ['байт', 'КБ', 'МБ', 'ГБ', 'ТБ', 'ПБ'] + +export function ext(filname: string): string { + const ext = getExt(filname) + const i = exts.indexOf(ext) + + return i > -1 + ? extd[i] + : defaultExt(ext) +} + +export function size(bytes: any, precision = 1): string { + if (isNaN(parseFloat(bytes)) || !isFinite(bytes)) return '' + + const number = Math.floor(Math.log(bytes) / Math.log(1024)) + const size = (bytes / Math.pow(1024, Math.floor(number))).toFixed(precision) + + return `${size} ${units[number]}` +} diff --git a/src/next-lib.js b/src/next-lib.ts similarity index 81% rename from src/next-lib.js rename to src/next-lib.ts index 3694918b..626adb36 100644 --- a/src/next-lib.js +++ b/src/next-lib.ts @@ -1,8 +1,12 @@ import axios from 'axios' -export async function requestGet(url, defaultResponse) { +export interface IResponseItems { + items: T[] +} + +export async function requestGet(url: string, defaultResponse: T): Promise { try { - const res = await axios.get(url) + const res = await axios.get(url) return res.data } catch (e) { @@ -19,7 +23,7 @@ export async function requestGet(url, defaultResponse) { export function wrapInitialProps(fn) { return async ctx => { if (process.env.NODE_ENV === 'production' && process.browser) { - return __NEXT_DATA__.props.pageProps; + return window['__NEXT_DATA__'].props.pageProps; } return fn(ctx) diff --git a/src/types.ts b/src/types.ts new file mode 100644 index 00000000..cd3580e1 --- /dev/null +++ b/src/types.ts @@ -0,0 +1,9 @@ +export interface IDocument { + category: string + fileName: string + fileSize: number + fileUrl: string + imageUrl: string + title: string + url: string +} diff --git a/src/utils/common.js b/src/utils/common.ts similarity index 82% rename from src/utils/common.js rename to src/utils/common.ts index ee15c886..a2ec4754 100644 --- a/src/utils/common.js +++ b/src/utils/common.ts @@ -40,7 +40,7 @@ export function indexEquals(withNumber) { * @param map */ export function select(byCondition, map = i => i) { - return (result, item) => byCondition(item) ? map(item): map(result) + return (result, item) => byCondition(item) ? map(item) : map(result) } /** @@ -49,19 +49,21 @@ export function select(byCondition, map = i => i) { * @param selector * @returns {*} */ -export function choise(scope, selector){ +export function choise(scope, selector) { return scope.reduce(selector, null); } -export function unique(fn) { - return list => [...new Set(list.map(fn))]; +export function unique(fn: (value: T) => U): (list: T[]) => U[] { + return list => Array.from( + new Set(list.map(fn)) + ) } export function branch(fn) { let keys = unique(fn); return list => keys(list) - .reduce((dict, key) => { + .reduce((dict: any, key: any) => { dict[key] = list.filter( i => fn(i) === key ); @@ -71,7 +73,7 @@ export function branch(fn) { } -export function assign(dict, key, value){ +export function assign(dict, key, value) { dict[key] = value; return dict; } @@ -88,7 +90,7 @@ export function map(v, fn) { * @param selector * @returns {*} */ -export function createMap(selector, list){ +export function createMap(selector, list) { return list.reduce((map, i) => map.set(selector(i), i), new Map()); } @@ -99,6 +101,6 @@ export function createMap(selector, list){ * @param {function} fn * @returns {function(*=): null} */ -export function nullSafe(fn){ +export function nullSafe(fn) { return i => i ? fn(i) : null; } From 9b642a38ce7d40973735ebbae43e6a2d38f5d96c Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Tue, 15 Oct 2019 02:21:02 +0300 Subject: [PATCH 046/101] main scss format --- src/style/main.scss | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/src/style/main.scss b/src/style/main.scss index b2fb398d..5d9b8853 100644 --- a/src/style/main.scss +++ b/src/style/main.scss @@ -1,44 +1,45 @@ * { - margin: 0; - padding: 0; + margin: 0; + padding: 0; } -html, body { - height: 100%; +html, +body { + height: 100%; } body { - min-width: 320px; + min-width: 320px; - color: var(--text-color); + color: var(--text-color); } h1 { - text-align: center; - font-size: var(--font-size-h1); + text-align: center; + font-size: var(--font-size-h1); - hyphens: none; + hyphens: none; } -h2{ - margin: var(--single-margin) 0; - font-size: var(--font-size-h2); +h2 { + margin: var(--single-margin) 0; + font-size: var(--font-size-h2); - hyphens: none; + hyphens: none; } -h3{ - margin: var(--single-margin) 0; +h3 { + margin: var(--single-margin) 0; - font-size: var(--font-size-h3); + font-size: var(--font-size-h3); - hyphens: none; + hyphens: none; } .actor { - border-bottom: 1px dashed black; + border-bottom: 1px dashed black; - &:hover { - border-bottom: 2px solid black; - } -} \ No newline at end of file + &:hover { + border-bottom: 2px solid black; + } +} From a6e528d59b555afc36440c22c40ee7865c666fc1 Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Tue, 15 Oct 2019 02:26:55 +0300 Subject: [PATCH 047/101] variables scss format --- src/style/variables.scss | 140 +++++++++++++++++++-------------------- 1 file changed, 69 insertions(+), 71 deletions(-) diff --git a/src/style/variables.scss b/src/style/variables.scss index 45cb8574..c7a0baa4 100644 --- a/src/style/variables.scss +++ b/src/style/variables.scss @@ -1,94 +1,92 @@ :root { - //SHADOW - --white-shadow: 0 .1em 0.3em rgba(0, 0, 0, 0.2); + //SHADOW + --white-shadow: 0 0.1em 0.3em rgba(0, 0, 0, 0.2); - //FONTS - --title-font: "PT Serif", Georgia, serif; - --text-font: "PT Sans", Arial, sans-serif; + //FONTS + --title-font: 'PT Serif', Georgia, serif; + --text-font: 'PT Sans', Arial, sans-serif; - --smaller-font-size: 0.9rem; - --normal-font-size: 1.0rem; - --bigger-font-size: 1.2rem; - --big-font-size: 1.5rem; - --biggest-font-size: 2.25rem; + --smaller-font-size: 0.9rem; + --normal-font-size: 1rem; + --bigger-font-size: 1.2rem; + --big-font-size: 1.5rem; + --biggest-font-size: 2.25rem; - //MENU - --menu-thickness: 2.5em; - --menu-colored-mark-thickness: 4px; - --menu-inactive-item-color: hsl(0, 0%, 50%); + //MENU + --menu-thickness: 2.5em; + --menu-colored-mark-thickness: 4px; + --menu-inactive-item-color: hsl(0, 0%, 50%); - //ANIMATION - $short-duration: 0.3s; + //ANIMATION + $short-duration: 0.3s; - //SIZE - --mobile-width: 31.25em; - --desktop-width: 59.99999em; + //SIZE + --mobile-width: 31.25em; + --desktop-width: 59.99999em; - --tablet-min-width: 31.25em; - --tablet-max-width: 64em; + --tablet-min-width: 31.25em; + --tablet-max-width: 64em; - --content-full: 100%; - --content-wide: 90%; - --content-semi-wide: 70%; - --content-thin: 60%; + --content-full: 100%; + --content-wide: 90%; + --content-semi-wide: 70%; + --content-thin: 60%; - --embed-video-ratio: 56.25%; + --embed-video-ratio: 56.25%; - --text-color: #303030; - --text-color-second: #ccc; + --text-color: #303030; + --text-color-second: #ccc; - //FONTS - --font-size-default: 14pt; - --font-size-second: 0.9rem; + //FONTS + --font-size-default: 14pt; + --font-size-second: 0.9rem; - --font-size-h1: 3.0rem; - --font-size-h2: 2.0rem; - --font-size-h3: 1.5rem; + --font-size-h1: 3rem; + --font-size-h2: 2rem; + --font-size-h3: 1.5rem; - //COLOR - --dark-color: hsl(0, 0%, 20%); - --darker-color: hsl(0, 0%, 10%); - --light-color: hsl(0, 0%, 80%); - --lighter-color: hsl(0, 0%, 100%); - --link-color: hsl(0, 0%, 80%); + //COLOR + --dark-color: hsl(0, 0%, 20%); + --darker-color: hsl(0, 0%, 10%); + --light-color: hsl(0, 0%, 80%); + --lighter-color: hsl(0, 0%, 100%); + --link-color: hsl(0, 0%, 80%); - --blue-color: rgb(63, 156, 234); - --orange-color: rgb(240, 160, 65); - --green-color: rgb(92, 190, 64); - --yellow-color: rgb(255, 238, 0); - --pink-color: rgb(246, 85, 160); - --magenta-color: rgb(214, 39, 246); - --red-color: rgb(246, 27, 20); - --gray-color: rgb(153, 154, 160); + --blue-color: rgb(63, 156, 234); + --orange-color: rgb(240, 160, 65); + --green-color: rgb(92, 190, 64); + --yellow-color: rgb(255, 238, 0); + --pink-color: rgb(246, 85, 160); + --magenta-color: rgb(214, 39, 246); + --red-color: rgb(246, 27, 20); + --gray-color: rgb(153, 154, 160); - --inactive-link-color: var(--light-color); + --inactive-link-color: var(--light-color); - --schedule-row-color: hsl(210, 55%, 90%); + --schedule-row-color: hsl(210, 55%, 90%); + //MARGINS + --small-margin: 0.2em; + --half-margin: 0.5em; + --single-margin: 1em; + --double-margin: 2em; + --post-margin: 5em; - - //MARGINS - --small-margin: .2em; - --half-margin: .5em; - --single-margin: 1.0em; - --double-margin: 2.0em; - --post-margin: 5.0em; - - //OTHER - --block-border-radius: 3px; + //OTHER + --block-border-radius: 3px; } @media (max-width: var(--mobile-width)) { - :root { - //FONTS - --smaller-font-size: 0.9rem; - --normal-font-size: 1.0rem; - --bigger-font-size: 1.1rem; - --big-font-size: 1.3rem; - --biggest-font-size: 2.0rem; + :root { + //FONTS + --smaller-font-size: 0.9rem; + --normal-font-size: 1rem; + --bigger-font-size: 1.1rem; + --big-font-size: 1.3rem; + --biggest-font-size: 2rem; - --font-size-h1: 1.75rem; - --font-size-h2: 1.50rem; - --font-size-h3: 1.25rem; - } + --font-size-h1: 1.75rem; + --font-size-h2: 1.5rem; + --font-size-h3: 1.25rem; + } } From 5d672842f364435c85ff3bc9d9c3206240034b15 Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Tue, 15 Oct 2019 02:46:41 +0300 Subject: [PATCH 048/101] mobile style variables --- pages/_app.tsx | 36 ++++++++++++++++++++++++++++++++++++ src/style/variables.scss | 15 --------------- 2 files changed, 36 insertions(+), 15 deletions(-) create mode 100644 pages/_app.tsx diff --git a/pages/_app.tsx b/pages/_app.tsx new file mode 100644 index 00000000..76a2ef98 --- /dev/null +++ b/pages/_app.tsx @@ -0,0 +1,36 @@ +import React from 'react' +import App, { Container } from 'next/app' + +class MyApp extends App { + render() { + const { Component, pageProps } = this.props + + return ( + + + + + + ) + } +} + +export default MyApp \ No newline at end of file diff --git a/src/style/variables.scss b/src/style/variables.scss index c7a0baa4..6dec6c08 100644 --- a/src/style/variables.scss +++ b/src/style/variables.scss @@ -75,18 +75,3 @@ //OTHER --block-border-radius: 3px; } - -@media (max-width: var(--mobile-width)) { - :root { - //FONTS - --smaller-font-size: 0.9rem; - --normal-font-size: 1rem; - --bigger-font-size: 1.1rem; - --big-font-size: 1.3rem; - --biggest-font-size: 2rem; - - --font-size-h1: 1.75rem; - --font-size-h2: 1.5rem; - --font-size-h3: 1.25rem; - } -} From cc32215fddb6114662c4fb09c3e4308d4ea8001f Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Tue, 15 Oct 2019 02:51:15 +0300 Subject: [PATCH 049/101] ArticleCard component style fix + ts --- .../{ArticleCard.jsx => ArticleCard/index.tsx} | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) rename src/components/{ArticleCard.jsx => ArticleCard/index.tsx} (92%) diff --git a/src/components/ArticleCard.jsx b/src/components/ArticleCard/index.tsx similarity index 92% rename from src/components/ArticleCard.jsx rename to src/components/ArticleCard/index.tsx index b9c27e0e..1d364e38 100644 --- a/src/components/ArticleCard.jsx +++ b/src/components/ArticleCard/index.tsx @@ -1,13 +1,17 @@ import React from 'react' import cx from 'classnames' -import { dateFormat } from '../lib/date' +import { dateFormat } from '../../lib/date' const Date = ({ children }) => (

{dateFormat(children)}

) -export const ArticleCard = ({ article }) => ( -
+export interface IArticleCardProps { + article: any +} + +export const ArticleCard: React.FC = ({ article }) => ( +
+ + +
+ ) +} diff --git a/src/style/hmenu.scss b/src/style/hmenu.scss index 789742c4..31a11604 100644 --- a/src/style/hmenu.scss +++ b/src/style/hmenu.scss @@ -58,53 +58,7 @@ -.HMenu__toggle { - position: absolute; - left: 0; - height: var(--hmenu-icon-height); - margin: var(--hmenu-margin); - - display: flex; - - a { - text-decoration: none; - border: none; - - width: var(--hmenu-icon-width); - height: var(--hmenu-icon-height); - background-size: 100%; - } - - a:hover { - text-decoration: none; - border: none; - } -} - -.HMenu--folded.HMenu--closed { - .HMenu__toggle { - a { - background-image: url(/graphics/hmenu-b.png); - } - - a:hover { - background-image: url(/graphics/hmenu-hover-b.png); - } - } -} - -.HMenu--folded.HMenu--open { - .HMenu__toggle { - a { - background-image: url(/graphics/hmenu-close-b.png); - } - - a:hover { - background-image: url(/graphics/hmenu-close-hover-b.png); - } - } -} diff --git a/src/assets/graphics/hmenu-b.png b/static/graphics/hmenu-b.png similarity index 100% rename from src/assets/graphics/hmenu-b.png rename to static/graphics/hmenu-b.png diff --git a/src/assets/graphics/hmenu-close-b.png b/static/graphics/hmenu-close-b.png similarity index 100% rename from src/assets/graphics/hmenu-close-b.png rename to static/graphics/hmenu-close-b.png diff --git a/src/assets/graphics/hmenu-close-hover-b.png b/static/graphics/hmenu-close-hover-b.png similarity index 100% rename from src/assets/graphics/hmenu-close-hover-b.png rename to static/graphics/hmenu-close-hover-b.png diff --git a/src/assets/graphics/hmenu-hover-b.png b/static/graphics/hmenu-hover-b.png similarity index 100% rename from src/assets/graphics/hmenu-hover-b.png rename to static/graphics/hmenu-hover-b.png From ab577fa263cd2ae3711c31918d5c51d558e1a33a Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Tue, 15 Oct 2019 04:39:20 +0300 Subject: [PATCH 053/101] Menu update. Use react hooks, not client based script. --- package-lock.json | 5 ++ package.json | 3 +- pages/_document.jsx | 2 - src/components/Menu/MenuToggle.tsx | 34 +++++--- src/components/Menu/index.tsx | 67 +++++++++++----- src/hooks/useScreenType.ts | 15 ++++ static/app.js | 124 ----------------------------- 7 files changed, 94 insertions(+), 156 deletions(-) create mode 100644 src/hooks/useScreenType.ts delete mode 100644 static/app.js diff --git a/package-lock.json b/package-lock.json index 0420604e..a8851f08 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16128,6 +16128,11 @@ } } }, + "use-media": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/use-media/-/use-media-1.4.0.tgz", + "integrity": "sha512-XsgyUAf3nhzZmEfhc5MqLHwyaPjs78bgytpVJ/xDl0TF4Bptf3vEpBNBBT/EIKOmsOc8UbuECq3mrP3mt1QANA==" + }, "util": { "version": "0.10.3", "resolved": "https://registry.npmjs.org/util/-/util-0.10.3.tgz", diff --git a/package.json b/package.json index 90e1c5a0..47399832 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,8 @@ "redux-thunk": "^2.2.0", "request-promise": "^2.0.1", "sitemap": "^1.5.0", - "thunkify": "^2.1.2" + "thunkify": "^2.1.2", + "use-media": "^1.4.0" }, "devDependencies": { "@babel/cli": "^7.4.4", diff --git a/pages/_document.jsx b/pages/_document.jsx index 09b8725c..cfd2420d 100644 --- a/pages/_document.jsx +++ b/pages/_document.jsx @@ -63,8 +63,6 @@ export default class MyDocument extends Document {
- -