2023-11-08 15:33:18 +03:00
|
|
|
import React, {useEffect, useState} from 'react';
|
2023-11-08 18:10:43 +03:00
|
|
|
import {SettingGroup as Base, SettingGroupProps} from '@tryghost/admin-x-design-system';
|
2023-11-14 16:50:08 +03:00
|
|
|
import {useRouting} from '@tryghost/admin-x-framework/routing';
|
2023-11-08 15:33:18 +03:00
|
|
|
import {useScrollSection} from '../hooks/useScrollSection';
|
2023-11-14 16:50:08 +03:00
|
|
|
import {useSearch} from './providers/SettingsAppProvider';
|
2023-11-08 15:33:18 +03:00
|
|
|
|
|
|
|
const TopLevelGroup: React.FC<Omit<SettingGroupProps, 'isVisible' | 'highlight'> & {keywords: string[]}> = ({keywords, navid, ...props}) => {
|
2024-02-08 10:32:40 +03:00
|
|
|
const {checkVisible, noResult} = useSearch();
|
2023-11-08 15:33:18 +03:00
|
|
|
const {route} = useRouting();
|
|
|
|
const [highlight, setHighlight] = useState(false);
|
|
|
|
const {ref} = useScrollSection(navid);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
setHighlight(route === navid);
|
|
|
|
}, [route, navid]);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (highlight) {
|
|
|
|
setTimeout(() => {
|
|
|
|
setHighlight(false);
|
2024-02-08 10:32:40 +03:00
|
|
|
}, 2000);
|
2023-11-08 15:33:18 +03:00
|
|
|
}
|
|
|
|
}, [highlight]);
|
|
|
|
|
2024-02-08 10:32:40 +03:00
|
|
|
return <Base ref={ref} highlight={highlight} isVisible={checkVisible(keywords) || noResult} navid={navid} {...props} />;
|
2023-11-08 15:33:18 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
export default TopLevelGroup;
|