-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b1a5a90
commit 4d8c2c2
Showing
7 changed files
with
188 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/app/rebuttals/pages/list-rebuttals/list-rebuttals.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
@if (loading()) { | ||
<app-loader /> | ||
} @else { | ||
<div class="col-md-12"> | ||
<div class="card"> | ||
<div class="card-header"> | ||
<h3 class="card-title"> | ||
<transloco key="app.my_rebuttals.all" [params]="{instance: currentInstance()}" /> | ||
</h3> | ||
</div> | ||
<div class="card-body"> | ||
<table class="table table-bordered"> | ||
<thead> | ||
<tr> | ||
<th>{{'app.instance' | transloco}}</th> | ||
<th>{{'app.reasons' | transloco}}</th> | ||
<th>{{'app.evidence' | transloco}}</th> | ||
<th>{{'app.rebuttal' | transloco}}</th> | ||
<th>{{'app.actions' | transloco}}</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@for (instance of instances(); track instance.domain) { | ||
<tr> | ||
<td> | ||
<a routerLink="/instances/detail/{{instance.domain}}">{{instance.domain}}</a> | ||
</td> | ||
<td> | ||
<ul> | ||
@if (instance.censureReasons.length) { | ||
<li> | ||
<strong>{{'app.censure' | transloco}}:</strong> {{instance.censureReasons.join(', ')}} | ||
</li> | ||
} | ||
@if (instance.hesitationReasons.length) { | ||
<li> | ||
<strong>{{'app.hesitation' | transloco}}:</strong> {{instance.hesitationReasons.join(', ')}} | ||
</li> | ||
} | ||
</ul> | ||
</td> | ||
<td> | ||
@if (instance.censuresEvidence || instance.hesitationsEvidence) { | ||
<ul> | ||
@if (instance.censuresEvidence) { | ||
<li> | ||
<strong>{{'app.censure' | transloco}}:</strong> {{instance.censuresEvidence}} | ||
</li> | ||
} | ||
@if (instance.hesitationsEvidence) { | ||
<li> | ||
<strong>{{'app.hesitation' | transloco}}:</strong> {{instance.hesitationsEvidence}} | ||
</li> | ||
} | ||
</ul> | ||
} @else { | ||
<code>{{'app.not_applicable' | transloco}}</code> | ||
} | ||
</td> | ||
<td> | ||
{{instance.rebuttal}} | ||
</td> | ||
<td> | ||
<button class="btn btn-danger" (click)="removeRebuttal(instance)">{{'app.generic_buttons.remove' | transloco}}</button> | ||
| ||
<a class="btn btn-primary" routerLink="/rebuttals/edit/{{instance.domain}}">{{'app.generic_buttons.edit' | transloco}}</a> | ||
</td> | ||
</tr> | ||
} @empty { | ||
<tr> | ||
<td colspan="5"> | ||
{{'app.rebuttal.no_rebuttal_yet' | transloco}} | ||
</td> | ||
</tr> | ||
} | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
</div> | ||
} |
3 changes: 3 additions & 0 deletions
3
src/app/rebuttals/pages/list-rebuttals/list-rebuttals.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
:host { | ||
min-width: 100%; | ||
} |
74 changes: 74 additions & 0 deletions
74
src/app/rebuttals/pages/list-rebuttals/list-rebuttals.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import {Component, computed, input, OnInit, signal} from '@angular/core'; | ||
import {TitleService} from "../../../services/title.service"; | ||
import {TranslatorService} from "../../../services/translator.service"; | ||
import {SharedModule} from "../../../shared/shared.module"; | ||
import {InstanceDetailResponse} from "../../../response/instance-detail.response"; | ||
import {FediseerApiService} from "../../../services/fediseer-api.service"; | ||
import {AuthenticationManagerService} from "../../../services/authentication-manager.service"; | ||
import {toPromise} from "../../../types/resolvable"; | ||
import {filter, map, zip} from "rxjs"; | ||
import {ApiResponseHelperService} from "../../../services/api-response-helper.service"; | ||
import {NormalizedInstanceDetailResponse} from "../../../response/normalized-instance-detail.response"; | ||
import {RouterLink} from "@angular/router"; | ||
import {CachedFediseerApiService} from "../../../services/cached-fediseer-api.service"; | ||
|
||
@Component({ | ||
selector: 'app-list-rebuttals', | ||
standalone: true, | ||
imports: [ | ||
SharedModule, | ||
RouterLink | ||
], | ||
templateUrl: './list-rebuttals.component.html', | ||
styleUrl: './list-rebuttals.component.scss' | ||
}) | ||
export class ListRebuttalsComponent implements OnInit { | ||
private rawInstances = signal<InstanceDetailResponse[]>([]); | ||
|
||
public loading = signal(true); | ||
public instances = computed(() => this.rawInstances().map(instance => NormalizedInstanceDetailResponse.fromInstanceDetail(instance))); | ||
public currentInstance = signal(this.authManager.currentInstanceSnapshot.name); | ||
|
||
constructor( | ||
private readonly titleService: TitleService, | ||
private readonly translator: TranslatorService, | ||
private readonly api: FediseerApiService, | ||
private readonly authManager: AuthenticationManagerService, | ||
private readonly apiResponseHelper: ApiResponseHelperService, | ||
private readonly cachedApi: CachedFediseerApiService, | ||
) { | ||
} | ||
public async ngOnInit(): Promise<void> { | ||
this.titleService.title = this.translator.get('app.my_rebuttals.title'); | ||
this.rawInstances.set(await toPromise(zip([ | ||
this.api.getHesitationsForInstance(this.currentInstance()), | ||
this.api.getCensuresForInstance(this.currentInstance()), | ||
]).pipe( | ||
map(responses => { | ||
if (this.apiResponseHelper.handleErrors(responses)) { | ||
return []; | ||
} | ||
|
||
return responses[0].successResponse!.instances.concat(responses[1].successResponse!.instances) | ||
.filter(instance => instance.rebuttal?.length) | ||
}), | ||
))); | ||
this.loading.set(false); | ||
} | ||
|
||
public async removeRebuttal(instance: NormalizedInstanceDetailResponse): Promise<void> { | ||
this.loading.set(true); | ||
const response = await toPromise(this.api.removeRebuttal(instance.domain)); | ||
this.apiResponseHelper.handleErrors(response); | ||
|
||
await Promise.all([ | ||
toPromise(this.cachedApi.getHesitationsForInstance(this.currentInstance(), {clear: true})), | ||
toPromise(this.cachedApi.getCensuresForInstance(this.currentInstance(), {clear: true})), | ||
]); | ||
this.cachedApi.clearCensuresByInstanceCache(instance.domain); | ||
this.cachedApi.clearHesitationsByInstanceCache(instance.domain); | ||
this.rawInstances.update(value => [...value.filter(rawInstance => rawInstance.domain !== instance.domain)]); | ||
|
||
this.loading.set(false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters