mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-06 20:15:17 +02:00
refactor: streamline BrowserWindow component functionality
- Removed the interval management for tab selection, simplifying the state handling. - Updated tab click handler to directly set the selected index without restarting the interval. - Changed video preload attribute from "none" to "auto" for improved loading performance.
This commit is contained in:
parent
323886b481
commit
eb5799336c
1 changed files with 2 additions and 26 deletions
|
|
@ -180,32 +180,8 @@ function GetStartedButton() {
|
||||||
const BrowserWindow = () => {
|
const BrowserWindow = () => {
|
||||||
const [selectedIndex, setSelectedIndex] = useState(0);
|
const [selectedIndex, setSelectedIndex] = useState(0);
|
||||||
const selectedItem = TAB_ITEMS[selectedIndex];
|
const selectedItem = TAB_ITEMS[selectedIndex];
|
||||||
const intervalRef = useRef<NodeJS.Timeout | null>(null);
|
|
||||||
const { expanded, open, close } = useExpandedMedia();
|
const { expanded, open, close } = useExpandedMedia();
|
||||||
|
|
||||||
const startInterval = useCallback(() => {
|
|
||||||
if (intervalRef.current) {
|
|
||||||
clearInterval(intervalRef.current);
|
|
||||||
}
|
|
||||||
intervalRef.current = setInterval(() => {
|
|
||||||
setSelectedIndex((prev) => (prev + 1) % TAB_ITEMS.length);
|
|
||||||
}, 10000);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
startInterval();
|
|
||||||
return () => {
|
|
||||||
if (intervalRef.current) {
|
|
||||||
clearInterval(intervalRef.current);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}, [startInterval]);
|
|
||||||
|
|
||||||
const handleTabClick = (index: number) => {
|
|
||||||
setSelectedIndex(index);
|
|
||||||
startInterval();
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<motion.div className="relative my-4 flex w-full flex-col items-start justify-start overflow-hidden rounded-2xl shadow-2xl md:my-12">
|
<motion.div className="relative my-4 flex w-full flex-col items-start justify-start overflow-hidden rounded-2xl shadow-2xl md:my-12">
|
||||||
|
|
@ -220,7 +196,7 @@ const BrowserWindow = () => {
|
||||||
<React.Fragment key={item.title}>
|
<React.Fragment key={item.title}>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => handleTabClick(index)}
|
onClick={() => setSelectedIndex(index)}
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex shrink-0 items-center gap-1.5 rounded-md px-2 py-1 text-xs transition duration-150 hover:bg-white sm:text-sm dark:hover:bg-neutral-950",
|
"flex shrink-0 items-center gap-1.5 rounded-md px-2 py-1 text-xs transition duration-150 hover:bg-white sm:text-sm dark:hover:bg-neutral-950",
|
||||||
selectedIndex === index && !item.featured &&
|
selectedIndex === index && !item.featured &&
|
||||||
|
|
@ -334,7 +310,7 @@ const TabVideo = memo(function TabVideo({ src }: { src: string }) {
|
||||||
ref={videoRef}
|
ref={videoRef}
|
||||||
key={src}
|
key={src}
|
||||||
src={src}
|
src={src}
|
||||||
preload="none"
|
preload="auto"
|
||||||
loop
|
loop
|
||||||
muted
|
muted
|
||||||
playsInline
|
playsInline
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue