@@ -47,6 +47,7 @@ public partial class CheckpointBrowserViewModel : ObservableObject
47
47
[ ObservableProperty ] private bool canGoToPreviousPage ;
48
48
[ ObservableProperty ] private bool isIndeterminate ;
49
49
[ ObservableProperty ] private bool noResultsFound ;
50
+ [ ObservableProperty ] private string noResultsText ;
50
51
51
52
public IEnumerable < CivitPeriod > AllCivitPeriods => Enum . GetValues ( typeof ( CivitPeriod ) ) . Cast < CivitPeriod > ( ) ;
52
53
public IEnumerable < CivitSortMode > AllSortModes => Enum . GetValues ( typeof ( CivitSortMode ) ) . Cast < CivitSortMode > ( ) ;
@@ -142,7 +143,6 @@ private async Task CivitModelQuery(CivitModelsRequest request)
142
143
{
143
144
Logger . Debug ( "Cache entry already exists, not updating model cards" ) ;
144
145
}
145
- NoResultsFound = ! models . Any ( ) ;
146
146
}
147
147
catch ( ApiException e )
148
148
{
@@ -153,6 +153,7 @@ private async Task CivitModelQuery(CivitModelsRequest request)
153
153
finally
154
154
{
155
155
ShowMainLoadingSpinner = false ;
156
+ UpdateResultsText ( ) ;
156
157
}
157
158
}
158
159
@@ -164,15 +165,13 @@ private void UpdateModelCards(IEnumerable<CivitModel>? models, CivitMetadata? me
164
165
if ( models is null )
165
166
{
166
167
ModelCards ? . Clear ( ) ;
167
- NoResultsFound = true ;
168
168
}
169
169
else
170
170
{
171
171
var updateCards = models
172
172
. Select ( model => new CheckpointBrowserCardViewModel ( model ,
173
173
downloadService , snackbarService , settingsManager ) ) ;
174
174
ModelCards = new ObservableCollection < CheckpointBrowserCardViewModel > ( updateCards ) ;
175
- NoResultsFound = false ;
176
175
}
177
176
TotalPages = metadata ? . TotalPages ?? 1 ;
178
177
CanGoToPreviousPage = CurrentPageNumber > 1 ;
@@ -206,8 +205,20 @@ private async Task SearchModels()
206
205
Sort = SortMode ,
207
206
Period = SelectedPeriod ,
208
207
Page = CurrentPageNumber ,
209
- Tag = SearchQuery
210
208
} ;
209
+
210
+ if ( SearchQuery . StartsWith ( "#" ) )
211
+ {
212
+ modelRequest . Tag = SearchQuery [ 1 ..] ;
213
+ }
214
+ else if ( SearchQuery . StartsWith ( "@" ) )
215
+ {
216
+ modelRequest . Username = SearchQuery [ 1 ..] ;
217
+ }
218
+ else
219
+ {
220
+ modelRequest . Query = SearchQuery ;
221
+ }
211
222
212
223
if ( SelectedModelType != CivitModelType . All )
213
224
{
@@ -220,7 +231,7 @@ private async Task SearchModels()
220
231
. FindByIdAsync ( ObjectHash . GetMd5Guid ( modelRequest ) ) ;
221
232
222
233
// If cached, update model cards
223
- if ( cachedQuery ? . Items is not null && cachedQuery . Items . Any ( ) )
234
+ if ( cachedQuery is not null )
224
235
{
225
236
var elapsed = timer . Elapsed ;
226
237
Logger . Debug ( "Using cached query for {Text} [{RequestHash}] (in {Elapsed:F1} s)" ,
@@ -230,21 +241,22 @@ private async Task SearchModels()
230
241
// Start remote query (background mode)
231
242
// Skip when last query was less than 2 min ago
232
243
var timeSinceCache = DateTimeOffset . UtcNow - cachedQuery . InsertedAt ;
233
- if ( timeSinceCache ? . TotalMinutes < 2 )
244
+ if ( timeSinceCache ? . TotalMinutes >= 2 )
234
245
{
235
- Logger . Debug ( "Cached query was less than 2 minutes ago ({Seconds:F0} s), skipping remote query" ,
246
+ CivitModelQuery ( modelRequest ) . SafeFireAndForget ( ) ;
247
+ Logger . Debug (
248
+ "Cached query was more than 2 minutes ago ({Seconds:F0} s), updating cache with remote query" ,
236
249
timeSinceCache . Value . TotalSeconds ) ;
237
- return ;
238
250
}
239
-
240
- CivitModelQuery ( modelRequest ) . SafeFireAndForget ( ) ;
241
251
}
242
252
else
243
253
{
244
254
// Not cached, wait for remote query
245
255
ShowMainLoadingSpinner = true ;
246
256
await CivitModelQuery ( modelRequest ) ;
247
257
}
258
+
259
+ UpdateResultsText ( ) ;
248
260
}
249
261
250
262
[ RelayCommand ]
@@ -282,6 +294,7 @@ partial void OnShowNsfwChanged(bool value)
282
294
{
283
295
settingsManager . SetModelBrowserNsfwEnabled ( value ) ;
284
296
ModelCardsView ? . Refresh ( ) ;
297
+ UpdateResultsText ( ) ;
285
298
}
286
299
287
300
partial void OnSelectedPeriodChanged ( CivitPeriod oldValue , CivitPeriod newValue )
@@ -312,4 +325,12 @@ private async Task TrySearchAgain(bool shouldUpdatePageNumber = true)
312
325
// execute command instead of calling method directly so that the IsRunning property gets updated
313
326
await SearchModelsCommand . ExecuteAsync ( null ) ;
314
327
}
328
+
329
+ private void UpdateResultsText ( )
330
+ {
331
+ NoResultsFound = ModelCardsView ? . IsEmpty ?? true ;
332
+ NoResultsText = ModelCards ? . Count == 0
333
+ ? "No results found"
334
+ : $ "{ ModelCards ? . Count } results hidden by filters";
335
+ }
315
336
}
0 commit comments