Skip to content

Commit f522c91

Browse files
committed
Improved event listeners
1 parent 7f2ec40 commit f522c91

File tree

3 files changed

+17
-71
lines changed

3 files changed

+17
-71
lines changed

src/pages/app-albums/app-albums.tsx

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ declare var blockstack;
1111
})
1212
export class AppAlbums {
1313
private present: PresentingService;
14-
private refresherListener: any;
1514
private refresherScroll: any;
1615

1716
@State() albums: any[] = [];
@@ -20,7 +19,6 @@ export class AppAlbums {
2019

2120
constructor() {
2221
this.present = new PresentingService();
23-
this.refresherListener = this.refreshList.bind(this);
2422
}
2523

2624
componentWillLoad() {
@@ -37,27 +35,12 @@ export class AppAlbums {
3735
return;
3836
}
3937
this.refresherScroll = document.getElementById('albums-refresher-scroll');
40-
if (this.refresherScroll) {
41-
this.refresherScroll.addEventListener(
42-
'ionRefresh',
43-
this.refresherListener
44-
);
45-
}
4638

4739
this.loadAlbums(false);
4840

4941
AnalyticsService.logEvent('photos-list');
5042
}
5143

52-
async componentDidUnload() {
53-
if (this.refresherScroll) {
54-
this.refresherScroll.removeEventListener(
55-
'ionRefresh',
56-
this.refresherListener
57-
);
58-
}
59-
}
60-
6144
refreshList() {
6245
this.loadAlbums(true, false);
6346
}
@@ -271,7 +254,11 @@ export class AppAlbums {
271254
</ion-header>,
272255

273256
<ion-content>
274-
<ion-refresher slot="fixed" id="albums-refresher-scroll">
257+
<ion-refresher
258+
slot="fixed"
259+
id="albums-refresher-scroll"
260+
onIonRefresh={() => this.refreshList()}
261+
>
275262
<ion-refresher-content />
276263
</ion-refresher>
277264
{empty && this.albumsLoaded ? (
@@ -335,7 +322,7 @@ export class AppAlbums {
335322
no-margin
336323
type="text"
337324
value={col.albumName}
338-
onBlur={event =>
325+
onIonBlur={event =>
339326
this.updateAlbumName(
340327
event,
341328
col.albumId,

src/pages/app-photos/app-photos.tsx

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ export class AppPhotos {
1818
private activatedByTouch = false;
1919
private present: PresentingService;
2020
private uploadService: UploadService;
21-
private photosRangeListener: any;
22-
private photosRefresherListener: any;
2321
private ionRouteDidChangeListener: any;
2422
private photosLoaded: number;
2523
private infiniteScroll: any;
@@ -41,8 +39,6 @@ export class AppPhotos {
4139

4240
constructor() {
4341
this.present = new PresentingService();
44-
this.photosRangeListener = this.loadPhotosRange.bind(this);
45-
this.photosRefresherListener = this.refreshPhotosList.bind(this);
4642
this.ionRouteDidChangeListener = this.ionRouteDidChange.bind(this);
4743
}
4844

@@ -79,21 +75,7 @@ export class AppPhotos {
7975
this.photosLoaded = 0;
8076

8177
this.infiniteScroll = document.getElementById('infinite-scroll');
82-
if (this.infiniteScroll) {
83-
this.infiniteScroll.addEventListener(
84-
'ionInfinite',
85-
this.photosRangeListener
86-
);
87-
}
88-
8978
this.refresherScroll = document.getElementById('photos-refresher-scroll');
90-
if (this.refresherScroll) {
91-
this.refresherScroll.addEventListener(
92-
'ionRefresh',
93-
this.photosRefresherListener
94-
);
95-
}
96-
9779
this.uploadService.addEventListeners(true);
9880
this.loadPhotosList(false);
9981

@@ -108,18 +90,6 @@ export class AppPhotos {
10890

10991
async componentDidUnload() {
11092
this.uploadService.removeEventListeners(true);
111-
if (this.infiniteScroll) {
112-
this.infiniteScroll.removeEventListener(
113-
'ionInfinite',
114-
this.photosRangeListener
115-
);
116-
}
117-
if (this.refresherScroll) {
118-
this.refresherScroll.removeEventListener(
119-
'ionRefresh',
120-
this.photosRefresherListener
121-
);
122-
}
12393
this.router.removeEventListener(
12494
'ionRouteDidChange',
12595
this.ionRouteDidChangeListener
@@ -418,7 +388,11 @@ export class AppPhotos {
418388
</ion-header>,
419389

420390
<ion-content id="photos-list">
421-
<ion-refresher slot="fixed" id="photos-refresher-scroll">
391+
<ion-refresher
392+
slot="fixed"
393+
id="photos-refresher-scroll"
394+
onIonRefresh={() => this.refreshPhotosList()}
395+
>
422396
<ion-refresher-content />
423397
</ion-refresher>
424398
{empty && this.listLoaded ? (
@@ -464,7 +438,11 @@ export class AppPhotos {
464438
))}
465439
</ion-grid>
466440
)}
467-
<ion-infinite-scroll threshold="100px" id="infinite-scroll">
441+
<ion-infinite-scroll
442+
threshold="100px"
443+
id="infinite-scroll"
444+
onIonInfinite={event => this.loadPhotosRange(event)}
445+
>
468446
<ion-infinite-scroll-content
469447
loading-spinner="bubbles"
470448
loading-text="Loading more photos..."

src/pages/app-settings/app-settings.tsx

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,18 @@ import SettingsService from '../../services/settings-service';
88
})
99
export class AppSettings {
1010
private present: PresentingService;
11-
private analyticsToggle: HTMLIonToggleElement;
12-
private analyticsToggleChangeListener: any;
1311

1412
@State() allowAnalytics: boolean;
1513

1614
constructor() {
1715
this.present = new PresentingService();
18-
this.analyticsToggleChangeListener = this.changeAnalyticsSetting.bind(this);
1916
}
2017

2118
async componentWillLoad() {
2219
this.allowAnalytics = await SettingsService.getAnalyticsSetting();
23-
}
24-
25-
async componentDidLoad() {
26-
this.analyticsToggle = document.querySelector('ion-toggle');
27-
await this.analyticsToggle.componentOnReady();
28-
this.analyticsToggle.addEventListener(
29-
'ionChange',
30-
this.analyticsToggleChangeListener
31-
);
32-
3320
AnalyticsService.logEvent('settings-page');
3421
}
3522

36-
async componentDidUnload() {
37-
this.analyticsToggle.removeEventListener(
38-
'ionChange',
39-
this.analyticsToggleChangeListener
40-
);
41-
}
42-
4323
visitBlockstackProfile(event: any): void {
4424
if (event) {
4525
event.preventDefault();
@@ -146,6 +126,7 @@ export class AppSettings {
146126
slot="end"
147127
value="analytics"
148128
checked={this.allowAnalytics}
129+
onIonChange={() => this.changeAnalyticsSetting()}
149130
/>
150131
</ion-item>
151132
<ion-item>

0 commit comments

Comments
 (0)