refactor: remove unused code and apply minor optimizations

This commit is contained in:
Chneemann 2025-04-18 20:36:38 +02:00
parent 37cdddab1a
commit 239c4f59e1
9 changed files with 14 additions and 163 deletions

View file

@ -52,7 +52,6 @@ export class LoginComponent implements OnInit, OnDestroy {
) {}
ngOnInit(): void {
this.routeParams();
this.deleteTokens();
}
@ -61,17 +60,6 @@ export class LoginComponent implements OnInit, OnDestroy {
this.destroy$.complete();
}
routeParams() {
this.route.params.pipe(takeUntil(this.destroy$)).subscribe((params) => {
if (params['id'] && params['id'] === 'pw-send') {
this.overlayService.setOverlayData('dialog', 'pw-send');
}
if (params['id'] && params['id'] === 'pw-change') {
this.overlayService.setOverlayData('dialog', 'pw-change');
}
});
}
isButtonDisabled() {
return this.buttonStateService.isButtonDisabled;
}

View file

@ -43,7 +43,7 @@
<div class="date">
<div>
@if (urgentTasks.length) {
<span>{{ nextUrgentTask }}</span>
<span>{{ nextUrgentTask | date }}</span>
<p class="spacer">
{{ "summary.upcomingDeadline" | translate }}
</p>

View file

@ -16,11 +16,13 @@ import {
PRIORITIES,
PRIORITY_LABELS,
} from '../../constants/task-priority.constants';
import { CommonModule } from '@angular/common';
@Component({
selector: 'app-summary',
standalone: true,
imports: [
CommonModule,
RouterModule,
TranslateModule,
LoadingSpinnerComponent,
@ -49,9 +51,8 @@ export class SummaryComponent implements OnInit, OnDestroy {
) {}
/**
* This method performs the following actions:
* - Calls the loadAllTasks method to load all tasks.
* - Calls the loadCurrentUser method to load the current user.
* Loads all tasks and the current user. Initializes the component
* by fetching necessary data from the TaskService and UserService.
*/
ngOnInit(): void {
this.loadAllTasks();
@ -132,31 +133,12 @@ export class SummaryComponent implements OnInit, OnDestroy {
* Retrieves the date of the next urgent task.
* @returns {string | null} The date of the next urgent task formatted as a string, or null if no urgent tasks exist.
*/
get nextUrgentTask(): string | null {
if (this.urgentTasks.length === 0) return null;
const nextTask = this.urgentTasks.reduce((earliest, current) => {
return Date.parse(current.date) < Date.parse(earliest.date)
? current
: earliest;
});
return this.timeConverter(nextTask.date);
}
/**
* Converts a date string to a human-readable format.
* @param dateString - The date string to convert.
* @returns A string representing the date in the format "MMM. DD, YYYY".
*/
timeConverter(dateString: string): string {
const date = new Date(dateString);
return date.toLocaleDateString('en-US', {
month: 'short',
day: 'numeric',
year: 'numeric',
});
return this.urgentTasks.length
? this.urgentTasks.reduce((a, b) =>
Date.parse(a.date) < Date.parse(b.date) ? a : b
).date
: null;
}
/**
@ -164,14 +146,9 @@ export class SummaryComponent implements OnInit, OnDestroy {
* @returns a localized greeting string.
*/
get greeting(): string {
const currentHour = new Date().getHours();
if (currentHour >= 5 && currentHour < 12) {
return this.translateService.instant('summary.morning');
}
if (currentHour >= 12 && currentHour < 18) {
return this.translateService.instant('summary.afternoon');
}
return this.translateService.instant('summary.evening');
const hour = new Date().getHours();
const key =
hour < 5 || hour >= 18 ? 'evening' : hour < 12 ? 'morning' : 'afternoon';
return this.translateService.instant(`summary.${key}`);
}
}

View file

@ -1,12 +0,0 @@
<section>
<div class="header">
<div class="headline">{{ "msgDialog.noticeHeadline" | translate }}</div>
<app-btn-close (click)="closeOverlay()"></app-btn-close>
</div>
<p>
@if (overlayData === "pw-send") { {{ "msgDialog.pwSend" | translate }} }
</p>
<p>
@if (overlayData === "pw-change") { {{ "msgDialog.pwChange" | translate }} }
</p>
</section>

View file

@ -1,41 +0,0 @@
section {
width: 500px;
height: fit-content;
padding: 24px;
border-radius: 24px;
background-color: var(--white);
box-shadow: 4px 4px 4px 0px rgba(0, 0, 0, 0.1);
p {
text-align: center;
font-size: 21px;
font-weight: 500;
padding-bottom: 12px;
}
}
.header {
display: flex;
justify-content: space-between;
align-items: center;
padding-bottom: 18px;
.headline {
font-size: 24px;
font-weight: 700;
}
}
/*------------- RESPONSIVE -------------*/
@media screen and (max-width: 600px) {
section {
width: calc(100vw - 96px);
}
}
@media screen and (max-width: 450px) {
section {
p {
font-size: 18px;
}
}
}

View file

@ -1,23 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { DialogOverlayComponent } from './dialog-overlay.component';
describe('DialogOverlayComponent', () => {
let component: DialogOverlayComponent;
let fixture: ComponentFixture<DialogOverlayComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [DialogOverlayComponent]
})
.compileComponents();
fixture = TestBed.createComponent(DialogOverlayComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View file

@ -1,29 +0,0 @@
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { BtnCloseComponent } from '../../buttons/btn-close/btn-close.component';
import { Router } from '@angular/router';
import { TranslateModule } from '@ngx-translate/core';
@Component({
selector: 'app-dialog-overlay',
standalone: true,
imports: [BtnCloseComponent, TranslateModule],
templateUrl: './dialog-overlay.component.html',
styleUrl: './dialog-overlay.component.scss',
})
export class DialogOverlayComponent {
@Input() overlayData: string = '';
@Input() overlayType: string = '';
@Output() closeDialogEmitter = new EventEmitter<boolean>();
constructor(private router: Router) {}
/**
* Navigates to the login route and emits an empty string via the
* "closeDialogEmitter" output event, which can be used to close the overlay
* from the parent component.
*/
closeOverlay() {
this.router.navigate(['/login']);
this.closeDialogEmitter.emit(false);
}
}

View file

@ -21,12 +21,6 @@
[overlayType]="overlayType"
(closeDialogEmitter)="onCloseOverlay()"
></app-task-edit-overlay>
} @case ('dialogOverlay') {
<app-dialog-overlay
[overlayData]="overlayData"
[overlayType]="overlayType"
(closeDialogEmitter)="onCloseOverlay()"
></app-dialog-overlay>
} @case ('contactOverlay') {
<app-contact-overlay
[overlayData]="overlayData"

View file

@ -3,7 +3,6 @@ import { OverlayService } from '../../../services/overlay.service';
import { CommonModule } from '@angular/common';
import { TaskOverlayComponent } from './task-overlay/task-overlay.component';
import { TaskEditOverlayComponent } from './task-edit-overlay/task-edit-overlay.component';
import { DialogOverlayComponent } from './dialog-overlay/dialog-overlay.component';
import { ContactOverlayComponent } from './contact-overlay/contact-overlay.component';
import { Subject, takeUntil } from 'rxjs';
@ -15,7 +14,6 @@ import { Subject, takeUntil } from 'rxjs';
TaskOverlayComponent,
TaskEditOverlayComponent,
ContactOverlayComponent,
DialogOverlayComponent,
],
templateUrl: './overlay.component.html',
styleUrl: './overlay.component.scss',
@ -25,7 +23,6 @@ export class OverlayComponent implements OnInit, OnDestroy {
| 'taskOverlay'
| 'taskOverlayEdit'
| 'newTaskOverlay'
| 'dialogOverlay'
| 'contactOverlay'
| null = null;
overlayData: any = null;