mirror of
				https://github.com/richard-loafle/fuse-angular.git
				synced 2025-11-04 13:13:33 +00:00 
			
		
		
		
	(layout/common) Added trackBy functions to ngFor loops in common components
This commit is contained in:
		
							parent
							
								
									ee86dc6245
								
							
						
					
					
						commit
						4694bb401d
					
				@ -9,7 +9,7 @@
 | 
				
			|||||||
<mat-menu
 | 
					<mat-menu
 | 
				
			||||||
    [xPosition]="'before'"
 | 
					    [xPosition]="'before'"
 | 
				
			||||||
    #languages="matMenu">
 | 
					    #languages="matMenu">
 | 
				
			||||||
    <ng-container *ngFor="let lang of availableLangs">
 | 
					    <ng-container *ngFor="let lang of availableLangs; trackBy: trackByFn">
 | 
				
			||||||
        <button
 | 
					        <button
 | 
				
			||||||
            mat-menu-item
 | 
					            mat-menu-item
 | 
				
			||||||
            (click)="setActiveLang(lang.id)">
 | 
					            (click)="setActiveLang(lang.id)">
 | 
				
			||||||
 | 
				
			|||||||
@ -78,6 +78,17 @@ export class LanguageComponent implements OnInit, OnDestroy
 | 
				
			|||||||
        this._translocoService.setActiveLang(lang);
 | 
					        this._translocoService.setActiveLang(lang);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Track by function for ngFor loops
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param index
 | 
				
			||||||
 | 
					     * @param item
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    trackByFn(index: number, item: any): any
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return item.id || index;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // -----------------------------------------------------------------------------------------------------
 | 
					    // -----------------------------------------------------------------------------------------------------
 | 
				
			||||||
    // @ Private methods
 | 
					    // @ Private methods
 | 
				
			||||||
    // -----------------------------------------------------------------------------------------------------
 | 
					    // -----------------------------------------------------------------------------------------------------
 | 
				
			||||||
 | 
				
			|||||||
@ -46,7 +46,7 @@
 | 
				
			|||||||
        <!-- Content -->
 | 
					        <!-- Content -->
 | 
				
			||||||
        <div class="relative flex flex-col flex-auto sm:max-h-120 divide-y overflow-y-auto bg-card">
 | 
					        <div class="relative flex flex-col flex-auto sm:max-h-120 divide-y overflow-y-auto bg-card">
 | 
				
			||||||
            <!-- Messages -->
 | 
					            <!-- Messages -->
 | 
				
			||||||
            <ng-container *ngFor="let message of messages">
 | 
					            <ng-container *ngFor="let message of messages; trackBy: trackByFn">
 | 
				
			||||||
                <div
 | 
					                <div
 | 
				
			||||||
                    class="flex group hover:bg-gray-50 dark:hover:bg-black dark:hover:bg-opacity-5"
 | 
					                    class="flex group hover:bg-gray-50 dark:hover:bg-black dark:hover:bg-opacity-5"
 | 
				
			||||||
                    [ngClass]="{'unread': !message.read}">
 | 
					                    [ngClass]="{'unread': !message.read}">
 | 
				
			||||||
 | 
				
			|||||||
@ -155,6 +155,17 @@ export class MessagesComponent implements OnInit, OnChanges, OnDestroy
 | 
				
			|||||||
        this._messagesService.delete(message.id).subscribe();
 | 
					        this._messagesService.delete(message.id).subscribe();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Track by function for ngFor loops
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param index
 | 
				
			||||||
 | 
					     * @param item
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    trackByFn(index: number, item: any): any
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return item.id || index;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // -----------------------------------------------------------------------------------------------------
 | 
					    // -----------------------------------------------------------------------------------------------------
 | 
				
			||||||
    // @ Private methods
 | 
					    // @ Private methods
 | 
				
			||||||
    // -----------------------------------------------------------------------------------------------------
 | 
					    // -----------------------------------------------------------------------------------------------------
 | 
				
			||||||
 | 
				
			|||||||
@ -46,7 +46,7 @@
 | 
				
			|||||||
        <!-- Content -->
 | 
					        <!-- Content -->
 | 
				
			||||||
        <div class="relative flex flex-col flex-auto sm:max-h-120 divide-y overflow-y-auto bg-card">
 | 
					        <div class="relative flex flex-col flex-auto sm:max-h-120 divide-y overflow-y-auto bg-card">
 | 
				
			||||||
            <!-- Notifications -->
 | 
					            <!-- Notifications -->
 | 
				
			||||||
            <ng-container *ngFor="let notification of notifications">
 | 
					            <ng-container *ngFor="let notification of notifications; trackBy: trackByFn">
 | 
				
			||||||
                <div
 | 
					                <div
 | 
				
			||||||
                    class="flex group hover:bg-gray-50 dark:hover:bg-black dark:hover:bg-opacity-5"
 | 
					                    class="flex group hover:bg-gray-50 dark:hover:bg-black dark:hover:bg-opacity-5"
 | 
				
			||||||
                    [ngClass]="{'unread': !notification.read}">
 | 
					                    [ngClass]="{'unread': !notification.read}">
 | 
				
			||||||
 | 
				
			|||||||
@ -155,6 +155,17 @@ export class NotificationsComponent implements OnChanges, OnInit, OnDestroy
 | 
				
			|||||||
        this._notificationsService.delete(notification.id).subscribe();
 | 
					        this._notificationsService.delete(notification.id).subscribe();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Track by function for ngFor loops
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param index
 | 
				
			||||||
 | 
					     * @param item
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    trackByFn(index: number, item: any): any
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return item.id || index;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // -----------------------------------------------------------------------------------------------------
 | 
					    // -----------------------------------------------------------------------------------------------------
 | 
				
			||||||
    // @ Private methods
 | 
					    // @ Private methods
 | 
				
			||||||
    // -----------------------------------------------------------------------------------------------------
 | 
					    // -----------------------------------------------------------------------------------------------------
 | 
				
			||||||
 | 
				
			|||||||
@ -31,7 +31,7 @@
 | 
				
			|||||||
                *ngIf="results && !results.length">
 | 
					                *ngIf="results && !results.length">
 | 
				
			||||||
                No results found!
 | 
					                No results found!
 | 
				
			||||||
            </mat-option>
 | 
					            </mat-option>
 | 
				
			||||||
            <ng-container *ngFor="let result of results">
 | 
					            <ng-container *ngFor="let result of results; trackBy: trackByFn">
 | 
				
			||||||
                <mat-option
 | 
					                <mat-option
 | 
				
			||||||
                    class="group relative h-14 px-6 py-0 sm:px-8 text-md"
 | 
					                    class="group relative h-14 px-6 py-0 sm:px-8 text-md"
 | 
				
			||||||
                    [routerLink]="result.link">
 | 
					                    [routerLink]="result.link">
 | 
				
			||||||
@ -73,7 +73,7 @@
 | 
				
			|||||||
                *ngIf="results && !results.length">
 | 
					                *ngIf="results && !results.length">
 | 
				
			||||||
                No results found!
 | 
					                No results found!
 | 
				
			||||||
            </mat-option>
 | 
					            </mat-option>
 | 
				
			||||||
            <ng-container *ngFor="let result of results">
 | 
					            <ng-container *ngFor="let result of results; trackBy: trackByFn">
 | 
				
			||||||
                <mat-option
 | 
					                <mat-option
 | 
				
			||||||
                    class="group relative h-14 px-5 py-0 text-md"
 | 
					                    class="group relative h-14 px-5 py-0 text-md"
 | 
				
			||||||
                    [routerLink]="result.link">
 | 
					                    [routerLink]="result.link">
 | 
				
			||||||
 | 
				
			|||||||
@ -200,4 +200,15 @@ export class SearchComponent implements OnChanges, OnInit, OnDestroy
 | 
				
			|||||||
        // Close the search
 | 
					        // Close the search
 | 
				
			||||||
        this.opened = false;
 | 
					        this.opened = false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Track by function for ngFor loops
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param index
 | 
				
			||||||
 | 
					     * @param item
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    trackByFn(index: number, item: any): any
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return item.id || index;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -94,7 +94,7 @@
 | 
				
			|||||||
                <!-- Shortcuts -->
 | 
					                <!-- Shortcuts -->
 | 
				
			||||||
                <div class="grid grid-cols-2 grid-flow-row">
 | 
					                <div class="grid grid-cols-2 grid-flow-row">
 | 
				
			||||||
                    <!-- Shortcut -->
 | 
					                    <!-- Shortcut -->
 | 
				
			||||||
                    <ng-container *ngFor="let shortcut of shortcuts">
 | 
					                    <ng-container *ngFor="let shortcut of shortcuts; trackBy: trackByFn">
 | 
				
			||||||
                        <div class="relative group flex flex-col overflow-hidden bg-card border-r border-b even:border-r-0 hover:bg-gray-50 dark:hover:bg-black dark:hover:bg-opacity-5">
 | 
					                        <div class="relative group flex flex-col overflow-hidden bg-card border-r border-b even:border-r-0 hover:bg-gray-50 dark:hover:bg-black dark:hover:bg-opacity-5">
 | 
				
			||||||
                            <ng-container *ngIf="mode === 'modify'">
 | 
					                            <ng-container *ngIf="mode === 'modify'">
 | 
				
			||||||
                                <div
 | 
					                                <div
 | 
				
			||||||
 | 
				
			|||||||
@ -209,6 +209,17 @@ export class ShortcutsComponent implements OnChanges, OnInit, OnDestroy
 | 
				
			|||||||
        this.mode = 'modify';
 | 
					        this.mode = 'modify';
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Track by function for ngFor loops
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param index
 | 
				
			||||||
 | 
					     * @param item
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    trackByFn(index: number, item: any): any
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return item.id || index;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // -----------------------------------------------------------------------------------------------------
 | 
					    // -----------------------------------------------------------------------------------------------------
 | 
				
			||||||
    // @ Private methods
 | 
					    // @ Private methods
 | 
				
			||||||
    // -----------------------------------------------------------------------------------------------------
 | 
					    // -----------------------------------------------------------------------------------------------------
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user