Load, save, and delete chapter reviews

This commit is contained in:
Amelia 2025-04-25 22:38:32 +02:00
parent a3e04f3bc1
commit 85b6f107bc
No known key found for this signature in database
GPG key ID: D6D0ECE365407EAA
13 changed files with 192 additions and 13 deletions

View file

@ -3,6 +3,7 @@ import {environment} from "../../environments/environment";
import { HttpClient } from "@angular/common/http";
import {Chapter} from "../_models/chapter";
import {TextResonse} from "../_types/text-response";
import {UserReview} from "../_single-module/review-card/user-review";
@Injectable({
providedIn: 'root'
@ -29,4 +30,16 @@ export class ChapterService {
return this.httpClient.post(this.baseUrl + 'chapter/update', chapter, TextResonse);
}
chapterReviews(chapterId: number) {
return this.httpClient.get<Array<UserReview>>(this.baseUrl + 'chapter/review?chapterId='+chapterId);
}
updateChapterReview(seriesId: number, chapterId: number, body: string) {
return this.httpClient.post<UserReview>(this.baseUrl + 'review/chapter/'+chapterId, {seriesId, body});
}
deleteChapterReview(chapterId: number) {
return this.httpClient.delete(this.baseUrl + 'review/chapter/'+chapterId);
}
}

View file

@ -1,4 +1,4 @@
<ng-container *transloco="let t; read:'review-series-modal'">
<ng-container *transloco="let t; read:'review-modal'">
<div>
<div class="modal-header">
<h4 class="modal-title" id="modal-basic-title">{{t('title')}}</h4>

View file

@ -7,6 +7,7 @@ import {translate, TranslocoDirective} from "@jsverse/transloco";
import {ConfirmService} from "../../shared/confirm.service";
import {ToastrService} from "ngx-toastr";
import {ChapterService} from "../../_services/chapter.service";
import {of} from "rxjs";
export enum ReviewSeriesModalCloseAction {
Create,
@ -55,12 +56,18 @@ export class ReviewModalComponent implements OnInit {
async delete() {
if (!await this.confirmService.confirm(translate('toasts.delete-review'))) return;
let obs;
if (this.reviewLocation === 'series') {
this.seriesService.deleteReview(this.review.seriesId).subscribe(() => {
this.toastr.success(translate('toasts.review-deleted'));
this.modal.close({success: true, review: this.review, action: ReviewSeriesModalCloseAction.Delete});
});
obs = this.seriesService.deleteReview(this.review.seriesId);
}
if (this.reviewLocation === 'chapter') {
obs = this.chapterService.deleteChapterReview(this.review.chapterId!)
}
obs?.subscribe(() => {
this.toastr.success(translate('toasts.review-deleted'));
this.modal.close({success: true, review: this.review, action: ReviewSeriesModalCloseAction.Delete});
});
}
save() {
@ -69,11 +76,17 @@ export class ReviewModalComponent implements OnInit {
return;
}
let obs;
if (this.reviewLocation === 'series') {
this.seriesService.updateReview(this.review.seriesId, model.reviewBody).subscribe(review => {
this.modal.close({success: true, review: review, action: ReviewSeriesModalCloseAction.Edit});
});
obs = this.seriesService.updateReview(this.review.seriesId, model.reviewBody);
}
if (this.reviewLocation === 'chapter') {
obs = this.chapterService.updateChapterReview(this.review.seriesId, this.review.chapterId!, model.reviewBody);
}
obs?.subscribe(review => {
this.modal.close({success: true, review: review, action: ReviewSeriesModalCloseAction.Edit});
});
}
}

View file

@ -177,7 +177,7 @@
<li [ngbNavItem]="TabID.Reviews">
<a ngbNavLink>
{{t(TabID.Reviews)}}
{{t('reviews-tab')}}
<span class="badge rounded-pill text-bg-secondary">{{userReviews.length + plusReviews.length}}</span>
</a>
<ng-template ngbNavContent>

View file

@ -222,7 +222,8 @@ export class ChapterDetailComponent implements OnInit {
forkJoin({
series: this.seriesService.getSeries(this.seriesId),
chapter: this.chapterService.getChapterMetadata(this.chapterId),
libraryType: this.libraryService.getLibraryType(this.libraryId)
libraryType: this.libraryService.getLibraryType(this.libraryId),
reviews: this.chapterService.chapterReviews(this.chapterId),
}).subscribe(results => {
if (results.chapter === null) {
@ -234,6 +235,8 @@ export class ChapterDetailComponent implements OnInit {
this.chapter = results.chapter;
this.weblinks = this.chapter.webLinks.split(',');
this.libraryType = results.libraryType;
this.userReviews = results.reviews.filter(r => !r.isExternal);
this.plusReviews = results.reviews.filter(r => r.isExternal);
this.themeService.setColorScape(this.chapter.primaryColor, this.chapter.secondaryColor);

View file

@ -72,7 +72,7 @@
"user-reviews-plus": "External Reviews"
},
"review-series-modal": {
"review-modal": {
"title": "Edit Review",
"review-label": "Review",
"close": "{{common.close}}",