Random changes

This commit is contained in:
X4Lo committed 2024-10-21 16:06:32 +01:00
1 parent 7160669468
commit 0b1a1d989f
17 files changed
+205 -159

No files matched your search

@@ -1,4 +1,5 @@
<div class="movie-card" [@fadeInOut]="animationDirection">
<div class="movie-card" [@fadeInOut]="animationDirection" appContextMenuTrigger
[menuOptions]="contextMenuOptions">
<div class="card-head">
<img class="card-img" [src]="posterPath" alt="Movie Poster"
onerror="this.src='assets/images/default/default-poster.png'">
@@ -13,6 +13,7 @@ import { LibraryService } from '../../../../core/services/library.service';
import { Router } from '@angular/router';
import { ConfirmModalComponent } from '../../modals/confirm-modal/confirm-modal.component';
import { environment } from '../../../../../environments/environment.prod';
import { CONTEXT_MENU_OPTIONS } from '../../../constants/context-menu-options';
@Component({
selector: 'app-main-card',
@@ -251,4 +252,22 @@ export class MainCardComponent implements OnInit {
if (this.entry.runtime == null) return '';
return this.entry.runtime;
}
get contextMenuOptions() {
let options = [];
// ? 1 - is in library
if (this.entry.isInLibrary) {
if (this.entry.watchlist) {
options.push(CONTEXT_MENU_OPTIONS.removeFromWatchlist);
} else {
options.push(CONTEXT_MENU_OPTIONS.addToWatchlist);
}
} else {
// ? 2 - not in library
options.push(CONTEXT_MENU_OPTIONS.addToLibrary);
}
return options;
}
}
@@ -1,3 +1,4 @@
import { Collection } from './collection.model';
import { Entry } from './entry.model';
export interface Media {
@@ -7,12 +8,15 @@ export interface Media {
mediaable: string;
mediaableId: number;
entry: Entry;
collection: Collection;
type: string;
path: string;
isLocal: boolean;
isSelected: boolean;
isCustom: boolean;
isFavorit: boolean;
createdAt: Date;
updatedAt: Date;
@@ -1,3 +1,4 @@
import { Entry } from './entry.model';
import { Episode } from './episode.models';
export interface Season {
@@ -9,6 +10,7 @@ export interface Season {
imdb_id: string;
entry_id: number;
entry: Entry;
name: string;
overview: string;
@@ -1,109 +0,0 @@
import {
Injectable,
ComponentFactoryResolver,
ApplicationRef,
Injector,
EmbeddedViewRef,
ComponentRef,
} from '@angular/core';
import { NotificationPopupComponent } from '../components/notification-popup/notification-popup.component';
@Injectable({
providedIn: 'root',
})
export class NotificationService {
private notificationComponents: ComponentRef<NotificationPopupComponent>[] =
[];
private notificationBottomMargin = 10; // Margin between notifications
private baseBottomPosition = 20; // Starting bottom position for the first notification
constructor(
private componentFactoryResolver: ComponentFactoryResolver,
private appRef: ApplicationRef,
private injector: Injector
) {}
public showNotification(
title: string,
message: string,
type: string = 'alert',
timeout: number = 5000
): void {
// Create a component reference for the notification
const componentRef = this.componentFactoryResolver
.resolveComponentFactory(NotificationPopupComponent)
.create(this.injector);
// Assign the message and type to the instance
componentRef.instance.title = title;
componentRef.instance.message = message;
componentRef.instance.type = type;
// Attach the component to the application
this.appRef.attachView(componentRef.hostView);
// Convert the component's host view into a DOM element and append it to the body
const domElem = (componentRef.hostView as EmbeddedViewRef<any>)
.rootNodes[0] as HTMLElement;
document.body.appendChild(domElem);
const position =
this.baseBottomPosition +
this.notificationComponents.length *
(domElem.offsetHeight + this.notificationBottomMargin);
domElem.style.bottom = `${position}px`;
domElem.style.position = 'fixed';
domElem.style.right = '20px';
// Store the component reference for later removal
this.notificationComponents.push(componentRef);
// Remove the notification after a delay
setTimeout(() => {
domElem.style.visibility = 'hidden';
}, timeout);
setTimeout(() => {
this.removeNotification(componentRef);
}, timeout + 1000); // Customize this value as needed
}
// private removeNotification(
// componentRef: ComponentRef<NotificationPopupComponent>
// ): void {
// this.appRef.detachView(componentRef.hostView);
// componentRef.destroy();
// this.notificationComponents = this.notificationComponents.filter(
// (c) => c !== componentRef
// );
// }
private removeNotification(
componentRef: ComponentRef<NotificationPopupComponent>
): void {
const domElem = (componentRef.hostView as EmbeddedViewRef<any>)
.rootNodes[0] as HTMLElement;
this.appRef.detachView(componentRef.hostView);
document.body.removeChild(domElem); // Make sure to remove the element from the body
componentRef.destroy();
// Filter out the destroyed notification
this.notificationComponents = this.notificationComponents.filter(
(c) => c !== componentRef
);
// Adjust positions of remaining notifications
this.adjustPositions();
}
private adjustPositions(): void {
// Start from the initial position again and reposition each remaining notification
this.notificationComponents.forEach((componentRef, index) => {
const domElem = (componentRef.hostView as EmbeddedViewRef<any>)
.rootNodes[0] as HTMLElement;
const position =
this.baseBottomPosition +
index * (domElem.offsetHeight + this.notificationBottomMargin);
domElem.style.bottom = `${position}px`;
});
}
}
@@ -0,0 +1,43 @@
import { Injectable } from '@angular/core';
import { ProgressAnimationType, ToastrService } from 'ngx-toastr';
@Injectable({
providedIn: 'root',
})
export class ToastService {
constructor(private toastr: ToastrService) {}
public show(title: string, message: string, type: string = 'success'): void {
const options = {
tapToDismiss: true,
progressBar: true,
positionClass: 'top-right',
progressAnimation: 'increasing' as ProgressAnimationType,
};
if (type == 'success') this.toastr.show(title, message, options);
else if (type == 'error') this.toastr.error(title, message, options);
else if (type == 'warning') this.toastr.warning(title, message, options);
else if (type == 'info') this.toastr.info(title, message, options);
}
public showWithOptions(
title: string,
message: string,
type: string = 'success',
extraOptions: any
): void {
const options = {
tapToDismiss: true,
progressBar: true,
positionClass: 'top-right',
progressAnimation: 'increasing' as ProgressAnimationType,
...extraOptions,
};
if (type == 'success') this.toastr.success(title, message, options);
else if (type == 'error') this.toastr.error(title, message, options);
else if (type == 'warning') this.toastr.warning(title, message, options);
else if (type == 'info') this.toastr.info(title, message, options);
}
}