feat: correction service recherche
This commit is contained in:
parent
400033f005
commit
9b29d7fe5f
|
|
@ -7,8 +7,7 @@ export const routes: Routes = [
|
|||
{path: 'login', loadComponent: ()=> import("./pages/login/login").then(m =>m.Login)},
|
||||
{path: 'register', loadComponent: ()=> import("./pages/register/register").then(m =>m.Register)},
|
||||
{path: 'login', loadComponent: ()=> import("./pages/login/login").then(m =>m.Login)},
|
||||
{path: 'potd', loadComponent: ()=> import("./pages/potd/potd").then(m =>m.POTD)},
|
||||
{path: 'search', loadComponent: ()=> import("./pages/search/search").then(m =>m.Search)},
|
||||
{path: 'potd', loadComponent: ()=> import("./pages/potd/potd").then(m =>m.POTD)},
|
||||
{path: 'video/:id', loadComponent: ()=> import("./pages/video/video").then(m =>m.Video)},
|
||||
{path: 'admin',canActivate: [adminGuard], loadChildren: () => import('./pages/admin/admin').then(m => m.Admin), data: { role: 'ADMIN' } },
|
||||
//version si besoin de multiplier les routes admin
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
<app-searchresults/>
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
import { Component } from '@angular/core';
|
||||
import { Search } from "../search/search";
|
||||
import { Searchresults } from "../search/searchresults/searchresults";
|
||||
|
||||
@Component({
|
||||
selector: 'app-home',
|
||||
imports: [Search],
|
||||
imports: [Searchresults],
|
||||
templateUrl: './home.html',
|
||||
styleUrl: './home.css'
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<div class="flex">
|
||||
<form class="inputSearch flex" (ngSubmit)="onSubmit()">
|
||||
<form class="inputSearch flex" (ngSubmit)="onSubmit($event)">
|
||||
<label class="input">
|
||||
<svg
|
||||
class="h-[1em] opacity-50"
|
||||
|
|
@ -19,6 +19,6 @@
|
|||
</svg>
|
||||
<input type="search" [value]="searchString()" (input)="updateSearch($event)" class="grow" placeholder="Search" />
|
||||
</label>
|
||||
<button class="btn mx-2">Search</button>
|
||||
<button type="submit" class="btn mx-2">Search</button>
|
||||
</form>
|
||||
</div>
|
||||
|
|
@ -1,23 +1,24 @@
|
|||
import { Component, inject, signal } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
import { NasaApi } from '../../../interfaces/nasa-api';
|
||||
import { NAPOD } from '../../../services/napod';
|
||||
import { Search } from '../../../services/search';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
|
||||
@Component({
|
||||
selector: 'app-searchform',
|
||||
imports: [],
|
||||
imports: [FormsModule],
|
||||
templateUrl: './searchform.html',
|
||||
styleUrl: './searchform.css',
|
||||
})
|
||||
export class Searchform {
|
||||
private readonly nasaApi = inject(NAPOD);
|
||||
private readonly router = inject(Router)
|
||||
searchResults = signal<NasaApi | null>(null)
|
||||
searchString=signal('');
|
||||
private readonly searchService = inject(Search);
|
||||
searchString = this.searchService.searchString;
|
||||
|
||||
onSubmit() {
|
||||
this.nasaApi.searchForVideos(this.searchString()).subscribe({
|
||||
next: (data)=>{this.searchResults.set(data);
|
||||
onSubmit(event: Event) {
|
||||
event.preventDefault(); // <-- Empêche le rechargement
|
||||
console.log("onSubmit appelé !"); // <-- Devrait s'afficher
|
||||
this.nasaApi.searchForVideos(this.searchService.searchString()).subscribe({
|
||||
next: (data)=>{this.searchService.searchResults.set(data);
|
||||
console.log(data.collection);
|
||||
},
|
||||
error: error =>{console.log(error);
|
||||
|
|
@ -25,14 +26,9 @@ export class Searchform {
|
|||
})
|
||||
}
|
||||
|
||||
onClick(nasaId: string){
|
||||
this.router.navigate(['/video/'+nasaId])
|
||||
}
|
||||
|
||||
updateSearch(event: Event){
|
||||
console.log(this.searchString());
|
||||
const target = event.target as HTMLInputElement;
|
||||
this.searchString.set(target.value)
|
||||
this.searchService.searchString.set(target.value)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,5 +28,4 @@
|
|||
|
||||
</ul>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
|
@ -1,4 +1,6 @@
|
|||
import { Component } from '@angular/core';
|
||||
import { Component, inject, signal } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
import { Search } from '../../../services/search';
|
||||
|
||||
@Component({
|
||||
selector: 'app-searchresults',
|
||||
|
|
@ -7,5 +9,14 @@ import { Component } from '@angular/core';
|
|||
styleUrl: './searchresults.css',
|
||||
})
|
||||
export class Searchresults {
|
||||
private readonly router = inject(Router)
|
||||
private readonly searchService = inject(Search);
|
||||
|
||||
searchResults = this.searchService.searchResults;
|
||||
searchString = this.searchService.searchString;
|
||||
|
||||
onClick(nasaId: string){
|
||||
this.router.navigate(['/video/'+nasaId])
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { Search } from './search';
|
||||
|
||||
describe('Search', () => {
|
||||
let service: Search;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(Search);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
import { Injectable, signal } from '@angular/core';
|
||||
import { NasaApi } from '../interfaces/nasa-api';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class Search {
|
||||
searchResults = signal<NasaApi | null>(null);
|
||||
searchString = signal('');
|
||||
}
|
||||
Loading…
Reference in New Issue