drop documents page (now it is a regular page)
This commit is contained in:
1 parent
55f44fab8c
commit
263f18a1df
5 files changed
+1
-182
No files matched your search
@@ -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<IDocument, string>(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<T>(fn: (value: T) => number): (a: T, b: T) => number {
|
|
||||||
return (a, b) => [a, b].map(fn).reduce(subtract)
|
|
||||||
}
|
|
||||||
|
|
||||||
function getPriorityFn<T>(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<IProps> = props => (
|
|
||||||
<App
|
|
||||||
showAuthor={true}
|
|
||||||
>
|
|
||||||
<Head>
|
|
||||||
<title>{props.title}</title>
|
|
||||||
<Meta meta={props.meta} />
|
|
||||||
</Head>
|
|
||||||
|
|
||||||
<h1>{props.title}</h1>
|
|
||||||
|
|
||||||
{props.collections.map((collection, index) => (
|
|
||||||
<DocumentList
|
|
||||||
key={index}
|
|
||||||
name={collection.name}
|
|
||||||
documents={collection.items}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</App>
|
|
||||||
)
|
|
||||||
|
|
||||||
export const unstable_getStaticProps = async (ctx) => {
|
|
||||||
const res = await requestGet<IResponseItems<IDocument>>(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
|
|
||||||
@@ -12,7 +12,6 @@ async function getMenuUrls(frequency = 'daily') {
|
|||||||
const menu = [
|
const menu = [
|
||||||
'/',
|
'/',
|
||||||
'/schedule',
|
'/schedule',
|
||||||
'/documents',
|
|
||||||
'/collective',
|
'/collective',
|
||||||
]
|
]
|
||||||
return menu
|
return menu
|
||||||
|
|||||||
@@ -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<IDocumentListProps> = props => (
|
|
||||||
<div className="documents-container">
|
|
||||||
<div className="documents-container__head">
|
|
||||||
<h2>{props.name}</h2>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="documents-container__body">
|
|
||||||
{props.documents.map((d, i) => (
|
|
||||||
<DocumentListItem key={i} {...d} />
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
+1
-1
@@ -20,7 +20,7 @@ export interface IPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface IDocument {
|
export interface IDocument {
|
||||||
category: string
|
// category: string
|
||||||
fileName: string
|
fileName: string
|
||||||
fileSize: number
|
fileSize: number
|
||||||
fileUrl: string
|
fileUrl: string
|
||||||
|
|||||||
@@ -36,26 +36,6 @@ export function choise(scope, selector) {
|
|||||||
return scope.reduce(selector, null);
|
return scope.reduce(selector, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function unique<T, U>(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) {
|
export function assign(dict, key, value) {
|
||||||
dict[key] = value;
|
dict[key] = value;
|
||||||
return dict;
|
return dict;
|
||||||
|
|||||||
Reference in new issue
Block a user