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

Commit e7253a3

Browse files
feat: auto scroll to top
1 parent 668e6ee commit e7253a3

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

studio/src/app/modals/editor/app-gif/app-gif.tsx

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ export class AppGif {
101101
return;
102102
}
103103

104-
this.paginationNext = tenorResponse.next;
105-
106104
const gifs: TenorGif[] = tenorResponse.results;
107105

108106
if (!gifs || gifs.length <= 0) {
@@ -123,6 +121,15 @@ export class AppGif {
123121
this.gifsOdd = [...this.gifsOdd, ...gifs.filter((_a, i) => i % 2)];
124122
this.gifsEven = [...this.gifsEven, ...gifs.filter((_a, i) => !(i % 2))];
125123

124+
if (!this.paginationNext || this.paginationNext === 0) {
125+
// We just put a small delay because of the repaint
126+
setTimeout(async () => {
127+
await this.autoScrollToTop();
128+
}, 100)
129+
}
130+
131+
this.paginationNext = tenorResponse.next;
132+
126133
resolve();
127134
});
128135
}
@@ -161,6 +168,21 @@ export class AppGif {
161168
this.searchTerm = ($event.target as InputTargetEvent).value;
162169
}
163170

171+
private autoScrollToTop(): Promise<void> {
172+
return new Promise<void>(async (resolve) => {
173+
const content: HTMLIonContentElement = this.el.querySelector('ion-content');
174+
175+
if (!content) {
176+
resolve();
177+
return;
178+
}
179+
180+
await content.scrollToTop();
181+
182+
resolve();
183+
});
184+
}
185+
164186
render() {
165187
return [
166188
<ion-header>
@@ -185,7 +207,8 @@ export class AppGif {
185207
</div>
186208
</div>
187209

188-
<ion-infinite-scroll threshold="100px" disabled={this.disableInfiniteScroll} onIonInfinite={(e: CustomEvent<void>) => this.searchNext(e)}>
210+
<ion-infinite-scroll threshold="100px" disabled={this.disableInfiniteScroll}
211+
onIonInfinite={(e: CustomEvent<void>) => this.searchNext(e)}>
189212
<ion-infinite-scroll-content
190213
loadingSpinner="bubbles"
191214
loadingText="Loading more data...">

0 commit comments

Comments
 (0)