Fix "Use This" button: transfer prompt across pages via sessionStorage

The optimization "Use This" button was on the /history page but tried
to set document.getElementById('prompt') which only exists on /. The
JS value was lost on navigation.

Fix: store prompt in sessionStorage, pick it up on main page load.
Also opens the composer overlay so the user sees the loaded prompt
immediately instead of landing on an empty output view.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
root 2026-03-29 07:24:59 -05:00
parent 7b9b7f6641
commit 856f584666

View File

@ -3538,6 +3538,18 @@ async function toggleDemo() {
loadModels();
renderSamplePrompts();
checkDemo();
// Pick up prompt from optimization "Use This" button
(function(){
var pending = sessionStorage.getItem('pending-prompt');
if (pending) {
sessionStorage.removeItem('pending-prompt');
var el = document.getElementById('prompt');
if (el) el.value = pending;
// Open composer if in output-focused mode
var ct = document.querySelector('.container');
if (ct) { ct.classList.remove('output-focused'); ct.classList.add('composer-active'); }
}
})();
// Background grid animation
!function(){const c=document.getElementById('bg-grid');if(!c)return;const x=c.getContext('2d');function resize(){c.width=window.innerWidth;c.height=window.innerHeight}resize();window.addEventListener('resize',resize);let t=0;function draw(){x.clearRect(0,0,c.width,c.height);const s=50,ox=(t*0.2)%s,oy=(t*0.1)%s;x.fillStyle='rgba(226,181,90,0.025)';for(let gx=-s+ox;gx<c.width+s;gx+=s){for(let gy=-s+oy;gy<c.height+s;gy+=s){x.beginPath();x.arc(gx,gy,0.7,0,Math.PI*2);x.fill()}}if(Math.random()>0.985){const ly=Math.random()*c.height;x.strokeStyle='rgba(226,181,90,0.012)';x.lineWidth=1;x.beginPath();x.moveTo(0,ly);x.lineTo(c.width,ly);x.stroke()}if(Math.random()>0.995){const lx=Math.random()*c.width;x.strokeStyle='rgba(226,181,90,0.008)';x.lineWidth=40;x.beginPath();x.moveTo(lx,0);x.lineTo(lx,c.height);x.stroke()}t++;requestAnimationFrame(draw)}draw()}();
@ -6950,8 +6962,7 @@ function _showOptimizeStream(runId, jobId) {
useBtn.style.cssText = 'color:var(--accent);border-color:var(--accent);font-size:9px;white-space:nowrap';
useBtn.textContent = 'Use This';
useBtn.onclick = function(){
var promptEl = document.getElementById('prompt');
if (promptEl) promptEl.value = r.prompt;
sessionStorage.setItem('pending-prompt', r.prompt);
window.location.href = '/';
};
row.appendChild(useBtn);