import React, { PureComponent } from 'react'
import { pathMatchRegexp } from 'utils'
import { SearchCard } from 'components'
import styles from './styles.less'
import * as ycore from 'ycore'
import * as antd from 'antd'
import * as Icons from '@ant-design/icons'
import Icon from '@ant-design/icons'
class SearchPageIndexer extends PureComponent {
constructor(props) {
super(props),
(this.state = {
SearchResult: '',
loading: true,
})
}
toogleLoading() {
this.setState({ loading: !this.state.loading })
}
componentDidMount() {
try {
const { location } = this.props
const matchSearch = pathMatchRegexp('/s/:id', location.pathname)
const parsed = matchSearch.shift()
const raw = parsed.toString()
const string = raw.replace('/s/', '')
const payload = { key: string }
ycore.comty_search.keywords((err, res) => {
if (err) {
ycore.notify.error(err)
}
ycore.yconsole.log('Founded entries => ', JSON.parse(res))
this.setState({ SearchResult: res })
this.toogleLoading()
}, payload)
} catch (err) {
ycore.notify.error(err)
}
}
renderResult = source => {
try {
const Empty = (
)
// TO DO: Settings serach & Post Search
const usersParsed = JSON.parse(source)['users']
const groupsParsed = JSON.parse(source)['groups']
const pagesParsed = JSON.parse(source)['pages']
const users = () => {
if (usersParsed.length >= 1) {
console.log('Users => ', usersParsed)
return this.EntryComponent('Users', usersParsed)
}
}
const groups = () => {
if (groupsParsed.length >= 1) {
console.log('Groups => ', groupsParsed)
return this.EntryComponent('Groups', groupsParsed)
}
}
const pages = () => {
if (pagesParsed.length >= 1) {
console.log('Pages => ', pagesParsed)
return this.EntryComponent('Pages', pagesParsed)
}
}
if (
!usersParsed.length >= 1 &&
!groupsParsed.length >= 1 &&
!pagesParsed.length >= 1
) {
return Empty
}
return [users(), groups(), pages()]
} catch (error) {
console.log(error)
return (
Render Error
)
}
}
EntryComponent = (t, source) => {
try {
return (
)
} catch (error) {
console.log(error)
return (
Render Error
)
}
}
render() {
const { location } = this.props
const matchSearch = pathMatchRegexp('/s/:id', location.pathname)
const parsed = matchSearch.shift()
const raw = parsed.toString()
const string = raw.replace('/s/', '')
if (matchSearch) {
console.log(`Search matched! ${location.pathname}`)
return (
Results of {string}{' '}
{this.state.loading
? null
: this.renderResult(this.state.SearchResult)}
)
}
return (
Render Error
)
}
}
export default SearchPageIndexer