mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-06 03:34:40 +00:00
fix: settings ui not following animations setting
This commit is contained in:
@@ -1,32 +1,32 @@
|
|||||||
import React, { memo, useEffect, useRef, useState } from 'react';
|
import React, { memo, useEffect, useRef, useState } from 'react';
|
||||||
import { motion } from 'framer-motion';
|
import { motion } from 'framer-motion';
|
||||||
import type { TabbedContainerProps } from '../types/TabbedContainerProps';
|
import type { TabbedContainerProps } from '../types/TabbedContainerProps';
|
||||||
|
import { useSettingsContext } from '../SettingsContext';
|
||||||
|
|
||||||
const TabbedContainer: React.FC<TabbedContainerProps> = ({ tabs }) => {
|
const TabbedContainer: React.FC<TabbedContainerProps> = ({ tabs }) => {
|
||||||
|
const { settingsState } = useSettingsContext();
|
||||||
const [activeTab, setActiveTab] = useState(0);
|
const [activeTab, setActiveTab] = useState(0);
|
||||||
const [hoveredTab, setHoveredTab] = useState<number | null>(null);
|
const [hoveredTab, setHoveredTab] = useState<number | null>(null);
|
||||||
const [tabWidth, setTabWidth] = useState(0);
|
const [tabWidth, setTabWidth] = useState(0);
|
||||||
const [position, setPosition] = useState(0);
|
const [position, setPosition] = useState(0);
|
||||||
const positionRef = useRef(position);
|
const positionRef = useRef(position);
|
||||||
|
|
||||||
|
// Function to handle message
|
||||||
|
const handleMessage = (event: MessageEvent) => {
|
||||||
|
if (event.data === "popupClosed") {
|
||||||
|
setActiveTab(0);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Function to handle message
|
useEffect(() => {
|
||||||
const handleMessage = (event: MessageEvent) => {
|
// Add event listener for 'message' event
|
||||||
if (event.data === "popupClosed") {
|
window.addEventListener("message", handleMessage);
|
||||||
setActiveTab(0);
|
|
||||||
}
|
// Cleanup
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener("message", handleMessage);
|
||||||
};
|
};
|
||||||
|
}, []);
|
||||||
useEffect(() => {
|
|
||||||
// Add event listener for 'message' event
|
|
||||||
window.addEventListener("message", handleMessage);
|
|
||||||
|
|
||||||
// Cleanup
|
|
||||||
return () => {
|
|
||||||
window.removeEventListener("message", handleMessage);
|
|
||||||
};
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const newPosition = -activeTab * 100;
|
const newPosition = -activeTab * 100;
|
||||||
@@ -36,7 +36,7 @@ const TabbedContainer: React.FC<TabbedContainerProps> = ({ tabs }) => {
|
|||||||
|
|
||||||
const containerRef = useRef(null);
|
const containerRef = useRef(null);
|
||||||
|
|
||||||
const springTransition = { type: 'spring', stiffness: 250, damping: 25 };
|
const springTransition = settingsState.animations ? { type: 'spring', stiffness: 250, damping: 25 } : { duration: 0 };
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (containerRef.current) {
|
if (containerRef.current) {
|
||||||
@@ -85,8 +85,8 @@ const TabbedContainer: React.FC<TabbedContainerProps> = ({ tabs }) => {
|
|||||||
className='flex'
|
className='flex'
|
||||||
>
|
>
|
||||||
{tabs.map((tab, index) => (
|
{tabs.map((tab, index) => (
|
||||||
<div key={index} className={`absolute h-[100vh] focus-visible:outline-none overflow-y-scroll w-full pb-40 transition-opacity duration-300 ${activeTab === index ? 'opacity-100' : 'opacity-0'}`}
|
<div key={index} className={`absolute h-[100vh] focus-visible:outline-none overflow-y-scroll w-full pb-40 ${ settingsState.animations ? 'transition-opacity duration-300' : ''} ${activeTab === index ? 'opacity-100' : 'opacity-0'}`}
|
||||||
style={{left: `${index * 100}%`}}>
|
style={{left: `${index * 100}%`}}>
|
||||||
{tab.content}
|
{tab.content}
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ const SettingsPage = ({ standalone }: SettingsPage) => {
|
|||||||
<button onClick={() => browser.runtime.sendMessage({ type: 'currentTab', info: 'OpenChangelog' })} className="absolute w-8 h-8 text-lg rounded-xl font-IconFamily top-1 right-1 bg-zinc-100 dark:bg-zinc-700"></button>
|
<button onClick={() => browser.runtime.sendMessage({ type: 'currentTab', info: 'OpenChangelog' })} className="absolute w-8 h-8 text-lg rounded-xl font-IconFamily top-1 right-1 bg-zinc-100 dark:bg-zinc-700"></button>
|
||||||
</div>
|
</div>
|
||||||
<Picker />
|
<Picker />
|
||||||
<TabbedContainer tabs={tabs} />
|
<TabbedContainer tabs={tabs} animations={false} />
|
||||||
</div>
|
</div>
|
||||||
</SettingsContextProvider>
|
</SettingsContextProvider>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ export interface Tab {
|
|||||||
}
|
}
|
||||||
export interface TabbedContainerProps {
|
export interface TabbedContainerProps {
|
||||||
tabs: Tab[];
|
tabs: Tab[];
|
||||||
|
animations?: boolean;
|
||||||
}
|
}
|
||||||
declare const TabbedContainer: React.FC<TabbedContainerProps>;
|
declare const TabbedContainer: React.FC<TabbedContainerProps>;
|
||||||
export default TabbedContainer;
|
export default TabbedContainer;
|
||||||
|
|||||||
Reference in New Issue
Block a user