From 263f18a1df0cbce854647e63a8d3431ba0651b9e Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Sat, 29 Feb 2020 01:04:28 +0300 Subject: [PATCH] drop documents page (now it is a regular page) --- pages/documents.tsx | 138 -------------------------- scripts/sitemap.js | 1 - src/components/DocumentList/index.tsx | 22 ---- src/types.ts | 2 +- src/utils/common.ts | 20 ---- 5 files changed, 1 insertion(+), 182 deletions(-) delete mode 100644 pages/documents.tsx delete mode 100644 src/components/DocumentList/index.tsx diff --git a/pages/documents.tsx b/pages/documents.tsx deleted file mode 100644 index 12c1f8c6..00000000 --- a/pages/documents.tsx +++ /dev/null @@ -1,138 +0,0 @@ -import Head from 'next/head' -import { App } from 'src/components/App' -import { Meta } from 'src/components/Meta' -import { meta } from 'src/lib/meta' -import { IDocument } from 'src/types' -import { DocumentList } from 'src/components/DocumentList' -import { unique } from 'src/utils/common' -import { createApiUrl, requestGet, IResponseItems } from 'src/next-lib' -import { NextPage } from 'next' - -interface IDocumentCategory { - name: string - items: IDocument[] -} - -function getSorted(documents: IDocument[]): IDocumentCategory[] { - const compose = (...fns) => value => fns - .map(fn => fn) - .reverse() - .reduce((acc, fn) => fn(acc), value) - - const pass = fn => value => { - fn(value) - return value - } - - const subtract = (a, b) => a - b - - const uniqueCategories = unique(i => i.category) - - const priority = { - 'Основные документы': [ - 'https://static.shlisselburg.org/art/uploads/ustav-2015.pdf', - 'https://static.shlisselburg.org/art/uploads/obrazovatelnaia-litsenziia-2015.pdf', - 'https://static.shlisselburg.org/art/uploads/svidetelstvo-na-pomeshchenie.pdf', - 'https://static.shlisselburg.org/art/uploads/egriul.pdf', - 'https://static.shlisselburg.org/art/uploads/inn.pdf', - 'https://static.shlisselburg.org/art/uploads/reshenie-o-sozdanii-shkoly.pdf', - 'https://static.shlisselburg.org/art/uploads/kopiia-resheniia-o-naznachenii-rukovoditelia.pdf', - 'https://static.shlisselburg.org/art/uploads/postanovlenie-o-sozdanii-munitsipalnogo-obrazovatelnogo-uchrezhdeniia-kultury-detskaia-khudozhestvennaia-shkola.pdf', - ], - 'Учебные программы': [ - 'https://static.shlisselburg.org/art/uploads/uchebnaia-programma-zhivopis.pdf', - ] - } - - const CATEGORY_PRIORITY = [ - 'Основные документы', - 'Планы ФХД', - 'Самообследование деятельности', - 'Инструкции', - 'Образование', - 'Учебные программы', - 'Платные образовательные услуги', - 'Дополнительные общеразвивающие программы', - 'Документы для поступления', - ] - - function sortBy(fn: (value: T) => number): (a: T, b: T) => number { - return (a, b) => [a, b].map(fn).reduce(subtract) - } - - 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] - : d - - const categoryPriority = getPriorityFn(10000, CATEGORY_PRIORITY) - - const documentPriority = ({ category, fileUrl }) => compose( - getPriorityFn.bind(null, 10000), - safeSelect.bind(null, [], priority) - )(category)(fileUrl) - - const documentsOf = category => documents.filter(i => i.category === category) - const sorted = documents => documents.sort(sortBy(documentPriority)) - const collectDocumentsByCategory = compose(sorted, documentsOf) - - return uniqueCategories(documents) - .sort(sortBy(categoryPriority)) - .reduce((acc, name) => [...acc, { - name, - items: collectDocumentsByCategory(name) - }], []) -} - -interface IProps { - collections: IDocumentCategory[] - title: string - meta: any -} - -const Page: NextPage = props => ( - - - {props.title} - - - -

{props.title}

- - {props.collections.map((collection, index) => ( - - ))} -
-) - -export const unstable_getStaticProps = async (ctx) => { - const res = await requestGet>(createApiUrl('/api/files'), null) - const files = res.items - const title = 'Документы' - const collections = getSorted(files) - - return { - props: { - collections, - title, - meta: meta({ - title, - description: 'Документы Шлиссельбургской ДХШ', - }) - } - } -} - -export default Page diff --git a/scripts/sitemap.js b/scripts/sitemap.js index 23b1d96a..ad704d64 100644 --- a/scripts/sitemap.js +++ b/scripts/sitemap.js @@ -12,7 +12,6 @@ async function getMenuUrls(frequency = 'daily') { const menu = [ '/', '/schedule', - '/documents', '/collective', ] return menu diff --git a/src/components/DocumentList/index.tsx b/src/components/DocumentList/index.tsx deleted file mode 100644 index 541e1d12..00000000 --- a/src/components/DocumentList/index.tsx +++ /dev/null @@ -1,22 +0,0 @@ -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/types.ts b/src/types.ts index baf86823..7fe64ce1 100644 --- a/src/types.ts +++ b/src/types.ts @@ -20,7 +20,7 @@ export interface IPage { } export interface IDocument { - category: string + // category: string fileName: string fileSize: number fileUrl: string diff --git a/src/utils/common.ts b/src/utils/common.ts index 00920c56..b06647d2 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -36,26 +36,6 @@ export function choise(scope, selector) { return scope.reduce(selector, null); } -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: any, key: any) => { - dict[key] = list.filter( - i => fn(i) === key - ); - - return dict; - }, {}) - -} - export function assign(dict, key, value) { dict[key] = value; return dict;