Skip to content
Snippets Groups Projects
Commit c329845f authored by mrp19's avatar mrp19
Browse files

remove search helper page

parent beeaf7d0
No related branches found
No related tags found
4 merge requests!57Merge of develop into master,!56Fixed buttons reportar, seguir, compartilhar, guardar and entrar (in comments...,!39Update admin system,!32Homologa
/*Copyright (C) 2019 Centro de Computacao Cientifica e Software Livre
Departamento de Informatica - Universidade Federal do Parana
This file is part of Plataforma Integrada MEC.
Plataforma Integrada MEC is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Plataforma Integrada MEC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Plataforma Integrada MEC. If not, see <http://www.gnu.org/licenses/>.*/
import React, { useEffect, useState, useContext } from 'react';
import axios from 'axios';
// import ResourceCard from '../Components/ResourceCard'
// import CollectionCard from '../Components/CollectionCard'
// import UserCard from '../Components/UserCard'
import {apiUrl} from '../env';
import './Styles/Home.css';
import { Store } from '../Store';
export default function Search(props){
const { state, dispatch } = useContext(Store)
const [ results, setResults ] = useState([])
const [ page, ] = useState(0)
const [ resultsPerPage, ] = useState(12)
const [ order, ] = useState('score')
useEffect(()=>{
dispatch({
type: 'HANDLE_SEARCH_BAR',
opened: true
})
const urlParams = new URLSearchParams(window.location.search)
const query = urlParams.get('query')
const searchClass = urlParams.get('search_class')
if(state.search.query !== query || state.search.class !== searchClass){
dispatch({
type: 'SAVE_SEARCH',
newSearch: {
query: query,
class: searchClass
}
})
}
return () => dispatch({
type: 'HANDLE_SEARCH_BAR',
opened: false
})
},[])
useEffect(()=>{
axios.get(`${apiUrl}/search?page=${page}&results_per_page=${resultsPerPage}&order=${order}&query=${state.search.query}&search_class=${state.search.class}`)
.then( res => {
setResults(res.data)
})
},[state.search])
return (
<React.Fragment>
<h1>Search for {state.search.query!=='*'?state.search.query:'all'} in {state.search.class}</h1>
{
state.search.class === 'LearningObject' &&
<ul>
{results.map((res)=><li key={res.id}> {res.name} </li>)}
</ul>
}
{state.search.class === 'Collection' &&
<ul>
{results.map((res)=><li key={res.id}> {res.name} </li>)}
</ul>
}
{state.search.class === 'User' &&
<ul>
{results.map((res)=><li key={res.id}> {res.name} </li>)}
</ul>
}
</React.Fragment>
)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment