Skip to content

Commit 7465238

Browse files
committed
feat(daffio): store result on modal close
1 parent b39a780 commit 7465238

5 files changed

Lines changed: 74 additions & 1 deletion

File tree

apps/daffio/src/app/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { daffioRouterDataServiceConfig } from './core/router/data-service-config
3131
import { DaffioSidebarHeaderComponent } from './core/sidebar/components/sidebar-header/sidebar-header.component';
3232
import { provideDaffioSidebarFeature } from './core/sidebar/provider';
3333
import { TemplateComponent } from './core/template/template.component';
34+
import { provideDaffioDocsSearchStoreResult } from './docs/search/state/provider';
3435
import { provideDaffioAlgolia } from './drivers/algolia.provider';
3536

3637
@NgModule({
@@ -77,6 +78,7 @@ import { provideDaffioAlgolia } from './drivers/algolia.provider';
7778
provideDaffRouterDataServiceConfig(daffioRouterDataServiceConfig),
7879
provideDaffioSidebarFeature(),
7980
provideDaffioAlgolia(),
81+
provideDaffioDocsSearchStoreResult(),
8082
],
8183
})
8284
export class AppModule {}

apps/daffio/src/app/docs/search/components/search-modal/search-modal.component.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
Component,
77
DestroyRef,
88
HostBinding,
9+
OnDestroy,
910
OnInit,
1011
QueryList,
1112
ViewChildren,
@@ -34,6 +35,7 @@ import {
3435

3536
import { DAFF_DOCS_SEARCH_RESULT_ICONS } from '../../constants/result-icons.const';
3637
import { DaffioDocsSearchResultItemDirective } from '../../directives/search-result-item/search-result-item.directive';
38+
import { DaffDocsSearchStoreResult } from '../../state/actions';
3739
import { DaffioDocsSearchFieldComponent } from '../search-field/search-field.component';
3840
import { DaffioDocsSearchFooterComponent } from '../search-footer/search-footer.component';
3941

@@ -55,7 +57,7 @@ import { DaffioDocsSearchFooterComponent } from '../search-footer/search-footer.
5557
],
5658
})
5759

58-
export class DaffioDocsSearchModalComponent implements AfterViewInit, OnInit {
60+
export class DaffioDocsSearchModalComponent implements AfterViewInit, OnInit, OnDestroy {
5961
readonly faClockRotateLeft = faClockRotateLeft;
6062
readonly RESULT_ICONS = DAFF_DOCS_SEARCH_RESULT_ICONS;
6163

@@ -78,6 +80,12 @@ export class DaffioDocsSearchModalComponent implements AfterViewInit, OnInit {
7880
private destroyRef: DestroyRef,
7981
) {}
8082

83+
ngOnDestroy(): void {
84+
if (this.formControl.value) {
85+
this.facade.dispatch(new DaffDocsSearchStoreResult(this.formControl.value));
86+
}
87+
}
88+
8189
ngOnInit(): void {
8290
this.loading$ = this.incrementalFacade.loading$;
8391
this.recentQueries$ = this.facade.recent$;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Action } from '@ngrx/store';
2+
3+
export enum DaffioDocsSearchActionTypes {
4+
STORE_RESULT = '[@daffodil/daffio] Docs Search Store Result',
5+
}
6+
7+
export class DaffDocsSearchStoreResult implements Action {
8+
readonly type = DaffioDocsSearchActionTypes.STORE_RESULT;
9+
10+
constructor(public result: string) {}
11+
}
12+
13+
export type DaffioDocsSearchActions =
14+
| DaffDocsSearchStoreResult;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { makeEnvironmentProviders } from '@angular/core';
2+
3+
import { daffSearchProvideExtraReducers } from '@daffodil/search/state';
4+
5+
import { daffioDocsSearchStoreResultReducers } from './reducers';
6+
7+
export const provideDaffioDocsSearchStoreResult = () => makeEnvironmentProviders([
8+
daffSearchProvideExtraReducers(daffioDocsSearchStoreResultReducers),
9+
]);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import {
2+
ActionReducer,
3+
combineReducers,
4+
} from '@ngrx/store';
5+
6+
import { daffIdentityReducer } from '@daffodil/core/state';
7+
import {
8+
DaffSearchReducersState,
9+
DaffSearchReducerState,
10+
} from '@daffodil/search/state';
11+
import { DaffSearchDocsResult } from '@daffodil/search-docs';
12+
13+
import {
14+
DaffioDocsSearchActions,
15+
DaffioDocsSearchActionTypes,
16+
} from './actions';
17+
18+
export const daffioDocsSearchStoreResultReducer: ActionReducer<DaffSearchReducerState<DaffSearchDocsResult>, DaffioDocsSearchActions> = (
19+
state: DaffSearchReducerState<DaffSearchDocsResult>,
20+
action: DaffioDocsSearchActions,
21+
): DaffSearchReducerState<DaffSearchDocsResult> => {
22+
switch (action.type) {
23+
case DaffioDocsSearchActionTypes.STORE_RESULT:
24+
return {
25+
...state,
26+
recent: [
27+
action.result,
28+
...state.recent,
29+
],
30+
};
31+
32+
default:
33+
return state;
34+
}
35+
};
36+
37+
export const daffioDocsSearchStoreResultReducers = combineReducers<DaffSearchReducersState<DaffSearchDocsResult>>({
38+
search: daffioDocsSearchStoreResultReducer,
39+
incremental: daffIdentityReducer,
40+
});

0 commit comments

Comments
 (0)