@@ -202,66 +202,78 @@ class CssSnippetStoreModal extends Modal {
202
202
grid . empty ( ) ;
203
203
const lowerFilter = filter . toLowerCase ( ) ;
204
204
205
- this . snippets
206
- . filter ( snippet =>
207
- ! filter ||
208
- snippet . name . toLowerCase ( ) . includes ( lowerFilter ) ||
209
- snippet . author . toLowerCase ( ) . includes ( lowerFilter ) ||
210
- snippet . description . toLowerCase ( ) . includes ( lowerFilter )
211
- )
212
- . forEach ( snippet => {
213
- const card = grid . createDiv ( { cls : 'community-item' } ) ;
214
-
215
- card . createEl ( 'div' , { text : snippet . name , cls : 'community-item-name' } ) ;
216
- card . createEl ( 'div' , { text : `By ${ snippet . author } ` , cls : 'community-item-author' } ) ;
217
- card . createEl ( 'div' , { text : snippet . description , cls : 'community-desc' } ) ;
218
-
219
- const buttonWrapper = card . createEl ( 'div' , { cls : 'snippet-store-button-wrapper' } ) ;
220
- const button = buttonWrapper . createEl ( 'button' , { cls : 'mod-cta' } ) ;
221
-
222
- this . checkSnippetExists ( snippet . id ) . then ( ( exists ) => {
223
- if ( exists ) {
224
- button . textContent = 'Delete' ;
225
- button . className = 'mod-danger' ;
226
-
227
- button . addEventListener ( 'click' , async ( ) => {
228
- await this . uninstall ( snippet . id ) ;
229
- this . close ( ) ;
230
- this . open ( ) ;
231
- } ) ;
232
- } else {
233
- button . textContent = 'Install' ;
234
- button . className = 'mod-cta' ;
235
-
236
- button . addEventListener ( 'click' , async ( ) => {
237
- const url = `https://raw.githubusercontent.com/${ snippet . repo } /refs/heads/main/${ snippet . folder } /snippet.css` ;
238
- try {
239
- if ( await isOnline ( ) ) {
240
- const response = await fetchWithTimeout ( url ) ;
241
- if ( ! response . ok ) {
242
- throw new Error ( `Network response was not ok: ${ response . statusText } ` ) ;
243
- }
244
- /*
245
- if (!response.headers.get('content-type')?.includes('text/css')) {
246
- throw new Error("Expected CSS content");
247
- }*/
248
- const code = await response . text ( ) ;
249
- await this . install ( snippet . id , code ) ;
250
- this . close ( ) ;
251
- this . open ( ) ;
252
- } else {
253
- new Notice ( `No Internet connection...` ) ;
205
+ const filteredSnippets = this . snippets . filter ( snippet =>
206
+ ! filter ||
207
+ snippet . name . toLowerCase ( ) . includes ( lowerFilter ) ||
208
+ snippet . author . toLowerCase ( ) . includes ( lowerFilter ) ||
209
+ snippet . description . toLowerCase ( ) . includes ( lowerFilter )
210
+ ) ;
211
+
212
+ if ( filteredSnippets . length === 0 ) {
213
+ const noResultsMessage = grid . createEl ( 'div' , {
214
+ text : this . snippets . length === 0
215
+ ? "No Internet connection"
216
+ : "No snippets match your search." ,
217
+ cls : 'no-snippets-message'
218
+ } ) ;
219
+ noResultsMessage . style . marginTop = '1rem' ;
220
+ noResultsMessage . style . textAlign = 'center' ;
221
+ noResultsMessage . style . color = 'var(--text-muted)' ;
222
+ noResultsMessage . style . fontStyle = 'italic' ;
223
+ noResultsMessage . style . width = '100%' ;
224
+ return ;
225
+ }
226
+
227
+ filteredSnippets . forEach ( snippet => {
228
+ const card = grid . createDiv ( { cls : 'community-item' } ) ;
229
+
230
+ card . createEl ( 'div' , { text : snippet . name , cls : 'community-item-name' } ) ;
231
+ card . createEl ( 'div' , { text : `By ${ snippet . author } ` , cls : 'community-item-author' } ) ;
232
+ card . createEl ( 'div' , { text : snippet . description , cls : 'community-desc' } ) ;
233
+
234
+ const buttonWrapper = card . createEl ( 'div' , { cls : 'snippet-store-button-wrapper' } ) ;
235
+ const button = buttonWrapper . createEl ( 'button' , { cls : 'mod-cta' } ) ;
236
+
237
+ this . checkSnippetExists ( snippet . id ) . then ( ( exists ) => {
238
+ if ( exists ) {
239
+ button . textContent = 'Delete' ;
240
+ button . className = 'mod-danger' ;
241
+
242
+ button . addEventListener ( 'click' , async ( ) => {
243
+ await this . uninstall ( snippet . id ) ;
244
+ this . close ( ) ;
245
+ this . open ( ) ;
246
+ } ) ;
247
+ } else {
248
+ button . textContent = 'Install' ;
249
+ button . className = 'mod-cta' ;
250
+
251
+ button . addEventListener ( 'click' , async ( ) => {
252
+ const url = `https://raw.githubusercontent.com/${ snippet . repo } /refs/heads/main/${ snippet . folder } /snippet.css` ;
253
+ try {
254
+ if ( await isOnline ( ) ) {
255
+ const response = await fetchWithTimeout ( url ) ;
256
+ if ( ! response . ok ) {
257
+ throw new Error ( `Network response was not ok: ${ response . statusText } ` ) ;
254
258
}
255
- } catch ( error ) {
256
- console . error ( error ) ;
257
- new Notice ( `Error: ${ error . message } ` ) ;
259
+ const code = await response . text ( ) ;
260
+ await this . install ( snippet . id , code ) ;
261
+ this . close ( ) ;
262
+ this . open ( ) ;
263
+ } else {
264
+ new Notice ( `No Internet connection...` ) ;
258
265
}
259
- } ) ;
260
- }
261
- } ) ;
266
+ } catch ( error ) {
267
+ console . error ( error ) ;
268
+ new Notice ( `Error: ${ error . message } ` ) ;
269
+ }
270
+ } ) ;
271
+ }
262
272
} ) ;
273
+ } ) ;
263
274
} ;
264
275
276
+
265
277
// Initial rendering
266
278
renderSnippets ( ) ;
267
279
0 commit comments