Skip to content

Commit

Permalink
feat(module): copy name to clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladyslav Yakovenko committed Jan 25, 2024
1 parent d7f7eaa commit 231caf4
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 30 deletions.
51 changes: 40 additions & 11 deletions src/app/components/module-parts/module-detail-data.service.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
import { Injectable } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { MatSnackBar } from '@angular/material/snack-bar';
import { BehaviorSubject, delay, merge, of, ReplaySubject, Subject } from 'rxjs';
import { filter, map, switchMap, takeUntil, tap, withLatestFrom } from 'rxjs/operators';
import { Injectable } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { MatSnackBar } from '@angular/material/snack-bar';
import {
BehaviorSubject,
delay,
merge,
of,
ReplaySubject,
Subject
} from 'rxjs';
import {
filter,
map,
switchMap,
takeUntil,
tap,
withLatestFrom
} from 'rxjs/operators';
import { RackModuleAdderComponent } from 'src/app/components/rack-parts/rack-module-adder/rack-module-adder.component';
import { UserManagementService } from '../../features/backbone/login/user-management.service';
import { SupabaseService } from '../../features/backend/supabase.service';
import { DbModule } from '../../models/module';
import { PatchMinimal } from '../../models/patch';
import { RackMinimal } from '../../models/rack';
import { UserManagementService } from '../../features/backbone/login/user-management.service';
import { SupabaseService } from '../../features/backend/supabase.service';
import { DbModule } from '../../models/module';
import { PatchMinimal } from '../../models/patch';
import { RackMinimal } from '../../models/rack';

@Injectable()
export class ModuleDetailDataService {
Expand All @@ -21,6 +35,7 @@ export class ModuleDetailDataService {
addModuleToCollection$ = new Subject<number>();
requestAddModuleToRack$ = new Subject<DbModule>();
removeModuleFromCollection$ = new Subject<number>();
copyModuleNameAndManufacturer$ = new Subject<void>();
//
racksWithThisModule$ = new BehaviorSubject<RackMinimal[] | undefined>(undefined);
patchesWithThisModule$ = new BehaviorSubject<PatchMinimal[] | undefined>(undefined);
Expand All @@ -35,6 +50,19 @@ export class ModuleDetailDataService {
public backend: SupabaseService
) {

this.copyModuleNameAndManufacturer$
.pipe(
withLatestFrom(this.singleModuleData$),
takeUntil(this.destroyEvent$)
)
.subscribe(([a, b]) => {
if (b) {
let text: string = `${ b.name } by ${ b.manufacturer.name }`;
navigator.clipboard.writeText(text);
snackBar.open('Copied: ' + text, undefined, {duration: 3000});
}
});

merge(this.userService.loggedUser$, this.updateSingleModuleData$)
.pipe(
switchMap(x => this.userService.loggedUser$),
Expand Down Expand Up @@ -146,9 +174,10 @@ export class ModuleDetailDataService {

}


ngOnDestroy(): void {
this.destroyEvent$.next();
this.destroyEvent$.complete();

}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core';
import {
ChangeDetectionStrategy,
Component,
Input,
OnInit
} from '@angular/core';
import { fadeInOnEnterAnimation } from 'angular-animations';
import { SupabaseService } from 'src/app/features/backend/supabase.service';
import { DbModule } from 'src/app/models/module';
import { defaultModuleMinimalViewConfig, ModuleMinimalViewConfig } from '../module-minimal/module-minimal.component';
import { Clipboard } from '@angular/cdk/clipboard';
import { SupabaseService } from 'src/app/features/backend/supabase.service';
import { DbModule } from 'src/app/models/module';
import {
defaultModuleMinimalViewConfig,
ModuleMinimalViewConfig
} from '../module-minimal/module-minimal.component';

@Component({
selector: 'app-module-details',
Expand All @@ -26,7 +33,6 @@ export class ModuleDetailsComponent implements OnInit {

constructor(
public backend: SupabaseService,
private clipboard: Clipboard
// userManagerService: UserManagementService
) {
// console.error(patchService);
Expand All @@ -35,9 +41,4 @@ export class ModuleDetailsComponent implements OnInit {
ngOnInit(): void {
}

copyModuleNameAndManufacturer(): void {
const textToCopy = `${this.data.name} by ${this.data.manufacturer.name}`;
this.clipboard.copy(textToCopy);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,19 @@
>
<mat-icon>menu_book</mat-icon>
</a>


<a mat-icon-button
matTooltip="Copy module name to clipboard"
(click)="dataService.copyModuleNameAndManufacturer$.next()"
>
<mat-icon>content_copy</mat-icon>
</a>

<a mat-icon-button
matTooltip="Seach on Google"
target="_blank"
rel="noopener noreferrer"
[href]="'https://www.google.com/search?q='+bag.singleModuleData.name+' '+bag.singleModuleData.manufacturer.name"
[href]="'https://www.google.com/search?q='+bag.singleModuleData.name+' by '+bag.singleModuleData.manufacturer.name"
>
<mat-icon>open_in_new</mat-icon>
</a>
Expand Down
10 changes: 5 additions & 5 deletions src/build.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Build information, automatically generated by `ng-info`
const build = {
version: '4.1.0',
timestamp: 'Thu Jan 25 2024 09:28:00 GMT+0100 (Central European Standard Time)',
version: '4.1.1',
timestamp: 'Thu Jan 25 2024 09:45:35 GMT+0100 (Central European Standard Time)',
message: null,
git: {
user: 'Vladyslav Yakovenko',
branch: 'develop',
hash: 'd655a1',
fullHash: 'd655a1dc3cb6198d2afc8f8db65f14600a68bbc2'
branch: 'sweep/allowe_to_copy_name_and_company_of_modul',
hash: 'd7f7ea',
fullHash: 'd7f7eaaaf77baa8933a0be7a089af33e3ed3b9bf'
}
};

Expand Down

0 comments on commit 231caf4

Please sign in to comment.