mirror of
https://github.com/dzeiocom/markblog.git
synced 2025-07-29 07:59:50 +00:00
Fixed lint errors :D
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
This commit is contained in:
@ -1,57 +1,30 @@
|
||||
import { Component } from 'react'
|
||||
import Element from '../components/Element'
|
||||
import Filters from '../components/Filters'
|
||||
import { Component } from 'react'
|
||||
import Post, { PostHeader } from '../components/Post'
|
||||
|
||||
interface Props {
|
||||
userAgent?: string
|
||||
userAgent?: string
|
||||
}
|
||||
|
||||
interface el extends PostHeader {}
|
||||
|
||||
interface States {
|
||||
elements: el[]
|
||||
elements: Array<PostHeader>
|
||||
loaded: boolean
|
||||
asideHeight: number
|
||||
categories: string[]
|
||||
categories: Array<string>
|
||||
}
|
||||
|
||||
// export const config = {amp: 'hybrid'}
|
||||
|
||||
let elements: PostHeader[] = []
|
||||
let elements: Array<PostHeader> = []
|
||||
|
||||
export default class Page extends Component<Props, States> {
|
||||
|
||||
onQuery = async (query: string, recent: boolean = true) => {
|
||||
// console.log(`query: ${query}`)
|
||||
const t= elements.filter(el => {
|
||||
return el.title.toLowerCase().includes(query.toLowerCase())
|
||||
})
|
||||
if (recent) {
|
||||
t.sort((a, b) => {
|
||||
return (a.date < b.date) ? 1 : -1
|
||||
})
|
||||
} else {
|
||||
t.sort((a, b) => {
|
||||
return (a.date > b.date) ? 1 : -1
|
||||
})
|
||||
}
|
||||
this.setState({
|
||||
elements: t
|
||||
})
|
||||
}
|
||||
|
||||
onHeight = async (height: number) => {
|
||||
this.setState({
|
||||
asideHeight: height
|
||||
})
|
||||
}
|
||||
|
||||
async componentDidMount() {
|
||||
public async componentDidMount() {
|
||||
const posts = await Post.fetchAll()
|
||||
const header: Array<PostHeader> = []
|
||||
let cats: Array<string> = []
|
||||
posts.forEach(el => {
|
||||
const cats: Array<string> = []
|
||||
posts.forEach((el) => {
|
||||
el.fetchSync()
|
||||
header.push(el.header)
|
||||
cats.push(...el.header.tags)
|
||||
@ -64,18 +37,25 @@ export default class Page extends Component<Props, States> {
|
||||
|
||||
elements = header
|
||||
this.setState({
|
||||
categories: cats.filter((item, pos) => cats.indexOf(item) === pos),
|
||||
elements: header,
|
||||
loaded: true,
|
||||
categories: cats.filter((item, pos) => {return cats.indexOf(item) === pos})
|
||||
})
|
||||
}
|
||||
|
||||
render() {
|
||||
public render() {
|
||||
return (
|
||||
<main>
|
||||
<span>
|
||||
{this.state && this.state.elements && this.state.elements.length !== 0 ? this.state.elements.map((el, index) => (
|
||||
<Element key={index} link={"/"+el.category.toLowerCase() + "/" + el.id} title={el.title} image={el.image} alt={el.imageAlt} date={el.date || new Date} />
|
||||
<Element
|
||||
key={index}
|
||||
link={`/${el.category.toLowerCase()}/${el.id}`}
|
||||
title={el.title}
|
||||
image={el.image}
|
||||
alt={el.imageAlt}
|
||||
date={el.date || new Date()}
|
||||
/>
|
||||
)) : this.state && this.state.loaded ? (
|
||||
<div>La recherche n'a rien donnée <span className="emoji">😢</span></div>
|
||||
) : (
|
||||
@ -105,7 +85,7 @@ export default class Page extends Component<Props, States> {
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
@media (min-width: 820px) and (min-height: ${this.state && this.state.asideHeight ? this.state.asideHeight+100 : 600}px) {
|
||||
@media (min-width: 820px) and (min-height: ${this.state && this.state.asideHeight ? this.state.asideHeight + 100 : 600}px) {
|
||||
span {
|
||||
max-width: calc(100% - 400px);
|
||||
}
|
||||
@ -116,7 +96,31 @@ export default class Page extends Component<Props, States> {
|
||||
}
|
||||
`}</style>
|
||||
</main>
|
||||
|
||||
)
|
||||
}
|
||||
|
||||
private async onQuery(query: string, recent: boolean = true) {
|
||||
// console.log(`query: ${query}`)
|
||||
const t = elements.filter( (el) => {
|
||||
return el.title.toLowerCase().includes(query.toLowerCase())
|
||||
})
|
||||
if (recent) {
|
||||
t.sort((a, b) => {
|
||||
return (a.date < b.date) ? 1 : -1
|
||||
})
|
||||
} else {
|
||||
t.sort((a, b) => {
|
||||
return (a.date > b.date) ? 1 : -1
|
||||
})
|
||||
}
|
||||
this.setState({
|
||||
elements: t,
|
||||
})
|
||||
}
|
||||
|
||||
private async onHeight(height: number) {
|
||||
this.setState({
|
||||
asideHeight: height,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user