Spaces:
Sleeping
Sleeping
Add localStorage persistence and fix bugs
Browse files- App state now saves to localStorage after every change
- Full session restore on page reload (step, text, tags, results, claims)
- Added "Start Over" button in header to clear all progress
- Fixed copyClaim() to accept event parameter properly
- Removed broken rejectState variable (approve/reject bug fix)
Co-authored-by: Cursor <cursoragent@cursor.com>
487 unmodified lines488489490491492493494123 unmodified lines6186196206216226236246256266276286296306314 unmodified lines6366376386396406412 unmodified lines644645646647648649650651652357 unmodified lines10101011101210131014101510161017101810191020102110224 unmodified lines10271028102910301031103251 unmodified lines1084108510861087108810891 unmodified line1091109210931094109510961097109810991100110111021103110411051106487 unmodified lines<span class="num">3</span> Draft Claim</button></nav><div style="width:200px"></div></header><main>123 unmodified lines<div class="claim-toolbar-left">Patent Claims Draft</div><div style="display:flex;gap:8px;align-items:center"><span class="status-badge done" id="claimStatus">β Draft Ready</span><button class="btn btn-ghost" onclick="copyClaim()">Copy</button></div></div><div class="claim-content" id="claimContent" contenteditable="true"></div></div><div class="btn-row" style="margin-top:20px"><button class="btn btn-primary" onclick="copyClaim()">Copy to Clipboard</button><button class="btn btn-secondary" onclick="regenerateClaim()">Regenerate</button><button class="btn btn-ghost" onclick="goToStep(2)">β Back to Prior Art</button></div>4 unmodified lines<script>// βββ STATE βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββconst state = {ideaText: '',keywords: [],2 unmodified linesselectedKindCodes: [],priorArt: [],approvedArt: [],claimDraft: ''};// βββ NAVIGATION ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββfunction goToStep(n, opts = {}) {[1,2,3].forEach(i => {357 unmodified linesstate.approvedArt = state.approvedArt.filter(x => x !== i);} else {state.approvedArt.push(i);state.approvedArt = state.approvedArt.filter(x => !rejectState.includes(x));}updateApprovedCount();}// simple reject stateconst rejectState = [];function rejectPA(i) {const item = document.getElementById(`pa-${i}`);const approveBtn = document.getElementById(`approve-${i}`);4 unmodified linesapproveBtn.classList.remove('active');state.approvedArt = state.approvedArt.filter(x => x !== i);updateApprovedCount();}function updateApprovedCount() {51 unmodified linesdocument.getElementById('claimContent').innerText = state.claimDraft;document.getElementById('claimLoading').style.display = 'none';document.getElementById('claimOutputWrap').style.display = 'block';}async function regenerateClaim() {1 unmodified lineawait generateClaim();}function copyClaim() {const text = document.getElementById('claimContent').innerText;navigator.clipboard.writeText(text).then(() => {const btn = event.target;const orig = btn.textContent;btn.textContent = 'β Copied!';btn.classList.add('copied');setTimeout(() => { btn.textContent = orig; btn.classList.remove('copied'); }, 2000);});}</script></body></html>487 unmodified lines488489490491492493494123 unmodified lines6186196206216226236246256266276286296306314 unmodified lines6366376386396406416422 unmodified lines645646647648649650651652653654655656657658659660661662663664665666667668669670357 unmodified lines102810291030103110321033103410351036103710384 unmodified lines104310441045104610471048104951 unmodified lines11011102110311041105110611071 unmodified line1109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163487 unmodified lines<span class="num">3</span> Draft Claim</button></nav><button class="btn btn-ghost" onclick="if(confirm('Clear all progress and start over?')) clearState()" style="font-size:11px;opacity:0.6">βΊ Start Over</button></header><main>123 unmodified lines<div class="claim-toolbar-left">Patent Claims Draft</div><div style="display:flex;gap:8px;align-items:center"><span class="status-badge done" id="claimStatus">β Draft Ready</span><button class="btn btn-ghost" onclick="copyClaim(event)">Copy</button></div></div><div class="claim-content" id="claimContent" contenteditable="true"></div></div><div class="btn-row" style="margin-top:20px"><button class="btn btn-primary" onclick="copyClaim(event)">Copy to Clipboard</button><button class="btn btn-secondary" onclick="regenerateClaim()">Regenerate</button><button class="btn btn-ghost" onclick="goToStep(2)">β Back to Prior Art</button></div>4 unmodified lines<script>// βββ STATE βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββconst STORAGE_KEY = 'eddison_state';const state = {ideaText: '',keywords: [],2 unmodified linesselectedKindCodes: [],priorArt: [],approvedArt: [],claimDraft: '',currentStep: 1};function saveState() {try { localStorage.setItem(STORAGE_KEY, JSON.stringify(state)); } catch(e) {}}function loadState() {try {const saved = localStorage.getItem(STORAGE_KEY);if (saved) Object.assign(state, JSON.parse(saved));} catch(e) {}}function clearState() {localStorage.removeItem(STORAGE_KEY);location.reload();}// βββ NAVIGATION ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββfunction goToStep(n, opts = {}) {[1,2,3].forEach(i => {357 unmodified linesstate.approvedArt = state.approvedArt.filter(x => x !== i);} else {state.approvedArt.push(i);}updateApprovedCount();saveState();}function rejectPA(i) {const item = document.getElementById(`pa-${i}`);const approveBtn = document.getElementById(`approve-${i}`);4 unmodified linesapproveBtn.classList.remove('active');state.approvedArt = state.approvedArt.filter(x => x !== i);updateApprovedCount();saveState();}function updateApprovedCount() {51 unmodified linesdocument.getElementById('claimContent').innerText = state.claimDraft;document.getElementById('claimLoading').style.display = 'none';document.getElementById('claimOutputWrap').style.display = 'block';saveState();}async function regenerateClaim() {1 unmodified lineawait generateClaim();}function copyClaim(e) {const text = document.getElementById('claimContent').innerText;navigator.clipboard.writeText(text).then(() => {const btn = e ? e.target : document.activeElement;const orig = btn.textContent;btn.textContent = 'β Copied!';btn.classList.add('copied');setTimeout(() => { btn.textContent = orig; btn.classList.remove('copied'); }, 2000);});}// βββ RESTORE SESSION ON LOAD βββββββββββββββββββββββββββββββββββββββββββββββββfunction restoreSession() {loadState();if (!state.ideaText && state.keywords.length === 0) return;document.getElementById('ideaText').value = state.ideaText;if (state.keywords.length > 0) {renderKeywords();renderKindCodes();document.getElementById('extractedSection').style.display = 'block';document.getElementById('analyzeBtn').innerHTML = 'β¦ Re-analyze';}if (state.priorArt.length > 0) {renderPriorArt();state.approvedArt.forEach(i => {const item = document.getElementById(`pa-${i}`);const btn = document.getElementById(`approve-${i}`);if (item) { item.classList.add('approved'); }if (btn) { btn.classList.add('active'); }});document.getElementById('priorArtResults').style.display = 'block';document.getElementById('searchBtn').innerHTML = 'β Re-Search';}if (state.claimDraft) {document.getElementById('claimContent').innerText = state.claimDraft;document.getElementById('claimLoading').style.display = 'none';document.getElementById('claimOutputWrap').style.display = 'block';}if (state.currentStep > 1) {goToStep(state.currentStep, { skipGenerate: true });}}restoreSession();</script></body></html>
eddison-app.html+66-9