1- import { Component } from '@angular/core' ;
1+ import { Component , OnInit } from '@angular/core' ;
22import { DynamicDialogRef } from 'primeng/dynamicdialog' ;
33import { DynamicDialogConfig } from 'primeng/dynamicdialog' ;
44import { StableDiffusionService } from 'src/app/stable-diffusion.service' ;
@@ -17,6 +17,8 @@ export class AddLorasComponent {
1717 loraFile : File | null = null ;
1818 searchField : string = '' ; // New field for search field
1919
20+ showNSFWLoras : boolean = false ;
21+
2022 searchResults : any [ ] = [ ] ; // Will hold the API search results
2123 selectedLoRA : any = null ; // Holds the selected LoRA from the table
2224 showImageDialog : boolean = false ; // Track the state of the image dialog
@@ -32,6 +34,21 @@ export class AddLorasComponent {
3234 , private sharedService : SharedService
3335 ) { }
3436
37+ ngOnInit ( ) : void {
38+ const fromParent = this . config ?. data ?. showNSFWLoras ;
39+ if ( typeof fromParent === 'boolean' ) {
40+ this . showNSFWLoras = fromParent ;
41+ return ;
42+ }
43+
44+ const stored = localStorage . getItem ( 'showNSFWLoras' ) ;
45+ if ( stored != null ) this . showNSFWLoras = stored === 'true' ;
46+ }
47+
48+ onShowNsfwChanged ( ) : void {
49+ localStorage . setItem ( 'showNSFWLoras' , this . showNSFWLoras . toString ( ) ) ;
50+ }
51+
3552 selectOption ( option : string ) {
3653 this . selectedSearchOption = option ;
3754 this . searchResults = [ ] ;
@@ -47,6 +64,8 @@ export class AddLorasComponent {
4764 }
4865
4966 search ( ) {
67+ if ( this . isLoading || ! this . searchField ) return ;
68+
5069 if ( this . selectedSearchOption === 'username' ) {
5170 this . searchByUsername ( ) ;
5271 } else if ( this . selectedSearchOption === 'lora_name' ) {
@@ -58,7 +77,7 @@ export class AddLorasComponent {
5877
5978 searchByUsername ( ) {
6079 this . isLoading = true ; // Start loading
61- this . stableDiffusionService . searchByUser ( this . searchField ) . subscribe ( {
80+ this . stableDiffusionService . searchByUser ( this . searchField , this . showNSFWLoras ) . subscribe ( {
6281 next : ( response : any ) => {
6382 console . log ( 'civitAi user search done' ) ;
6483 this . searchResults = response ;
@@ -80,7 +99,7 @@ export class AddLorasComponent {
8099
81100 searchByLoRAName ( ) {
82101 this . isLoading = true ; // Start loading
83- this . stableDiffusionService . searchByQuery ( this . searchField ) . subscribe ( {
102+ this . stableDiffusionService . searchByQuery ( this . searchField , this . showNSFWLoras ) . subscribe ( {
84103 next : ( response : any ) => {
85104 console . log ( 'civitAi query search done' ) ;
86105 this . searchResults = response ;
@@ -103,7 +122,7 @@ export class AddLorasComponent {
103122 // New method to search by Model ID
104123 searchByModelId ( ) {
105124 this . isLoading = true ; // Start loading
106- this . stableDiffusionService . searchByID ( this . searchField ) . subscribe ( {
125+ this . stableDiffusionService . searchByID ( this . searchField , this . showNSFWLoras ) . subscribe ( {
107126 next : ( response : any ) => {
108127 this . searchResults = response ;
109128
@@ -159,7 +178,7 @@ export class AddLorasComponent {
159178 }
160179 } ) ;
161180 }
162- this . ref . close ( ) ;
181+ this . ref . close ( { showNSFWLoras : this . showNSFWLoras } ) ;
163182 }
164183
165184 selectLora ( lora : any ) {
@@ -174,7 +193,7 @@ export class AddLorasComponent {
174193
175194
176195 close ( ) {
177- this . ref . close ( ) ;
196+ this . ref . close ( { showNSFWLoras : this . showNSFWLoras } ) ;
178197 }
179198
180199 showError ( error : any ) {
0 commit comments