one-click-accessibility/modules/scanner/assets/js/app.js
VasylD 43f1b2cb5a
[APP-1741][APP-1742][APP-1743] add components, calc contrast ratio, a… (#346)
* [APP-1741][APP-1742][APP-1743] add components, calc contrast ratio, add logic for lightness

* Update modules/scanner/assets/js/components/color-contrast-form/color-set.js

Co-authored-by: gitstream-cm[bot] <111687743+gitstream-cm[bot]@users.noreply.github.com>

* update

* update

* Remove shadow dom, add color picker

* Remove shadow dom, add color picker

* Remove shadow dom, add color picker

* Update modules/scanner/assets/js/layouts/color-contrast-layout.js

Co-authored-by: gitstream-cm[bot] <111687743+gitstream-cm[bot]@users.noreply.github.com>

* Update modules/scanner/assets/js/components/color-contrast-form/color-set.js

Co-authored-by: gitstream-cm[bot] <111687743+gitstream-cm[bot]@users.noreply.github.com>

* Update modules/scanner/assets/js/components/color-contrast-form/color-set.js

Co-authored-by: gitstream-cm[bot] <111687743+gitstream-cm[bot]@users.noreply.github.com>

* Update modules/scanner/assets/js/layouts/color-contrast-layout.js

Co-authored-by: gitstream-cm[bot] <111687743+gitstream-cm[bot]@users.noreply.github.com>

* Update modules/scanner/assets/js/utils/calc-color-ratio.js

Co-authored-by: gitstream-cm[bot] <111687743+gitstream-cm[bot]@users.noreply.github.com>

* Remove shadow dom, add color picker

* Remove shadow dom, add color picker

* Revert shadow dom, include styles for color picker

* Revert shadow dom, include styles for color picker

---------

Co-authored-by: gitstream-cm[bot] <111687743+gitstream-cm[bot]@users.noreply.github.com>
2025-07-25 16:03:12 +02:00

105 lines
3.1 KiB
JavaScript

import ErrorBoundary from '@elementor/ui/ErrorBoundary';
import { Notifications } from '@ea11y/components';
import { useNotificationSettings } from '@ea11y-apps/global/hooks/use-notifications';
import { mixpanelEvents, mixpanelService } from '@ea11y-apps/global/services';
import { ErrorMessage } from '@ea11y-apps/scanner/components/error-message';
import { Header } from '@ea11y-apps/scanner/components/header';
import { Loader } from '@ea11y-apps/scanner/components/list-loader';
import { NotConnectedMessage } from '@ea11y-apps/scanner/components/not-connected-message';
import { QuotaMessage } from '@ea11y-apps/scanner/components/quota-message';
import { ResolvedMessage } from '@ea11y-apps/scanner/components/resolved-message';
import { BLOCKS, PAGE_QUOTA_LIMIT } from '@ea11y-apps/scanner/constants';
import { useScannerWizardContext } from '@ea11y-apps/scanner/context/scanner-wizard-context';
import {
AltTextLayout,
MainLayout,
ManageMainLayout,
ManualLayout,
RemediationLayout,
} from '@ea11y-apps/scanner/layouts';
import { ColorContrastLayout } from '@ea11y-apps/scanner/layouts/color-contrast-layout';
import { StyledPaper } from '@ea11y-apps/scanner/styles/app.styles';
import { removeExistingFocus } from '@ea11y-apps/scanner/utils/focus-on-element';
import { useEffect } from '@wordpress/element';
const App = () => {
const { notificationMessage, notificationType } = useNotificationSettings();
const {
setOpenedBlock,
violation,
resolved,
openedBlock,
isManage,
isError,
loading,
} = useScannerWizardContext();
const showResolvedMessage = Boolean(
(resolved > 0 && violation === resolved) || violation === 0,
);
useEffect(() => {
if (window.ea11yScannerData?.planData?.user?.id && violation !== null) {
void mixpanelService.init();
}
}, [window.ea11yScannerData?.planData?.user?.id, violation]);
useEffect(() => {
if (showResolvedMessage) {
removeExistingFocus();
setOpenedBlock(BLOCKS.main);
}
}, [showResolvedMessage]);
useEffect(() => {
if (!PAGE_QUOTA_LIMIT) {
mixpanelService.sendEvent(mixpanelEvents.upgradeSuggestionViewed, {
current_plan: window.ea11yScannerData?.planData?.plan?.name,
action_trigger: 'scan_triggered',
feature_locked: 'multi-page scan',
});
}
}, [PAGE_QUOTA_LIMIT]);
const getBlock = () => {
if (!window.ea11yScannerData?.isConnected) {
return <NotConnectedMessage />;
}
if (!PAGE_QUOTA_LIMIT) {
return <QuotaMessage />;
}
if (isError) {
return <ErrorMessage />;
}
if (loading) {
return <Loader />;
}
switch (openedBlock) {
case BLOCKS.main:
return <MainLayout />;
case BLOCKS.management:
return <ManageMainLayout />;
case BLOCKS.altText:
return <AltTextLayout />;
case BLOCKS.colorContrast:
return <ColorContrastLayout />;
default:
return isManage ? <RemediationLayout /> : <ManualLayout />;
}
};
return (
<StyledPaper>
<ErrorBoundary fallback={<ErrorMessage />}>
<Header />
{showResolvedMessage ? <ResolvedMessage /> : getBlock()}
<Notifications message={notificationMessage} type={notificationType} />
</ErrorBoundary>
</StyledPaper>
);
};
export default App;