|
| 1 | +import { Component } from '@angular/core'; |
| 2 | +import {ApiService} from '../../../api.service'; |
| 3 | +import {NgbModal} from '@ng-bootstrap/ng-bootstrap'; |
| 4 | +import {UserService} from '../../../user.service'; |
| 5 | +import {MessageService} from '../../../message.service'; |
| 6 | +import {debounce} from '../../../util/debounce'; |
| 7 | +import {Maimai2Rival} from '../model/Maimai2Rival'; |
| 8 | +import {HttpParams} from '@angular/common/http'; |
| 9 | +import {environment} from "../../../../environments/environment"; |
| 10 | + |
| 11 | +@Component({ |
| 12 | + selector: 'app-maimai2-rival', |
| 13 | + templateUrl: './maimai2-rival.component.html', |
| 14 | + styleUrls: ['./maimai2-rival.component.css'] |
| 15 | +}) |
| 16 | +export class Maimai2RivalComponent { |
| 17 | + |
| 18 | + host = environment.assetsHost; |
| 19 | + rivalList: Maimai2Rival[] = []; |
| 20 | + loading = true; |
| 21 | + addingFriend: boolean; |
| 22 | + private aimeId: string; |
| 23 | + |
| 24 | + constructor( |
| 25 | + private api: ApiService, |
| 26 | + private modalService: NgbModal, |
| 27 | + protected userService: UserService, |
| 28 | + private messageService: MessageService, |
| 29 | + ) { |
| 30 | + } |
| 31 | + |
| 32 | + ngOnInit(){ |
| 33 | + this.loading = true; |
| 34 | + this.aimeId = String(this.userService.currentUser.defaultCard.extId); |
| 35 | + this.loadRival(); |
| 36 | + } |
| 37 | + |
| 38 | + loadRival() { |
| 39 | + const param = new HttpParams().set('aimeId', this.aimeId); |
| 40 | + this.api.get('api/game/maimai2/rival', param).subscribe( |
| 41 | + (data) => { |
| 42 | + this.rivalList = data; |
| 43 | + this.loading = false; |
| 44 | + }, |
| 45 | + error => { |
| 46 | + this.messageService.notice(`Cannot get rival list: ${error}`); |
| 47 | + } |
| 48 | + ); |
| 49 | + } |
| 50 | + |
| 51 | + removeRival(rivalUserId: string) { |
| 52 | + const param = new HttpParams().set('rivalId', (Number).parseInt(rivalUserId)).set('aimeId', this.aimeId); |
| 53 | + this.api.delete('api/game/maimai2/rival', param).subscribe( |
| 54 | + () => { |
| 55 | + const newList = this.rivalList.filter(item => item.rivalId !== rivalUserId); |
| 56 | + this.messageService.notice(`(id:${rivalUserId}) delete successfully.`); |
| 57 | + this.rivalList = newList; |
| 58 | + }, |
| 59 | + error => this.messageService.notice(`remove rival failed: ${error}`) |
| 60 | + ); |
| 61 | + } |
| 62 | + |
| 63 | + getFormattedNumberByDigit(input: string, digit: number): string { |
| 64 | + return input.toString().padStart(digit, '0'); |
| 65 | + } |
| 66 | + |
| 67 | + addRival(rivalUserId: string) { |
| 68 | + this.addingFriend = true; |
| 69 | + const param = new HttpParams().set('rivalId',rivalUserId).set('aimeId', this.aimeId); |
| 70 | + this.api.post('api/game/maimai2/rival' , param).subscribe( |
| 71 | + data => { |
| 72 | + this.addingFriend = false; |
| 73 | + if (data) { |
| 74 | + this.messageService.notice(`Add rival success!`); |
| 75 | + this.ngOnInit(); |
| 76 | + } |
| 77 | + }, |
| 78 | + error => { |
| 79 | + this.messageService.notice(`add rival failed: ${error}`); |
| 80 | + this.addingFriend = false; |
| 81 | + } |
| 82 | + ); |
| 83 | + } |
| 84 | + |
| 85 | + protected readonly String = String; |
| 86 | +} |
0 commit comments