add searchpage
This commit is contained in:
+2
-4
@@ -15,7 +15,7 @@
|
|||||||
},
|
},
|
||||||
"root": "",
|
"root": "",
|
||||||
"sourceRoot": "src",
|
"sourceRoot": "src",
|
||||||
"prefix": "app",
|
"prefix": "sd",
|
||||||
"architect": {
|
"architect": {
|
||||||
"build": {
|
"build": {
|
||||||
"builder": "@angular/build:application",
|
"builder": "@angular/build:application",
|
||||||
@@ -29,9 +29,7 @@
|
|||||||
"input": "public"
|
"input": "public"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"styles": [
|
"styles": ["src/styles.scss"]
|
||||||
"src/styles.scss"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"configurations": {
|
"configurations": {
|
||||||
"production": {
|
"production": {
|
||||||
|
|||||||
+3
-4
@@ -1,8 +1,7 @@
|
|||||||
<main class="main">
|
<main class="main">
|
||||||
|
<h1>Search Dispatcher</h1>
|
||||||
|
<p>Search with Intent</p>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<h1>Search Dispatcher</h1>
|
<router-outlet />
|
||||||
<p>Search with Intent</p>
|
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<router-outlet />
|
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
import { Routes } from '@angular/router';
|
import { Routes } from '@angular/router';
|
||||||
|
import { SearchBox } from './search-box/search-box';
|
||||||
|
|
||||||
export const routes: Routes = [];
|
export const routes: Routes = [
|
||||||
|
{ path: '', redirectTo: 'main', pathMatch: 'full' },
|
||||||
|
{ path: 'main', component: SearchBox },
|
||||||
|
];
|
||||||
|
|||||||
+3
-2
@@ -1,11 +1,12 @@
|
|||||||
import { Component, signal } from '@angular/core';
|
import { Component, signal } from '@angular/core';
|
||||||
import { RouterOutlet } from '@angular/router';
|
import { RouterOutlet } from '@angular/router';
|
||||||
|
import { SearchBox } from './search-box/search-box';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-root',
|
selector: 'app-root',
|
||||||
imports: [RouterOutlet],
|
imports: [RouterOutlet, SearchBox],
|
||||||
templateUrl: './app.html',
|
templateUrl: './app.html',
|
||||||
styleUrl: './app.scss'
|
styleUrl: './app.scss',
|
||||||
})
|
})
|
||||||
export class App {
|
export class App {
|
||||||
protected readonly title = signal('search-dispatcher');
|
protected readonly title = signal('search-dispatcher');
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
<form (submit)="onSubmit($event)">
|
||||||
|
<label>
|
||||||
|
Search:
|
||||||
|
<input type="text" [formField]="searchForm.term" />
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<button type="submit">Search</button>
|
||||||
|
</form>
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { SearchBox } from './search-box';
|
||||||
|
|
||||||
|
describe('SearchBox', () => {
|
||||||
|
let component: SearchBox;
|
||||||
|
let fixture: ComponentFixture<SearchBox>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
imports: [SearchBox],
|
||||||
|
}).compileComponents();
|
||||||
|
|
||||||
|
fixture = TestBed.createComponent(SearchBox);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
await fixture.whenStable();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import { Component, signal, ChangeDetectionStrategy, inject } from '@angular/core';
|
||||||
|
import { form, FormField, required } from '@angular/forms/signals';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
|
||||||
|
interface SearchObject {
|
||||||
|
term: string;
|
||||||
|
service: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'sd-search-box',
|
||||||
|
imports: [FormField],
|
||||||
|
templateUrl: './search-box.html',
|
||||||
|
styleUrl: './search-box.scss',
|
||||||
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||||
|
})
|
||||||
|
export class SearchBox {
|
||||||
|
private router = inject(Router);
|
||||||
|
|
||||||
|
searchModel = signal<SearchObject>({
|
||||||
|
term: '',
|
||||||
|
service: '',
|
||||||
|
});
|
||||||
|
|
||||||
|
searchForm = form(this.searchModel, (schemaPath) => {
|
||||||
|
required(schemaPath.term, { message: 'Term is required' });
|
||||||
|
});
|
||||||
|
|
||||||
|
onSubmit(event: Event) {
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
const searchObject = this.searchModel();
|
||||||
|
|
||||||
|
window.location.href = `https://www.startpage.com/do/dsearch?q=${searchObject.term}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user