fix(SearchPane): update initialTab handling and persist last active tab in localStorage
This commit is contained in:
parent
23e9cf418f
commit
9a902d6b4f
|
|
@ -55,7 +55,7 @@ export default function App() {
|
|||
const [currentPage, setCurrentPage] = useState<Page>('status');
|
||||
const { config, setConfig, saveStatus, pendingCount, flushNow, reload } = useSettings();
|
||||
const [showSearch, setShowSearch] = useState(false);
|
||||
const [searchInitialTab, setSearchInitialTab] = useState<0 | 1>(0);
|
||||
const [searchInitialTab, setSearchInitialTab] = useState<0 | 1 | undefined>(undefined);
|
||||
const [devicesOpenId, setDevicesOpenId] = useState<string | null>(null);
|
||||
const [isFullscreen, setIsFullscreen] = useState(false);
|
||||
const [fileManagerInitialPath, setFileManagerInitialPath] = useState<string | undefined>(undefined);
|
||||
|
|
@ -260,7 +260,7 @@ function AppPage({ title, onBack }: { title: string; onBack: () => void }) {
|
|||
{isFullscreen ? <Minimize2 className="w-5 h-5 text-white" /> : <Maximize2 className="w-5 h-5 text-white" />}
|
||||
</button>
|
||||
<button
|
||||
onClick={() => { setSearchInitialTab(0); setShowSearch(true); }}
|
||||
onClick={() => { setSearchInitialTab(undefined); setShowSearch(true); }}
|
||||
className="p-2 hover:bg-[#5e5e5e] rounded-lg"
|
||||
>
|
||||
<Search className="w-5 h-5 text-white" />
|
||||
|
|
|
|||
|
|
@ -14,15 +14,18 @@ interface SearchPaneProps {
|
|||
|
||||
const TABS = ['Local', 'Assembly64'] as const;
|
||||
|
||||
export default function SearchPane({ config, setConfig, initialTab = 0, onClose, onOpenFolder }: SearchPaneProps) {
|
||||
const panelRef = useRef<HTMLDivElement>(null);
|
||||
const [activeTab, setActiveTab] = useState<0 | 1>(initialTab);
|
||||
let _lastTab: 0 | 1 = (localStorage.getItem('search.tab') === '1' ? 1 : 0);
|
||||
|
||||
// Jump to initialTab without animation on first render
|
||||
export default function SearchPane({ config, setConfig, initialTab, onClose, onOpenFolder }: SearchPaneProps) {
|
||||
const panelRef = useRef<HTMLDivElement>(null);
|
||||
const [activeTab, setActiveTab] = useState<0 | 1>(initialTab ?? _lastTab);
|
||||
|
||||
// Jump to starting tab without animation on first render
|
||||
useEffect(() => {
|
||||
const el = panelRef.current;
|
||||
if (!el || initialTab === 0) return;
|
||||
el.scrollLeft = initialTab * el.clientWidth;
|
||||
const tab = initialTab ?? _lastTab;
|
||||
if (!el || tab === 0) return;
|
||||
el.scrollLeft = tab * el.clientWidth;
|
||||
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
const scrollToTab = (idx: 0 | 1) => {
|
||||
|
|
@ -36,6 +39,8 @@ export default function SearchPane({ config, setConfig, initialTab = 0, onClose,
|
|||
if (!el) return;
|
||||
const idx = Math.round(el.scrollLeft / el.clientWidth) as 0 | 1;
|
||||
setActiveTab(idx);
|
||||
_lastTab = idx;
|
||||
localStorage.setItem('search.tab', String(idx));
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user