Skip to content

Commit

Permalink
Add search page for aluno
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-Alvarenga committed Nov 3, 2024
1 parent e970e36 commit 86e93be
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 3 deletions.
2 changes: 1 addition & 1 deletion client/src/components/aluno/Aside.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<router-link to="/aluno/me">Meu perfil</router-link>
</li>
<li>
<router-link to="/buscar">Pesquisa</router-link>
<router-link to="/aluno/search">Pesquisa</router-link>
</li>
<li>
<router-link to="/rede">Meus vínculos</router-link>
Expand Down
9 changes: 9 additions & 0 deletions client/src/router/routes/aluno.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Rede from '../../views/aluno/Rede.vue';
import ConfigAluno from '../../views/aluno/Config.vue';
import Messages from '../../views/aluno/Messages.vue';
import ChatAluno from '../../views/aluno/Message.vue';
import Pesquisa from '../../views/aluno/Pesquisa.vue';

import {
isRecoveringAluno,
Expand Down Expand Up @@ -99,6 +100,14 @@ export const alunoRoutes = [
(await isCompletedAluno()) ? ((await isAuthAluno()) ? next() : next("/login")) : next("/register/complete");
}
},
{
path: "/aluno/search",
name: "PesquisaALuno",
component: Pesquisa,
beforeEnter: async (to, from, next) => {
(await isAuthAluno()) ? next() : next("/login");
}
},
{
path: "/config",
name: "Config",
Expand Down
7 changes: 5 additions & 2 deletions client/src/router/routes/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import PublicPerfilProfessor from '../../views/shared/PerfilProfessor.vue';
import Pesquisa from '../../views/shared/Pesquisa.vue';
import Vagas from '../../views/shared/Vagas.vue';
import Vaga from '../../views/shared/Vaga.vue';
import { isAuthSomebody } from '../guards/guards';
import { isAuthAluno, isAuthSomebody } from '../guards/guards';

export const sharedRoutes = [
{
Expand Down Expand Up @@ -34,7 +34,10 @@ export const sharedRoutes = [
{
path: '/buscar',
name: 'Pesquisa',
component: Pesquisa
component: Pesquisa,
beforeEnter: async (to, from, next) => {
(await isAuthAluno()) ? next("/aluno/search") : next();
}
},
{
path: '/vagas',
Expand Down
117 changes: 117 additions & 0 deletions client/src/views/aluno/Pesquisa.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<template>
<Header />
<div id="app">
<main>
<AsideDashboard pageName="pesquisa" />
<section class="content">
<div class="search">
<div class="box">
<input type="text" placeholder="Buscar usuário" v-model="busca" @keyup.enter="filterUsers">
<button @click="filterUsers">
<img :src="icons.search" alt="Buscar">
</button>
</div>
</div>
<ul class="box">
<li class="user" v-if="filteredUsers.length < 1">
<a href="">
<div class="infoAluno">
<p>Nenhum usuário com esse nome ou email encontrado</p>
</div>
</a>
</li>
<p class="resultado" v-else v-text="(filteredUsers.length > 1)?
filteredUsers.length + ' resultados encontrados para sua busca' :
filteredUsers.length + ' resultado encontrado para sua busca'"></p>
<li class="user" v-for="(estudante, index) in filteredUsers" :key="index">
<router-link :to="'/aluno/profile/' + estudante.rm">
<img v-if="estudante.imageUrl == 'default'" src="../../assets/icons/artwork.png" :alt="estudante.name">
<img v-else :src="estudante.imageUrl" :alt="estudante.name">
<div class="infoAluno">
<div class="contentAluno name">
<p class="who">{{ estudante.name }}</p>
<p>{{ JSON.parse(estudante.endereco).municipio + ", " + JSON.parse(estudante.endereco).estado }}</p>
</div>
<div class="box-button">
<button>Ver perfil</button>
</div>
</div>
</router-link>
</li>
</ul>
</section>
</main>
</div>
</template>

<script>
import Header from '../../components/Header.vue';
import AsideDashboard from '../../components/aluno/AsideDashboard.vue';
import searchIcon from '../../assets/icons/procurar.png';
import Cookies from 'js-cookie';
import {
getUsers
} from '../../services/api/shared';
import { getMeAluno } from '../../services/api/aluno';
export default {
name: 'Pesquisa',
components: {
Header,
AsideDashboard
},
data() {
return {
aluno: {
token: '',
nome: '',
nascimento: '',
idade: '',
connected: false
},
icons: {
search: searchIcon,
},
users: {
alunos: []
},
busca: '',
filteredUsers: []
};
},
methods: {
async loadUsers(){
try {
const response = await getUsers();
if (response.status >= 200 && response.status < 300) {
this.users.alunos = response.data.alunos;
this.filteredUsers = this.users.alunos;
} else{
console.log("Ops.. Algo deu errado ao buscar os usuários. 😕\n" + response.message);
}
} catch (error) {
console.log("Ops.. Algo deu errado ao recuperar os seus vínculos. 😕\n" + error);
}
},
filterUsers() {
const terms = this.busca.trim().split(' ');
this.filteredUsers = this.users.alunos.filter(aluno => {
return terms.some(term =>
aluno.name.toLowerCase().includes(term.toLowerCase()) ||
aluno.email.toLowerCase().includes(term.toLowerCase()) ||
aluno.rm.toLowerCase().includes(term.toLowerCase())
);
});
}
},
async created() {
await this.loadUsers();
}
};
</script>

<style lang="scss" scoped>
@import "../../scss/pages/shared/_pesquisa.scss";
</style>

0 comments on commit 86e93be

Please sign in to comment.