Skip to content

Commit 91077aa

Browse files
committed
Render saved search editor dialog and bookmark controls
Previous commits added the components for the saved search editor dialog and bookmark controls. This commit renders those controls component (which then renders the dialog component) The controls only appear for authenticated users.
1 parent 0db6eeb commit 91077aa

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

frontend/src/static/js/components/webstatus-overview-filters.ts

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
css,
2323
html,
2424
PropertyValueMap,
25+
nothing,
2526
} from 'lit';
2627
import {customElement, property, state} from 'lit/decorators.js';
2728
import {type components} from 'webstatus.dev-backend';
@@ -62,9 +63,11 @@ import {Toast} from '../utils/toast.js';
6263
import {navigateToUrl} from '../utils/app-router.js';
6364
import {
6465
AppBookmarkInfo,
66+
SavedSearchScope,
6567
savedSearchHelpers,
6668
} from '../contexts/app-bookmark-info-context.js';
67-
import {VOCABULARY} from '../utils/constants.js';
69+
import {UserSavedSearch, VOCABULARY} from '../utils/constants.js';
70+
import {User, firebaseUserContext} from '../contexts/firebase-user-context.js';
6871

6972
const WEBSTATUS_FEATURE_OVERVIEW_CSV_FILENAME =
7073
'webstatus-feature-overview.csv';
@@ -82,8 +85,14 @@ export class WebstatusOverviewFilters extends LitElement {
8285
@property({type: Object})
8386
appBookmarkInfo?: AppBookmarkInfo;
8487

88+
@consume({context: firebaseUserContext, subscribe: true})
89+
@state()
90+
user: User | null | undefined;
91+
8592
_activeQuery: string = '';
8693

94+
_activeUserSavedSearch?: UserSavedSearch | undefined;
95+
8796
// Whether the export button should be enabled based on export status.
8897
@state()
8998
exportDataStatus: TaskStatus = TaskStatus.INITIAL;
@@ -159,6 +168,13 @@ export class WebstatusOverviewFilters extends LitElement {
159168
this.appBookmarkInfo,
160169
this.location,
161170
);
171+
const search = savedSearchHelpers.getCurrentSavedSearch(
172+
this.appBookmarkInfo,
173+
this.location,
174+
);
175+
if (search?.scope === SavedSearchScope.UserSavedSearch) {
176+
this._activeUserSavedSearch = search.value;
177+
}
162178
}
163179
}
164180

@@ -367,6 +383,35 @@ export class WebstatusOverviewFilters extends LitElement {
367383
<sl-icon slot="prefix" name="search"></sl-icon>
368384
</sl-button>
369385
</webstatus-typeahead>
386+
${this.user && this.apiClient
387+
? this.renderSavedSearchControls(this.user, this.apiClient)
388+
: nothing}
389+
`;
390+
}
391+
392+
renderSavedSearchControls(user: User, apiClient: APIClient): TemplateResult {
393+
if (this.typeaheadRef.value === undefined) {
394+
return html``;
395+
}
396+
return html`
397+
<sl-popup
398+
placement="top-end"
399+
autoSize="horizontal"
400+
distance="5"
401+
active
402+
.anchor=${this.typeaheadRef.value}
403+
>
404+
<div slot="anchor" class="popup-anchor saved-search-controls"></div>
405+
<div class="popup-content">
406+
<webstatus-saved-search-controls
407+
.user=${user}
408+
.apiClient=${apiClient}
409+
.savedSearch=${this._activeUserSavedSearch}
410+
.location=${this.location}
411+
.overviewPageQueryInput=${this.typeaheadRef.value}
412+
></webstatus-saved-search-controls>
413+
</div>
414+
</sl-popup>
370415
`;
371416
}
372417

0 commit comments

Comments
 (0)