Spaces:
Running
Running
refactor: remove unused useMemo and related code in LoadingScreen component
Browse files- src/App.tsx +0 -1
- src/components/LoadingScreen.tsx +0 -48
src/App.tsx
CHANGED
|
@@ -3,7 +3,6 @@ import React, {
|
|
| 3 |
useEffect,
|
| 4 |
useCallback,
|
| 5 |
useRef,
|
| 6 |
-
useMemo,
|
| 7 |
} from "react";
|
| 8 |
import { openDB, type IDBPDatabase } from "idb";
|
| 9 |
import {
|
|
|
|
| 3 |
useEffect,
|
| 4 |
useCallback,
|
| 5 |
useRef,
|
|
|
|
| 6 |
} from "react";
|
| 7 |
import { openDB, type IDBPDatabase } from "idb";
|
| 8 |
import {
|
src/components/LoadingScreen.tsx
CHANGED
|
@@ -43,7 +43,6 @@ export const LoadingScreen = ({
|
|
| 43 |
const canvasRef = useRef<HTMLCanvasElement>(null);
|
| 44 |
const dropdownBtnRef = useRef<HTMLButtonElement>(null);
|
| 45 |
const dropdownRef = useRef<HTMLDivElement>(null);
|
| 46 |
-
const wrapperRef = useRef<HTMLDivElement>(null); // NEW: anchor for centering
|
| 47 |
|
| 48 |
// For keyboard navigation
|
| 49 |
const [activeIndex, setActiveIndex] = useState(
|
|
@@ -189,53 +188,6 @@ export const LoadingScreen = ({
|
|
| 189 |
handleModelSelect,
|
| 190 |
]);
|
| 191 |
|
| 192 |
-
// Recompute portal position on open + resize
|
| 193 |
-
const [, forceRerender] = useState(0);
|
| 194 |
-
useEffect(() => {
|
| 195 |
-
const onResize = () => forceRerender((x) => x + 1);
|
| 196 |
-
window.addEventListener("resize", onResize);
|
| 197 |
-
return () => window.removeEventListener("resize", onResize);
|
| 198 |
-
}, []);
|
| 199 |
-
|
| 200 |
-
// Compute portal style based on the whole button group (center + clamp + optional drop-up)
|
| 201 |
-
const portalStyle = useMemo(() => {
|
| 202 |
-
if (typeof window === "undefined") return {};
|
| 203 |
-
const anchor = wrapperRef.current || dropdownBtnRef.current;
|
| 204 |
-
if (!anchor) return {};
|
| 205 |
-
|
| 206 |
-
const rect = anchor.getBoundingClientRect();
|
| 207 |
-
|
| 208 |
-
const margin = 8;
|
| 209 |
-
const minWidth = 320;
|
| 210 |
-
const dropdownWidth = Math.max(rect.width, minWidth);
|
| 211 |
-
|
| 212 |
-
// Center
|
| 213 |
-
let left = Math.round(rect.left + rect.width / 2 - dropdownWidth / 2);
|
| 214 |
-
// Clamp to viewport
|
| 215 |
-
left = Math.min(
|
| 216 |
-
Math.max(margin, left),
|
| 217 |
-
window.innerWidth - dropdownWidth - margin
|
| 218 |
-
);
|
| 219 |
-
|
| 220 |
-
// Flip up if not enough space below
|
| 221 |
-
const spaceBelow = window.innerHeight - rect.bottom;
|
| 222 |
-
const spaceAbove = rect.top;
|
| 223 |
-
const estimatedItemH = 56; // rough item height
|
| 224 |
-
const estimatedPad = 16;
|
| 225 |
-
const estimatedHeight =
|
| 226 |
-
estimatedItemH * Math.min(MODEL_OPTIONS.length, 6) + estimatedPad;
|
| 227 |
-
const dropUp = spaceBelow < estimatedHeight && spaceAbove > spaceBelow;
|
| 228 |
-
|
| 229 |
-
const top = dropUp ? rect.top - estimatedHeight - 8 : rect.bottom + 8;
|
| 230 |
-
|
| 231 |
-
return {
|
| 232 |
-
position: "fixed" as const,
|
| 233 |
-
left: `${left}px`,
|
| 234 |
-
top: `${top}px`,
|
| 235 |
-
width: `${dropdownWidth}px`,
|
| 236 |
-
zIndex: 100,
|
| 237 |
-
};
|
| 238 |
-
}, []);
|
| 239 |
|
| 240 |
return (
|
| 241 |
<div className="relative flex flex-col items-center justify-center min-h-screen bg-gradient-to-br from-gray-900 via-slate-900 to-gray-900 text-white p-6 overflow-hidden">
|
|
|
|
| 43 |
const canvasRef = useRef<HTMLCanvasElement>(null);
|
| 44 |
const dropdownBtnRef = useRef<HTMLButtonElement>(null);
|
| 45 |
const dropdownRef = useRef<HTMLDivElement>(null);
|
|
|
|
| 46 |
|
| 47 |
// For keyboard navigation
|
| 48 |
const [activeIndex, setActiveIndex] = useState(
|
|
|
|
| 188 |
handleModelSelect,
|
| 189 |
]);
|
| 190 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
|
| 192 |
return (
|
| 193 |
<div className="relative flex flex-col items-center justify-center min-h-screen bg-gradient-to-br from-gray-900 via-slate-900 to-gray-900 text-white p-6 overflow-hidden">
|