@@ -3,6 +3,7 @@ import { formatBytes, newExpirationValue, unixNow } from "./utils.js";
3
3
4
4
export class MirrorBlobs extends LitElement {
5
5
static properties = {
6
+ showAll : { state : true , type : Boolean } ,
6
7
remoteBlobs : { state : true } ,
7
8
localBlobs : { state : true } ,
8
9
@@ -49,8 +50,7 @@ export class MirrorBlobs extends LitElement {
49
50
50
51
localAuth = null ;
51
52
async fetchLocalBlobs ( ) {
52
- this . pubkey = await window . nostr ?. getPublicKey ( ) ;
53
- if ( ! this . pubkey ) return ;
53
+ const pubkey = await window . nostr . getPublicKey ( ) ;
54
54
55
55
this . status = "Signing..." ;
56
56
@@ -67,7 +67,7 @@ export class MirrorBlobs extends LitElement {
67
67
68
68
this . status = "Fetching..." ;
69
69
70
- this . localBlobs = await fetch ( "/list/" + this . pubkey , {
70
+ this . localBlobs = await fetch ( "/list/" + pubkey , {
71
71
headers : { authorization : "Nostr " + btoa ( JSON . stringify ( this . localAuth ) ) } ,
72
72
} ) . then ( ( res ) => res . json ( ) ) ;
73
73
@@ -110,18 +110,27 @@ export class MirrorBlobs extends LitElement {
110
110
</ form > ` ;
111
111
}
112
112
113
+ getShownBlobs ( ) {
114
+ return this . showAll
115
+ ? this . remoteBlobs
116
+ : this . remoteBlobs . filter ( ( blob ) => ! this . localBlobs . some ( ( b ) => b . sha256 === blob . sha256 ) ) ;
117
+ }
118
+
113
119
selectAll ( ) {
114
- const missingBlobs = this . remoteBlobs . filter ( ( blob ) => ! this . localBlobs . some ( ( b ) => b . sha256 === blob . sha256 ) ) ;
120
+ const blobs = this . getShownBlobs ( ) ;
115
121
116
- if ( this . selected . length === missingBlobs . length ) {
122
+ if ( this . selected . length === blobs . length ) {
117
123
this . selected = [ ] ;
118
- } else this . selected = missingBlobs . map ( ( b ) => b . sha256 ) ;
124
+ } else this . selected = blobs . map ( ( b ) => b . sha256 ) ;
119
125
}
120
126
toggleSelection ( sha256 ) {
121
127
if ( this . selected . includes ( sha256 ) ) {
122
128
this . selected = this . selected . filter ( ( s ) => s !== sha256 ) ;
123
129
} else this . selected = [ ...this . selected , sha256 ] ;
124
130
}
131
+ toggleShowAll ( ) {
132
+ this . showAll = ! this . showAll ;
133
+ }
125
134
126
135
async mirrorBlobs ( ) {
127
136
const blobs = this . remoteBlobs . filter ( ( blob ) => this . selected . includes ( blob . sha256 ) ) ;
@@ -170,10 +179,15 @@ export class MirrorBlobs extends LitElement {
170
179
} else if ( this . status ) {
171
180
return html `< p class ="my-5 text-center text-lg "> ${ this . status } </ p > ` ;
172
181
} else if ( this . remoteBlobs && this . localBlobs ) {
173
- const missingBlobs = this . remoteBlobs . filter ( ( blob ) => ! this . localBlobs . some ( ( b ) => b . sha256 === blob . sha256 ) ) ;
174
-
175
- if ( missingBlobs . length === 0 ) {
176
- return html `< p class ="text-green-500 text-lg text-center p-10 "> All blobs synced ✅</ p > ` ;
182
+ const blobs = this . getShownBlobs ( ) ;
183
+ const check = html ` < label
184
+ > < input type ="checkbox " type ="checkbox " .checked ="${ this . showAll } " @change ="${ this . toggleShowAll } " /> Show
185
+ all</ label
186
+ > ` ;
187
+
188
+ if ( blobs . length === 0 ) {
189
+ return html `${ check }
190
+ < p class ="text-green-500 text-lg text-center p-10 "> All blobs synced ✅</ p > ` ;
177
191
}
178
192
179
193
return html `
@@ -184,14 +198,15 @@ export class MirrorBlobs extends LitElement {
184
198
>
185
199
Select All
186
200
</ button >
201
+ ${ check }
187
202
< button
188
203
class ="text-md bg-blue-500 text-gray-100 py-1 px-3 rounded-md tracking-wide font-semibold hover:bg-blue-600 cursor-pointer transition ease-in duration-300 flex-shrink-0 ml-auto "
189
204
@click ="${ this . mirrorBlobs } "
190
205
>
191
206
Mirror Blobs
192
207
</ button >
193
208
</ div >
194
- ${ this . renderBlobs ( missingBlobs ) }
209
+ ${ this . renderBlobs ( blobs ) }
195
210
` ;
196
211
}
197
212
0 commit comments