ReportPreview.svelte (7078B)
1 <script lang="ts"> 2 import { onMount } from 'svelte'; 3 import { deploymentSupportPolicy } from '../config/deployment-support.ts'; 4 import type { SupportPolicy } from '../config/support.ts'; 5 import { internalHref } from '../navigation-url.ts'; 6 import SupportLink from './SupportLink.svelte'; 7 import { 8 reportContextSnapshot, 9 subscribeReportContext, 10 closeReportContext, 11 reviewReportPreview, 12 reportPreviewSnapshot, 13 closeReportPreview, 14 copyReportPreview, 15 type ReportContext, 16 type ReportPreview 17 } from '../support/report.ts'; 18 let { 19 context, 20 policy = deploymentSupportPolicy 21 }: { context: ReportContext; policy?: SupportPolicy } = $props(); 22 let revision = $state(0), 23 notes = $state(''), 24 listingVersion = $state(false), 25 coordinate = $state(false), 26 peer = $state(false), 27 messages = $state<string[]>([]), 28 privateDisclosure = $state(false), 29 preview = $state.raw<ReportPreview | undefined>(), 30 busy = $state(false), 31 notice = $state<string | undefined>(); 32 const actual = $derived.by(() => { 33 void revision; 34 return reportContextSnapshot(context); 35 }); 36 const text = $derived.by(() => { 37 void revision; 38 return preview && reportPreviewSnapshot(preview); 39 }); 40 function discard() { 41 if (preview) closeReportPreview(preview); 42 preview = undefined; 43 notice = undefined; 44 } 45 function choose(id: string, checked: boolean) { 46 discard(); 47 messages = checked 48 ? [...messages, id] 49 : messages.filter((value) => value !== id); 50 } 51 function review() { 52 discard(); 53 preview = reviewReportPreview( 54 context, 55 JSON.stringify({ 56 listingVersion, 57 coordinate, 58 peer, 59 messages, 60 notes, 61 privateDisclosure 62 }), 63 'reviewed_report_preview' 64 ); 65 if (!preview) 66 notice = 67 actual?.kind === 'conversation' && !privateDisclosure 68 ? 'Review the private sharing disclosure before preparing selected private information.' 69 : 'A report preview was not prepared. Select only the information you intend to share and keep the description short.'; 70 } 71 async function copy() { 72 const selected = preview; 73 if (!selected || busy) return; 74 busy = true; 75 const outcome = await copyReportPreview(selected, 'reviewed_copy_report'); 76 busy = false; 77 if (preview !== selected) return; 78 notice = 79 outcome === 'copied' 80 ? 'Report copied. Nothing was sent to support.' 81 : outcome === 'stopped' 82 ? 'This report is no longer current. A copy already requested may still remain outside HarvestCircle.' 83 : 'Copy was unavailable. Select the reviewed text below if you still want to share it.'; 84 } 85 onMount(() => { 86 const original = context; 87 const off = subscribeReportContext(original, () => { 88 revision++; 89 if (!reportContextSnapshot(original)) { 90 discard(); 91 notes = ''; 92 messages = []; 93 peer = false; 94 listingVersion = false; 95 coordinate = false; 96 privateDisclosure = false; 97 } 98 }); 99 return () => { 100 off(); 101 discard(); 102 closeReportContext(original); 103 }; 104 }); 105 </script> 106 107 <section class="stack" aria-label="Prepare a selected report"> 108 <h3>Choose what to share</h3> 109 <p> 110 Only selected information appears in the preview. Preparing or copying a 111 report does not send it. 112 </p> 113 {#if actual} 114 {#if actual.kind === 'listing'} 115 <fieldset class="stack"> 116 <legend>Public listing information</legend> 117 <label 118 ><input 119 type="checkbox" 120 checked={listingVersion} 121 onchange={(event) => { 122 discard(); 123 listingVersion = event.currentTarget.checked; 124 }} 125 /> Share listing version</label 126 > 127 <label 128 ><input 129 type="checkbox" 130 checked={coordinate} 131 onchange={(event) => { 132 discard(); 133 coordinate = event.currentTarget.checked; 134 }} 135 /> Share coordinate</label 136 > 137 </fieldset> 138 {:else if actual.kind === 'conversation'} 139 <p class="notice"> 140 Support cannot automatically read encrypted messages. Selected private 141 text and identifiers become readable outside HarvestCircle if you share 142 them. 143 </p> 144 <fieldset class="stack"> 145 <legend>Private information to include</legend> 146 <label 147 ><input 148 type="checkbox" 149 checked={peer} 150 onchange={(event) => { 151 discard(); 152 peer = event.currentTarget.checked; 153 }} 154 /> Share authenticated peer key</label 155 > 156 {#each actual.messages as message, index (message.id)} 157 <div class="stack"> 158 <label 159 ><input 160 type="checkbox" 161 aria-label={'Share message text and ID ' + (index + 1)} 162 checked={messages.includes(message.id)} 163 onchange={(event) => 164 choose(message.id, event.currentTarget.checked)} 165 /> 166 Share message text and ID {index + 1}</label 167 > 168 <p class="description">{message.content}</p> 169 </div> 170 {/each} 171 </fieldset> 172 {/if} 173 <label for="report-problem-description">Problem description</label> 174 <textarea 175 id="report-problem-description" 176 rows="4" 177 maxlength="4096" 178 value={notes} 179 oninput={(event) => { 180 discard(); 181 notes = event.currentTarget.value; 182 }}></textarea> 183 <p> 184 Type only information you intend to share. No other messages, drafts, 185 receipts or account data are attached. 186 </p> 187 {#if actual.kind === 'conversation'} 188 <label 189 ><input 190 type="checkbox" 191 checked={privateDisclosure} 192 onchange={(event) => { 193 discard(); 194 privateDisclosure = event.currentTarget.checked; 195 }} 196 /> I understand selected private information will leave HarvestCircle if I 197 share it.</label 198 > 199 {/if} 200 <button type="button" disabled={busy} onclick={review}>Review report</button 201 > 202 {#if text !== undefined} 203 <pre 204 class="description" 205 role="region" 206 aria-label="Selected report preview">{text}</pre> 207 <button type="button" disabled={busy} onclick={() => void copy()} 208 >Copy reviewed report</button 209 > 210 {/if} 211 {:else}<p class="notice"> 212 This report context is no longer available. Reopen it from the current 213 listing or conversation if appropriate. 214 </p>{/if} 215 {#if notice}<p role="status">{notice}</p>{/if} 216 <p> 217 Copied text can remain in your clipboard or other applications. 218 Disconnecting or clearing local data cannot erase those copies. A copy 219 already requested may complete after disconnecting. 220 </p> 221 <SupportLink {policy} /> 222 <a href={internalHref('/about#report')}>Help and report instructions</a> 223 </section>