diff --git a/apps/NwaifuAnime/src/app/app.component.html b/apps/NwaifuAnime/src/app/app.component.html
index 8d5d324..f6d2c90 100644
--- a/apps/NwaifuAnime/src/app/app.component.html
+++ b/apps/NwaifuAnime/src/app/app.component.html
@@ -11,3 +11,4 @@
+
diff --git a/apps/NwaifuAnime/src/app/app.component.ts b/apps/NwaifuAnime/src/app/app.component.ts
index c57fac1..2ebfc62 100644
--- a/apps/NwaifuAnime/src/app/app.component.ts
+++ b/apps/NwaifuAnime/src/app/app.component.ts
@@ -2,11 +2,11 @@ import { Component } from "@angular/core";
import { RouterModule } from "@angular/router";
import { AppService } from "./app.service";
import { HeaderComponent } from "./components/header/header.component";
-import { Datum } from "./services/parsers/rulib/rulib.search.dto";
+import { NotificationComponent } from "./components/notification/notification.component";
@Component({
standalone: true,
- imports: [RouterModule, HeaderComponent],
+ imports: [RouterModule, HeaderComponent, NotificationComponent, NotificationComponent],
selector: "app-root",
templateUrl: "./app.component.html",
styleUrl: "./app.component.less",
@@ -14,7 +14,6 @@ import { Datum } from "./services/parsers/rulib/rulib.search.dto";
})
export class AppComponent {
title = "NwaifuAnime";
- items: Datum[] = [];
constructor(private sw: AppService) {}
get hasUpdate() {
diff --git a/apps/NwaifuAnime/src/app/components/auth/auth.component.ts b/apps/NwaifuAnime/src/app/components/auth/auth.component.ts
index 576b461..a6a103c 100644
--- a/apps/NwaifuAnime/src/app/components/auth/auth.component.ts
+++ b/apps/NwaifuAnime/src/app/components/auth/auth.component.ts
@@ -2,6 +2,7 @@ import { CommonModule } from "@angular/common";
import { AfterViewInit, Component, ElementRef, OnDestroy, ViewChild } from "@angular/core";
import { ActivatedRoute, Router, RouterLink } from "@angular/router";
import { Subject, takeUntil } from "rxjs";
+import { NotificationService } from "../../services/notification/notification.service";
import { RulibAuthService } from "../../services/parsers/rulib/rulib.auth.service";
import { EAuthTokenService } from "./enum";
@@ -20,18 +21,34 @@ export class AuthComponent implements AfterViewInit, OnDestroy {
private route: ActivatedRoute,
private router: Router,
private rulibAuthService: RulibAuthService,
+ private notificationService: NotificationService,
) {}
private setToken(service: EAuthTokenService, token: string) {
switch (service) {
case EAuthTokenService.RULIB:
- this.rulibAuthService.setToken(token);
+ this.rulibAuthService
+ .setToken(token)
+ .pipe(takeUntil(this.destroy$))
+ .subscribe((data) => {
+ if (data) {
+ this.router.navigate(["/"]);
+ this.notificationService.info("Успешная авторизация в RuLib!", "Вход");
+ } else {
+ this.router.navigate(["/", "auth"]);
+ this.notificationService.error(
+ "Не удалось авторизоваться в RuLib! Попробуйте ещё раз.",
+ "Вход",
+ 4000,
+ );
+ }
+ });
break;
default:
this.router.navigate(["/", "auth"]);
+ this.notificationService.error("Неизвестный сервис авторизации!", "Вход");
return;
}
- this.router.navigate(["/"]);
}
setLibSocialToken() {
diff --git a/apps/NwaifuAnime/src/app/components/notification/notification.component.html b/apps/NwaifuAnime/src/app/components/notification/notification.component.html
new file mode 100644
index 0000000..5cbeeb0
--- /dev/null
+++ b/apps/NwaifuAnime/src/app/components/notification/notification.component.html
@@ -0,0 +1,12 @@
+
+
+
+
{{ notification.name }}
+
+
+
{{ notification.message }}
+
+
diff --git a/apps/NwaifuAnime/src/app/components/notification/notification.component.less b/apps/NwaifuAnime/src/app/components/notification/notification.component.less
new file mode 100644
index 0000000..e69de29
diff --git a/apps/NwaifuAnime/src/app/components/notification/notification.component.ts b/apps/NwaifuAnime/src/app/components/notification/notification.component.ts
new file mode 100644
index 0000000..9d86d09
--- /dev/null
+++ b/apps/NwaifuAnime/src/app/components/notification/notification.component.ts
@@ -0,0 +1,53 @@
+import { CommonModule } from "@angular/common";
+import { AfterViewInit, Component, OnDestroy } from "@angular/core";
+import { Subject, takeUntil } from "rxjs";
+import { INotification } from "../../services/notification/notification.dto";
+import { NotificationService } from "../../services/notification/notification.service";
+
+@Component({
+ standalone: true,
+ selector: "app-notification",
+ templateUrl: "./notification.component.html",
+ styleUrls: ["./notification.component.less"],
+ imports: [CommonModule],
+})
+export class NotificationComponent implements AfterViewInit, OnDestroy {
+ show_notification = false;
+ isError = false;
+ private closeNotificationTimer: ReturnType | null = null;
+ notification: INotification = { isError: false, message: "", name: "", time: 0 };
+
+ private destroy$ = new Subject();
+
+ constructor(private notificationService: NotificationService) {}
+
+ ngAfterViewInit(): void {
+ this.notificationService.notification$
+ .asObservable()
+ .pipe(takeUntil(this.destroy$))
+ .subscribe((data) => {
+ if (!data) return;
+ this.notification = data;
+ this.show_notification = true;
+ if (this.closeNotificationTimer) {
+ clearTimeout(this.closeNotificationTimer);
+ }
+ this.closeNotificationTimer = setTimeout(() => {
+ this.show_notification = false;
+ }, data.time);
+ });
+ }
+
+ ngOnDestroy(): void {
+ this.destroy$.next();
+ this.destroy$.complete();
+ }
+
+ closeNotification() {
+ this.show_notification = false;
+ }
+
+ get borderColor(): string {
+ return this.notification.isError ? "border-red-600" : "border-green-600";
+ }
+}
diff --git a/apps/NwaifuAnime/src/app/services/notification/notification.dto.ts b/apps/NwaifuAnime/src/app/services/notification/notification.dto.ts
new file mode 100644
index 0000000..313a632
--- /dev/null
+++ b/apps/NwaifuAnime/src/app/services/notification/notification.dto.ts
@@ -0,0 +1,6 @@
+export interface INotification {
+ message: string;
+ isError: boolean;
+ time: number;
+ name: string;
+}
diff --git a/apps/NwaifuAnime/src/app/services/notification/notification.service.ts b/apps/NwaifuAnime/src/app/services/notification/notification.service.ts
new file mode 100644
index 0000000..ae34159
--- /dev/null
+++ b/apps/NwaifuAnime/src/app/services/notification/notification.service.ts
@@ -0,0 +1,32 @@
+import { Injectable } from "@angular/core";
+import { Subject } from "rxjs";
+import { INotification } from "./notification.dto";
+
+@Injectable({
+ providedIn: "root",
+})
+export class NotificationService {
+ readonly notification$ = new Subject();
+
+ private sendNotification(message: INotification) {
+ this.notification$.next(message);
+ }
+
+ info(message: string, title: string = "", time = 3000) {
+ this.sendNotification({
+ message,
+ isError: false,
+ time: time,
+ name: title,
+ });
+ }
+
+ error(message: string, title: string = "", time = 3000) {
+ this.sendNotification({
+ message,
+ isError: true,
+ time: time,
+ name: title,
+ });
+ }
+}
diff --git a/apps/NwaifuAnime/src/app/services/parsers/rulib/rulib.auth.service.ts b/apps/NwaifuAnime/src/app/services/parsers/rulib/rulib.auth.service.ts
index d1d2730..47e0f4d 100644
--- a/apps/NwaifuAnime/src/app/services/parsers/rulib/rulib.auth.service.ts
+++ b/apps/NwaifuAnime/src/app/services/parsers/rulib/rulib.auth.service.ts
@@ -9,13 +9,16 @@ export class RulibAuthService implements OnDestroy {
private api_url = "https://api.lib.social";
constructor(private http: HttpClient) {}
- setToken(token: string) {
- this.checkToken(token)
+ setToken(token: string): Observable {
+ return this.checkToken(token)
.pipe(takeUntil(this.destroy$))
- .subscribe((data) => {
- if (!data) return;
- localStorage.setItem("token", token);
- });
+ .pipe(
+ map((data) => {
+ if (!data) return false;
+ localStorage.setItem("token", token);
+ return true;
+ }),
+ );
}
getToken(): string {