gift-log.component.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { Component, OnInit } from '@angular/core';
  2. import { NavComponent } from '../../../app/components/nav/nav.component';
  3. import { InfiniteScrollCustomEvent, ToastController } from '@ionic/angular';
  4. import * as Parse from 'parse';
  5. import { ionicStandaloneModules } from '../../ionic-standalone.modules';
  6. import { SharedModule } from '../../shared.module';
  7. import { Router } from '@angular/router';
  8. import { CommonModule, DatePipe } from '@angular/common';
  9. import { AiChatService } from '../../../services/aichart.service';
  10. @Component({
  11. selector: 'app-gift-log',
  12. templateUrl: './gift-log.component.html',
  13. styleUrls: ['./gift-log.component.scss'],
  14. standalone: true,
  15. imports: [...ionicStandaloneModules, NavComponent, SharedModule,CommonModule],
  16. providers: [DatePipe],
  17. })
  18. export class GiftLogComponent implements OnInit {
  19. active: string = 'from';
  20. list: Array<Parse.Object> = [];
  21. disbable: boolean = true;
  22. constructor(private router: Router, public aiChatServ: AiChatService) {}
  23. ngOnInit() {
  24. this.getBrowseHistory();
  25. }
  26. segmentChanged(e: any) {
  27. let { value } = e.detail;
  28. this.active = value;
  29. // console.log(this.active);
  30. this.list = [];
  31. this.disbable = true;
  32. this.getBrowseHistory();
  33. }
  34. async getBrowseHistory() {
  35. let uid = Parse.User.current().id;
  36. let query = new Parse.Query('LoveRender');
  37. // query.equalTo('toUser', uid);
  38. query.notEqualTo('isDeleted', true);
  39. query.equalTo(
  40. this.active == 'from' ? 'fromUser' : 'toUser',
  41. Parse.User.current()
  42. );
  43. // if (this.active == 'from') {
  44. // query.notEqualTo('toUser', Parse.User.current());
  45. // } else {
  46. // query.notEqualTo('fromUser', Parse.User.current());
  47. // }
  48. query.descending('createdAt');
  49. query.limit(20);
  50. query.skip(this.list.length);
  51. query.include('fromUser', 'toUser');
  52. let r = await query.find();
  53. this.list.push(...r);
  54. return r;
  55. }
  56. async onIonInfinite(ev: any) {
  57. let result = await this.getBrowseHistory();
  58. if (result.length == 0) {
  59. this.disbable = false;
  60. }
  61. setTimeout(() => {
  62. (ev as InfiniteScrollCustomEvent).target.complete();
  63. }, 500);
  64. }
  65. toUrl(id: string) {
  66. this.router.navigate(['/user/profile/' + id]);
  67. }
  68. }