feat(ui): shot status, projects and client portal keep their place
Deploy / deploy (push) Successful in 3m31s

Coming back from a shot left the shot status page at the top with its
sections reset. The scroll restore saved window.scrollY, but dashboard pages
scroll the layout's <main>, so it always saved 0; the Projects page had the
same bug. Only episode expansion was remembered — scene and group sections
came back fully collapsed.

A shared useScrollMemory hook saves the real scroll container's position as
the user scrolls (so any way of leaving keeps it) and restores it once the
content that sets the page height is back. It ignores the scroll the shared
<main> fires when the next page replaces this one, which otherwise
overwrote the saved position.

Shot status now remembers episode, scene and group expansion per project.
The client portal already kept its filters and collapsed episodes but
restored scroll before they were applied; it now uses the hook too.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
twotalesanimation
2026-09-18 05:52:13 +02:00
parent 532ebd82d7
commit 33bc6a935c
4 changed files with 170 additions and 59 deletions
+9 -11
View File
@@ -1,6 +1,7 @@
'use client';
import { useState, useEffect } from 'react';
import { useState, useRef, useEffect } from 'react';
import { useScrollMemory } from '@/hooks/use-scroll-memory';
import Link from 'next/link';
import Image from 'next/image';
import {
@@ -127,7 +128,6 @@ const TASK_TYPE_LABELS: Record<string, string> = {
GENERAL: 'Task',
};
const SCROLL_KEY = 'client-portal-scroll';
const QUEUE_KEY = 'client-portal-queue';
const STATE_KEY = 'client-portal-state';
const PREFS_KEY_PREFIX = 'client-portal-prefs-';
@@ -154,6 +154,11 @@ export default function ClientPortalPage({
const [sortMode, setSortMode] = useState<'episode' | 'recent'>('episode');
const [searchQuery, setSearchQuery] = useState<string>('');
const [episodeFilter, setEpisodeFilter] = useState<string | null>(null);
// Filters and collapsed episodes set the page height, so the scroll
// position is restored only once they are back.
const [viewRestored, setViewRestored] = useState(false);
const pageRef = useRef<HTMLDivElement>(null);
useScrollMemory(token ? `clientPortal:${token}` : null, pageRef, viewRestored);
const toggleEpisode = (ep: string) => {
setCollapsedEpisodes((prev) => {
@@ -209,13 +214,7 @@ export default function ClientPortalPage({
}
} catch { /* ignore */ }
}
const saved = sessionStorage.getItem(SCROLL_KEY);
if (saved) {
sessionStorage.removeItem(SCROLL_KEY);
requestAnimationFrame(() => {
window.scrollTo(0, parseInt(saved, 10));
});
}
setViewRestored(true);
}
}, [loading, token]);
@@ -429,7 +428,6 @@ export default function ClientPortalPage({
};
const handleReviewClick = () => {
sessionStorage.setItem(SCROLL_KEY, String(window.scrollY));
sessionStorage.setItem(QUEUE_KEY, JSON.stringify(getReviewQueue()));
sessionStorage.setItem(
STATE_KEY,
@@ -444,7 +442,7 @@ export default function ClientPortalPage({
};
return (
<div className="min-h-screen bg-zinc-950 text-white">
<div ref={pageRef} className="min-h-screen bg-zinc-950 text-white">
<header className="border-b border-zinc-800 bg-zinc-900">
<div className="max-w-5xl mx-auto px-6 py-4 flex items-center justify-between">
{/* Logo */}