clean code

This commit is contained in:
Chneemann 2024-05-27 16:26:38 +02:00
parent c7e64d34c3
commit e0677e9971
8 changed files with 56 additions and 73 deletions

View file

@ -1,20 +1,25 @@
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { RegisterComponent } from "./register/register.component"; import { RegisterComponent } from './register/register.component';
import { ChooseAvatarComponent } from "./choose-avatar/choose-avatar.component"; import { ChooseAvatarComponent } from './choose-avatar/choose-avatar.component';
import { LoginComponent } from "./login/login.component"; import { LoginComponent } from './login/login.component';
import { PasswordForgetComponent } from "./password-forget/password-forget.component"; import { PasswordForgetComponent } from './password-forget/password-forget.component';
import { PasswordResetComponent } from "./password-reset/password-reset.component"; import { PasswordResetComponent } from './password-reset/password-reset.component';
import { loginService } from '../../service/login.service';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { RouterLink } from '@angular/router'; import { RouterLink } from '@angular/router';
@Component({ @Component({
selector: 'app-main-login', selector: 'app-main-login',
standalone: true, standalone: true,
templateUrl: './main-login.component.html', templateUrl: './main-login.component.html',
styleUrl: './main-login.component.scss', styleUrl: './main-login.component.scss',
imports: [CommonModule,RegisterComponent, ChooseAvatarComponent, LoginComponent, PasswordForgetComponent, PasswordResetComponent,RouterLink] imports: [
CommonModule,
RegisterComponent,
ChooseAvatarComponent,
LoginComponent,
PasswordForgetComponent,
PasswordResetComponent,
RouterLink,
],
}) })
export class MainLoginComponent { export class MainLoginComponent {}
}

View file

@ -8,7 +8,7 @@ import { getAuth, sendPasswordResetEmail } from 'firebase/auth';
import { Firestore } from '@angular/fire/firestore'; import { Firestore } from '@angular/fire/firestore';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { StartHeaderComponent } from '../../../shared/components/login/start-header/start-header.component'; import { StartHeaderComponent } from '../../../shared/components/login/start-header/start-header.component';
import { TranslateModule} from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
@Component({ @Component({
selector: 'app-password-forget', selector: 'app-password-forget',
@ -22,18 +22,16 @@ import { TranslateModule} from '@ngx-translate/core';
RouterModule, RouterModule,
SmallBtnComponent, SmallBtnComponent,
StartHeaderComponent, StartHeaderComponent,
TranslateModule TranslateModule,
], ],
}) })
export class PasswordForgetComponent { export class PasswordForgetComponent {
email: string = ''; email: string = '';
emailSentBtn = false; emailSentBtn = false;
firestore: Firestore = inject(Firestore); firestore: Firestore = inject(Firestore);
constructor(private router: Router) {} constructor(private router: Router) {}
/**
/**
* Initiates a password reset process for the user. * Initiates a password reset process for the user.
* Sends a password reset email to the user's registered email address. * Sends a password reset email to the user's registered email address.
* *
@ -44,7 +42,7 @@ export class PasswordForgetComponent {
sendPasswordResetEmail(auth, this.email) sendPasswordResetEmail(auth, this.email)
.then(() => { .then(() => {
ngForm.resetForm(ngForm); ngForm.resetForm(ngForm);
this.router.navigate(['/login']); this.router.navigate(['/login']);
}) })
.catch((error) => { .catch((error) => {
const errorCode = error.code; const errorCode = error.code;
@ -52,8 +50,7 @@ export class PasswordForgetComponent {
}); });
} }
/**
/**
* Handles the form submission, invoking the password reset function and then sending a notification email. * Handles the form submission, invoking the password reset function and then sending a notification email.
* *
* @param ngForm The form instance containing user input. * @param ngForm The form instance containing user input.
@ -63,7 +60,6 @@ export class PasswordForgetComponent {
this.sendEmail(); this.sendEmail();
} }
/** /**
* Simulates sending an email by toggling a button state to show feedback to the user. * Simulates sending an email by toggling a button state to show feedback to the user.
* After a set timeout, resets the button state. * After a set timeout, resets the button state.

View file

@ -1,4 +1,4 @@
import { Component, inject } from '@angular/core'; import { Component } from '@angular/core';
import { FooterComponent } from '../../../shared/components/login/footer/footer.component'; import { FooterComponent } from '../../../shared/components/login/footer/footer.component';
import { FormsModule, NgForm } from '@angular/forms'; import { FormsModule, NgForm } from '@angular/forms';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
@ -21,7 +21,7 @@ import { TranslateModule } from '@ngx-translate/core';
FooterComponent, FooterComponent,
RouterModule, RouterModule,
SmallBtnComponent, SmallBtnComponent,
TranslateModule TranslateModule,
], ],
templateUrl: './password-reset.component.html', templateUrl: './password-reset.component.html',
styleUrl: './password-reset.component.scss', styleUrl: './password-reset.component.scss',
@ -32,15 +32,11 @@ export class PasswordResetComponent {
oobCode: string = ''; oobCode: string = '';
private queryParamsSubscription: Subscription = new Subscription(); private queryParamsSubscription: Subscription = new Subscription();
constructor( constructor(private route: ActivatedRoute, private router: Router) {}
private route: ActivatedRoute,
private router: Router,
) {}
/**
/** * Initializes the component by subscribing to query parameters.
* Initializes the component by subscribing to query parameters. */
*/
ngOnInit(): void { ngOnInit(): void {
this.queryParamsSubscription = this.route.queryParams.subscribe( this.queryParamsSubscription = this.route.queryParams.subscribe(
(params) => { (params) => {
@ -49,20 +45,18 @@ export class PasswordResetComponent {
); );
} }
/**
/** * Handles the submission of the password reset form.
* Handles the submission of the password reset form. * @param ngForm The form data of the password reset form.
* @param ngForm The form data of the password reset form. */
*/
onSubmit(ngForm: NgForm): void { onSubmit(ngForm: NgForm): void {
this.resetPassword(ngForm); this.resetPassword(ngForm);
} }
/**
/** * Performs the password reset operation using Firebase Authentication.
* Performs the password reset operation using Firebase Authentication. * @param ngForm The form data of the password reset form.
* @param ngForm The form data of the password reset form. */
*/
resetPassword(ngForm: NgForm): void { resetPassword(ngForm: NgForm): void {
const auth = getAuth(); const auth = getAuth();
const newPassword = this.passwordRepeat; const newPassword = this.passwordRepeat;
@ -76,19 +70,17 @@ export class PasswordResetComponent {
}); });
} }
/** /**
* Cleans up the component by unsubscribing from the query parameters subscription. * Cleans up the component by unsubscribing from the query parameters subscription.
*/ */
ngOnDestroy(): void { ngOnDestroy(): void {
this.queryParamsSubscription.unsubscribe(); this.queryParamsSubscription.unsubscribe();
} }
/** /**
* Checks if the entered passwords match. * Checks if the entered passwords match.
* @returns true if the password and repeated password are the same. * @returns true if the password and repeated password are the same.
*/ */
passwordsMatch(): boolean { passwordsMatch(): boolean {
return this.password === this.passwordRepeat; return this.password === this.passwordRepeat;
} }

View file

@ -1,6 +1,5 @@
import { import {
AfterViewChecked, AfterViewChecked,
AfterViewInit,
Component, Component,
ElementRef, ElementRef,
Input, Input,
@ -10,12 +9,10 @@ import {
import { UserService } from '../../service/user.service'; import { UserService } from '../../service/user.service';
import { ChannleService } from '../../service/channle.service'; import { ChannleService } from '../../service/channle.service';
import { ChatService } from '../../service/chat.service'; import { ChatService } from '../../service/chat.service';
import { Channel } from '../../interface/channel.interface';
import { MainComponent } from '../main/main.component'; import { MainComponent } from '../main/main.component';
import { SingleChatComponent } from '../main-chat/single-chat/single-chat.component'; import { SingleChatComponent } from '../main-chat/single-chat/single-chat.component';
import { Chat, ChatAnswers } from '../../interface/chat.interface'; import { Chat, ChatAnswers } from '../../interface/chat.interface';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { User } from '../../interface/user.interface';
import { ChatMsgBoxComponent } from '../main-chat/chat-msg-box/chat-msg-box.component'; import { ChatMsgBoxComponent } from '../main-chat/chat-msg-box/chat-msg-box.component';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';

View file

@ -1,4 +1,4 @@
import { ChangeDetectorRef, Component, Input, OnInit } from '@angular/core'; import { Component, Input, OnInit } from '@angular/core';
import { ActivatedRoute, RouterModule } from '@angular/router'; import { ActivatedRoute, RouterModule } from '@angular/router';
import { SidebarChannelsComponent } from './sidebar-channels/sidebar-channels.component'; import { SidebarChannelsComponent } from './sidebar-channels/sidebar-channels.component';
import { SidebarDirectMessagesComponent } from './sidebar-direct-messages/sidebar-direct-messages.component'; import { SidebarDirectMessagesComponent } from './sidebar-direct-messages/sidebar-direct-messages.component';

View file

@ -1,4 +1,4 @@
import { Injectable, Input, OnInit } from '@angular/core'; import { Injectable } from '@angular/core';
import { import {
getDownloadURL, getDownloadURL,
getStorage, getStorage,
@ -23,7 +23,6 @@ export class DownloadFilesService {
} }
loadAllFiles(docID: string) { loadAllFiles(docID: string) {
// lädt die fails in den firebase storage
const storage = getStorage(); const storage = getStorage();
for (const file of this.uploadFiles) { for (const file of this.uploadFiles) {
const storageRef = ref(storage, `chatFiles/${docID}/${file.name}`); const storageRef = ref(storage, `chatFiles/${docID}/${file.name}`);
@ -54,7 +53,6 @@ export class DownloadFilesService {
downloadedFilesData.push({ id: folderID, files: folderFiles }); downloadedFilesData.push({ id: folderID, files: folderFiles });
} }
// Emit the updated value // Emit the updated value
this.downloadedFiles.next(downloadedFilesData); this.downloadedFiles.next(downloadedFilesData);
}) })

View file

@ -11,14 +11,11 @@ export class LanguageService {
this.translate.setDefaultLang(this.currentLang); this.translate.setDefaultLang(this.currentLang);
} }
/** /**
* Switches the application's current language. * Switches the application's current language.
* * This method sets the current language based on the specified `lang` parameter and updates the translation service to use the new language. This is useful for enabling runtime language switching in a multi-lingual application.
* This method sets the current language based on the specified `lang` parameter and updates the translation service to use the new language. This is useful for enabling runtime language switching in a multi-lingual application. * @param lang The language code to switch to. Supported values are 'en' for English and 'de' for German.
* */
* @param lang The language code to switch to. Supported values are 'en' for English and 'de' for German.
*/
switchLanguage() { switchLanguage() {
this.currentLang = this.currentLang === 'en' ? 'de' : 'en'; this.currentLang = this.currentLang === 'en' ? 'de' : 'en';
this.translate.use(this.currentLang); this.translate.use(this.currentLang);

View file

@ -1,25 +1,23 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root',
}) })
export class ToggleBooleanService { export class ToggleBooleanService {
constructor() {}
constructor() { }
openSearchWindow: boolean = false; openSearchWindow: boolean = false;
openChannelMemberWindow: boolean = false; openChannelMemberWindow: boolean = false;
closeChannelMemberWindow: boolean = false; closeChannelMemberWindow: boolean = false;
openSearchWindowHead: boolean = false; openSearchWindowHead: boolean = false;
selectUserInMsgBox:boolean = false; selectUserInMsgBox: boolean = false;
isSidebarOpen: boolean = true; isSidebarOpen: boolean = true;
/** /**
* Opens or closes the add member window based on the provided boolean value. * Opens or closes the add member window based on the provided boolean value.
* @param boolean A boolean value to determine whether to open or close the add member window. * @param boolean A boolean value to determine whether to open or close the add member window.
*/ */
openAddMemberWindow(boolean : boolean){ openAddMemberWindow(boolean: boolean) {
this.closeChannelMemberWindow = boolean; this.closeChannelMemberWindow = boolean;
} }
} }