LocalDataReview.svelte (8387B)
1 <script lang="ts"> 2 import { onMount, untrack } from 'svelte'; 3 import Button from './primitives/Button.svelte'; 4 import { 5 localDataReviewSnapshot, 6 reviewLocalData, 7 previewLocalDataRemoval, 8 confirmLocalDataRemoval, 9 cancelLocalDataRemoval, 10 subscribeLocalDataReview, 11 type LocalDataReview 12 } from '../persistence/local-data-review.ts'; 13 let { review }: { review: LocalDataReview } = $props(); 14 let snapshot = $state.raw(untrack(() => localDataReviewSnapshot(review))); 15 let selectedPublic = $state.raw<string[]>([]), 16 selectedReceived = $state.raw<string[]>([]), 17 selectedOutbox = $state.raw<string[]>([]); 18 let feedback = $state<string | undefined>(); 19 const family = (value: string) => 20 value === 'public_draft' 21 ? 'Listing draft' 22 : value === 'public_operation' 23 ? 'Publication recovery record' 24 : 'Inbox preference recovery record'; 25 function reset() { 26 selectedPublic = []; 27 selectedReceived = []; 28 selectedOutbox = []; 29 feedback = undefined; 30 } 31 onMount(() => { 32 snapshot = localDataReviewSnapshot(review); 33 return subscribeLocalDataReview(review, () => { 34 snapshot = localDataReviewSnapshot(review); 35 if (snapshot.state !== 'ready') reset(); 36 }); 37 }); 38 function toggle(category: 'public' | 'received' | 'outbox', id: string) { 39 feedback = undefined; 40 if (category === 'public') 41 selectedPublic = selectedPublic.includes(id) 42 ? selectedPublic.filter((value) => value !== id) 43 : [...selectedPublic, id]; 44 else if (category === 'received') 45 selectedReceived = selectedReceived.includes(id) 46 ? selectedReceived.filter((value) => value !== id) 47 : [...selectedReceived, id]; 48 else 49 selectedOutbox = selectedOutbox.includes(id) 50 ? selectedOutbox.filter((value) => value !== id) 51 : [...selectedOutbox, id]; 52 } 53 async function inspect() { 54 reset(); 55 await reviewLocalData(review, 'reviewed_local_inventory'); 56 } 57 async function preview(category: 'public' | 'received' | 'outbox') { 58 const result = await previewLocalDataRemoval( 59 review, 60 category, 61 JSON.stringify( 62 category === 'public' 63 ? selectedPublic 64 : category === 'received' 65 ? selectedReceived 66 : selectedOutbox 67 ) 68 ); 69 feedback = result 70 ? undefined 71 : 'Removal preview is unavailable. Review the current data and select only eligible records.'; 72 } 73 function keep() { 74 cancelLocalDataRemoval(review); 75 reset(); 76 } 77 async function confirm() { 78 reset(); 79 await confirmLocalDataRemoval(review, 'reviewed_local_removal'); 80 } 81 </script> 82 83 <section class="stack" aria-label="Review local data"> 84 <h2>Local controls</h2> 85 <Button 86 label="Review data in this browser" 87 onclick={inspect} 88 disabled={snapshot.state === 'loading' || 89 (snapshot.state === 'ready' && snapshot.busy)} 90 /> 91 {#if snapshot.state === 'guest'} 92 <p> 93 Connect to review your account-local data. Guest browsing does not expose 94 an account inventory. 95 </p> 96 {:else if snapshot.state === 'loading'} 97 <p role="status">Checking this account’s local data…</p> 98 {:else if snapshot.state === 'unavailable'} 99 <p role="status">{snapshot.notice}</p> 100 {:else if snapshot.state === 'ready'} 101 <p>Account in this browser:</p> 102 <p class="key" data-local-data-owner>{snapshot.owner}</p> 103 <p> 104 Pending or uncertain work is protected. Logical byte counts describe 105 stored record text, not disk usage. No private message text is opened by 106 this inventory. 107 </p> 108 {#if snapshot.preview} 109 <h3>Review removal</h3> 110 <p> 111 {snapshot.preview.selected} selected {snapshot.preview.category === 112 'public' 113 ? 'public records' 114 : snapshot.preview.category === 'outbox' 115 ? 'settled send records' 116 : 'encrypted received copies'}. 117 </p> 118 <p>{snapshot.preview.consequences}</p> 119 <div class="row"> 120 <Button 121 label="Keep data" 122 onclick={keep} 123 disabled={snapshot.busy} 124 /><Button 125 label="Confirm removal" 126 onclick={confirm} 127 disabled={snapshot.busy} 128 /> 129 </div> 130 {:else} 131 <h3>Listing drafts and publication records</h3> 132 {#if snapshot.publicRows.length} 133 <ul class="stack"> 134 {#each snapshot.publicRows as row (row.key)} 135 <li class="stack"> 136 <label class="row" 137 ><input 138 type="checkbox" 139 checked={selectedPublic.includes(row.key)} 140 onchange={() => toggle('public', row.key)} 141 disabled={row.state === 'protected' || snapshot.busy} 142 />{family(row.family)} · {row.logicalBytes} logical bytes · {row.state === 143 'protected' 144 ? 'Protected' 145 : 'Eligible for reviewed removal'}</label 146 > 147 <p class="key">{row.id}</p> 148 </li> 149 {/each} 150 </ul> 151 {:else}<p>No public records for this account in this browser.</p>{/if} 152 <Button 153 label="Review public removal" 154 onclick={() => preview('public')} 155 disabled={!selectedPublic.length || snapshot.busy} 156 /> 157 <h3>Encrypted received copies</h3> 158 {#if !snapshot.receivedRemoval}<p> 159 Enable messaging explicitly before reviewing received-copy removal. 160 Reviewing data does not probe or enable messaging. 161 </p>{/if} 162 {#if snapshot.received.length} 163 <ul class="stack"> 164 {#each snapshot.received as row (row.id)}<li class="stack"> 165 <label class="row" 166 ><input 167 type="checkbox" 168 checked={selectedReceived.includes(row.id)} 169 onchange={() => toggle('received', row.id)} 170 disabled={!snapshot.receivedRemoval || snapshot.busy} 171 />Encrypted received copy · {row.logicalBytes} logical bytes</label 172 > 173 <p class="key">{row.id}</p> 174 </li>{/each} 175 </ul> 176 {:else}<p> 177 No encrypted received copies for this account in this browser. 178 </p>{/if} 179 <Button 180 label="Review received removal" 181 onclick={() => preview('received')} 182 disabled={!snapshot.receivedRemoval || 183 !selectedReceived.length || 184 snapshot.busy} 185 /> 186 <h3>Private send recovery</h3> 187 <p> 188 {snapshot.outbox.count} retained records · {snapshot.outbox.bytes} logical 189 bytes. This browser retains at most 100 send records. Settled records also 190 occupy that capacity. Unsettled send records stay protected. 191 </p> 192 {#if !snapshot.receivedRemoval}<p> 193 Enable messaging explicitly before reviewing settled-send removal. 194 Reviewing data does not probe or enable messaging. 195 </p>{/if} 196 {#if snapshot.outboxRows.length} 197 <ul class="stack"> 198 {#each snapshot.outboxRows as row (row.id)} 199 <li class="stack"> 200 <label class="row" 201 ><input 202 type="checkbox" 203 checked={selectedOutbox.includes(row.id)} 204 onchange={() => toggle('outbox', row.id)} 205 disabled={!snapshot.receivedRemoval || 206 row.state === 'protected' || 207 snapshot.busy} 208 />Encrypted send recovery · {row.logicalBytes} logical bytes · {row.state === 209 'protected' 210 ? 'Protected' 211 : 'Eligible settled send'}</label 212 > 213 <p class="key">{row.id}</p> 214 </li> 215 {/each} 216 </ul> 217 {:else}<p> 218 No private send recovery records for this account in this browser. 219 </p>{/if} 220 <Button 221 label="Review settled send removal" 222 onclick={() => preview('outbox')} 223 disabled={!snapshot.receivedRemoval || 224 !selectedOutbox.length || 225 snapshot.busy} 226 /> 227 {/if} 228 {#if snapshot.busy}<p role="status"> 229 Checking the selected local action… 230 </p>{/if} 231 {#if snapshot.notice}<p role="status">{snapshot.notice}</p>{/if} 232 {/if} 233 {#if feedback}<p role="status">{feedback}</p>{/if} 234 </section>