Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
akariv committed Oct 12, 2023
1 parent 9497b6b commit 9351519
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 15 deletions.
15 changes: 15 additions & 0 deletions projects/srm/src/app/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,21 @@ export class ApiService {
).pipe(
map((presets) => presets.filter((r: Preset) => r.example))
);
}

getEmergencies(): Observable<Preset[]> {
const params = {size: 17, order: 'score'};
return this.innerCache(
'presets',
this.http.get(environment.presetsURL, {params}).pipe(
map((res) => {
const results = res as QueryPresetResult;
return results.search_results.map((r: any) => r.source)
})
), true
).pipe(
map((presets) => presets.filter((r: Preset) => r.emergency))
);
}

getAutoComplete(query: string): Observable<AutoComplete[]> {
Expand Down
1 change: 1 addition & 0 deletions projects/srm/src/app/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export type Preset = {
style: string,
preset: boolean,
example: boolean,
emergency: boolean,
};

export type AutoComplete = {
Expand Down
16 changes: 12 additions & 4 deletions projects/srm/src/app/homepage/homepage.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,19 @@ <h1 class='tagline'>
</div>
</a>
</div>
<div class='examples hide-while-searching'>
<span class='explain'>לדוגמה אפשר לחפש:</span>
<div class='list'>
<a *ngFor='let example of examples' (activated)='startSearch(example.title)' clickOnReturn>{{example.title}}</a>
<div class='examples-block hide-while-searching'>
<div class='emergencies hide-while-searching'>
<span class='explain'>ניתן לאתר שירותים למצב חירום המלחמתי כמו:</span>
<div class='list'>
<a *ngFor='let emergency of emergencies' (activated)='startSearch(emergency.title, true)' clickOnReturn>{{emergency.title}}</a>
</div>
</div>
<div class='examples hide-while-searching'>
<span class='explain'>בנוסף, ניתן לחפש באתר גם שירותי שגרה כמו:</span>
<div class='list'>
<a *ngFor='let example of examples' (activated)='startSearch(example.title)' clickOnReturn>{{example.title}}</a>
</div>
</div>
</div>
</div>
<div class='logos hide-while-searching'>
Expand Down
24 changes: 21 additions & 3 deletions projects/srm/src/app/homepage/homepage.component.less
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@
}
}
}
.examples {
.examples-block {
display: flex;
flex-flow: column;
gap: 8px;
gap: 12px;
padding: 0 16px;

.desktop({
Expand All @@ -238,6 +238,11 @@
.mobile({
min-height: 120px;
});
}
.examples, .emergencies {
display: flex;
flex-flow: column;
gap: 8px;
.explain {
color: @color-gray-1;
.font-rag-sans;
Expand All @@ -260,6 +265,7 @@
a {
color: @color-blue-1;
.font-rag-sans;
display: inline-block;
font-size: 16px;
font-weight: 300;
line-height: 20px;
Expand All @@ -268,7 +274,19 @@
background: rgba(31, 55, 246, 0.10);
white-space: nowrap;
cursor: pointer;
pointer-events: all;
pointer-events: all;
}
}
}
.emergencies {
.explain {
font-weight: 600;
}
.list {
a {
color: #9B0000;
font-weight: 600;
background: rgba(253, 202, 72, 0.30);
}
}
}
Expand Down
24 changes: 16 additions & 8 deletions projects/srm/src/app/homepage/homepage.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AfterViewInit, Component, ElementRef, OnInit } from '@angular/core';
import { ApiService } from '../api.service';
import { Preset, TaxonomyItem } from '../consts';
import { Preset, TaxonomyItem, prepareQuery } from '../consts';
import { PlatformService } from '../platform.service';
import { SearchConfig } from '../search/search-config';
import { Router } from '@angular/router';
Expand All @@ -22,13 +22,17 @@ export class HomepageComponent {
public searchConfig: SearchConfig;
searching = false;
examples: Preset[];
emergencies: Preset[];

constructor(private api: ApiService, private platform: PlatformService, private router: Router, private layout: LayoutService) {
this.searchConfig = new SearchConfig(this, this.router, this.api, this.platform);
this.searchConfig.autoFocus = false;
this.api.getExamples().subscribe((examples) => {
this.examples = examples;
});
this.api.getEmergencies().subscribe((emergencies) => {
this.emergencies = emergencies;
});
}

updateFocus(focus: boolean) {
Expand All @@ -43,14 +47,18 @@ export class HomepageComponent {
}
}

startSearch(query: string) {
if (this.layout.desktop) {
this.searching = true;
this.searchConfig.query_ = query;
this.searchConfig.queries.next(query);
this.searchConfig.focus();
startSearch(query: string, direct=false) {
if (direct) {
this.router.navigate(['/s', prepareQuery(query)]);
} else {
this.router.navigate(['/q'], {queryParams: {q: query}});
if (this.layout.desktop) {
this.searching = true;
this.searchConfig.query_ = query;
this.searchConfig.queries.next(query);
this.searchConfig.focus();
} else {
this.router.navigate(['/q'], {queryParams: {q: query}});
}
}
}

Expand Down

0 comments on commit 9351519

Please sign in to comment.