Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit 0cc5232

Browse files
feat: add ability to filter decks
1 parent 50bbb01 commit 0cc5232

File tree

2 files changed

+72
-9
lines changed

2 files changed

+72
-9
lines changed

studio/src/app/components/core/app-menu-user/app-menu-user.scss

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,21 @@ ion-split-pane {
2323
ion-menu {
2424
ion-content {
2525
ion-list {
26+
ion-searchbar[class*="sc-ion-searchbar"] {
27+
padding-left: 0;
28+
29+
--cancel-button-color: var(--ion-color-medium);
30+
--clear-button-color: var(--ion-color-medium);
31+
32+
input.searchbar-input[class*="sc-ion-searchbar"] {
33+
box-shadow: none;
34+
font-size: var(--font-size-small);
35+
36+
-webkit-padding-start: 48px;
37+
padding-inline-start: 48px;
38+
}
39+
}
40+
2641
ion-item {
2742
--detail-icon-opacity: 0;
2843

studio/src/app/components/core/app-menu-user/app-menu-user.tsx

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ export class AppMenuUser {
3838
@State()
3939
private authUser: AuthUser;
4040

41-
@State()
4241
private decks: Deck[] = null;
4342

43+
@State()
44+
private filteredDecks: Deck[] = null;
45+
4446
private skeletons: number[] = Array(3).fill(0);
4547

4648
constructor() {
@@ -62,14 +64,16 @@ export class AppMenuUser {
6264
filter((user: User) => user && !user.anonymous)).subscribe(async (user: User) => {
6365
if (user) {
6466
try {
65-
const decks: Deck[] = await this.deckService.getUserDecks(user.id);
66-
this.decks = [...decks];
67+
this.decks = await this.deckService.getUserDecks(user.id);
68+
await this.filterDecks(null);
6769
} catch (err) {
6870
// TODO: print error?
6971
this.decks = [];
72+
await this.filterDecks(null);
7073
}
7174
} else {
7275
this.decks = [];
76+
await this.filterDecks(null);
7377
}
7478
});
7579
}
@@ -144,13 +148,48 @@ export class AppMenuUser {
144148
})
145149
}
146150

151+
private async filterDecksOnChange(e: CustomEvent) {
152+
if (e && e.detail) {
153+
await this.filterDecks(e.detail.value);
154+
} else {
155+
await this.filterDecks(null);
156+
}
157+
}
158+
159+
private filterDecks(value: string): Promise<void> {
160+
return new Promise<void>((resolve) => {
161+
if (!value || value === undefined || value === '') {
162+
this.filteredDecks = [...this.decks];
163+
164+
resolve();
165+
return;
166+
}
167+
168+
if (!this.decks || this.decks.length <= 0) {
169+
this.filteredDecks = [...this.decks];
170+
171+
resolve();
172+
return;
173+
}
174+
175+
const matchingDecks: Deck[] = this.decks.filter((matchDeck: Deck) => {
176+
return matchDeck.name && matchDeck.name.toLowerCase().indexOf(value.toLowerCase()) > -1
177+
});
178+
179+
this.filteredDecks = [...matchingDecks];
180+
181+
resolve();
182+
});
183+
}
184+
147185
render() {
148186
return <ion-list>
149187
{this.renderUser()}
150188

151189
<ion-item-divider>
152190
<ion-label>Presentations</ion-label>
153-
<ion-button size="small" slot="end" shape="round" margin-end onClick={() => this.navigateNewDeck()} class="new">
191+
<ion-button size="small" slot="end" shape="round" margin-end onClick={() => this.navigateNewDeck()}
192+
class="new">
154193
<ion-icon name="book" slot="start"></ion-icon>
155194
<ion-label>New</ion-label>
156195
</ion-button>
@@ -176,7 +215,10 @@ export class AppMenuUser {
176215

177216
private renderPresentations() {
178217
if (Utils.isLoggedIn(this.authUser)) {
179-
return this.renderDecks();
218+
return [
219+
this.renderDecksFilter(),
220+
this.renderDecks()
221+
];
180222
} else {
181223
return <ion-item button onClick={() => this.signIn()}>
182224
<ion-icon name="log-in" slot="start"></ion-icon>
@@ -196,10 +238,16 @@ export class AppMenuUser {
196238
}
197239
}
198240

241+
private renderDecksFilter() {
242+
return <ion-searchbar debounce={500} animated placeholder="Filter your presentations"
243+
onIonChange={(e: CustomEvent) => this.filterDecksOnChange(e)}
244+
ion-no-padding ion-margin-top ion-margin-bottom></ion-searchbar>;
245+
}
246+
199247
private renderDecks() {
200-
if (this.decks && this.decks.length > 0) {
248+
if (this.filteredDecks && this.filteredDecks.length > 0) {
201249
return (
202-
this.decks.map((deck: Deck) => {
250+
this.filteredDecks.map((deck: Deck) => {
203251
const url: string = `/editor/${deck.id}`;
204252

205253
return <ion-item href={url} routerDirection="root">
@@ -208,10 +256,10 @@ export class AppMenuUser {
208256
</ion-item>
209257
})
210258
);
211-
} else if (this.decks && this.decks.length === 0) {
259+
} else if (this.filteredDecks && this.filteredDecks.length === 0) {
212260
return (
213261
<ion-item>
214-
<ion-label>No presentations yet 😔</ion-label>
262+
<ion-label>No presentations 😔</ion-label>
215263
</ion-item>
216264
)
217265
} else {

0 commit comments

Comments
 (0)