Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(popup): move WM toggle Switch to global header #654

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion src/popup/components/layout/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import React from 'react';
import { Link, useLocation } from 'react-router-dom';
import { ArrowBack, Settings } from '../Icons';
import { HeaderEmpty } from './HeaderEmpty';
import { Switch } from '@/popup/components/ui/Switch';
import { ROUTES_PATH } from '@/popup/Popup';
import { useBrowser, usePopupState } from '@/popup/lib/context';
import { useBrowser, useMessage, usePopupState } from '@/popup/lib/context';
import { isOkState } from '@/shared/helpers';

const NavigationButton = () => {
const location = useLocation();
Expand Down Expand Up @@ -33,12 +35,40 @@ const NavigationButton = () => {
}, [location, connected]);
};

const ToggleWMButton: React.FC<{ toggleWM: () => void }> = ({ toggleWM }) => {
const {
state: { enabled, connected, state },
} = usePopupState();

if (!connected) return null;
if (!isOkState(state)) return null;

return (
<Switch
checked={enabled}
onChange={toggleWM}
size="small"
title="Enable/Disable Web Monetization"
aria-label="Continuous payment stream"
Comment on lines +51 to +52
Copy link
Member Author

@sidvishnoi sidvishnoi Oct 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should we call these?

/>
);
};

export const Header = () => {
const message = useMessage();
const browser = useBrowser();
const { dispatch } = usePopupState();

const toggleWM = () => {
message.send('TOGGLE_WM');
dispatch({ type: 'TOGGLE_WM', data: {} });
};

const Logo = browser.runtime.getURL('assets/images/logo.svg');

return (
<HeaderEmpty logo={Logo}>
<ToggleWMButton toggleWM={toggleWM} />
<NavigationButton />
</HeaderEmpty>
);
Expand Down
4 changes: 2 additions & 2 deletions src/popup/components/ui/Switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ export interface SwitchProps
}

export const Switch = forwardRef<HTMLInputElement, SwitchProps>(function Switch(
{ size, label, className, onChange = () => {}, ...props },
{ size, label, className, title, onChange = () => {}, ...props },
ref,
) {
return (
<label className="flex items-center gap-x-4">
<label className="flex items-center gap-x-4" title={title}>
<input
role="switch"
ref={ref}
Expand Down
11 changes: 0 additions & 11 deletions src/popup/pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
import { PayWebsiteForm } from '../components/PayWebsiteForm';
import { NotMonetized } from '@/popup/components/NotMonetized';
import { debounceAsync } from '@/shared/helpers';
import { Switch } from '../components/ui/Switch';

export const Component = () => {
const t = useTranslation();
Expand Down Expand Up @@ -58,11 +57,6 @@ export const Component = () => {
void updateRateOfPay.current(rateOfPay);
};

const onChangeWM = () => {
message.send('TOGGLE_WM');
dispatch({ type: 'TOGGLE_WM', data: {} });
};

if (tab.status !== 'monetized') {
switch (tab.status) {
case 'all_sessions_invalid':
Expand Down Expand Up @@ -111,11 +105,6 @@ export const Component = () => {
</p>
</div>
)}
<Switch
checked={enabled}
onChange={onChangeWM}
label="Continuous payment stream"
/>

<hr />

Expand Down