mirror of
https://github.com/movie-web/extension.git
synced 2025-09-13 13:13:24 +00:00
Make popout ask for permission
This commit is contained in:
19
src/components/PermissionMissingScreen.tsx
Normal file
19
src/components/PermissionMissingScreen.tsx
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import { Icon } from '~components/Icon';
|
||||||
|
|
||||||
|
import '~tabs/PermissionGrant.css';
|
||||||
|
|
||||||
|
export interface PermissionMissingProps {
|
||||||
|
onGrant?: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function PermissionMissingScreen(props: PermissionMissingProps) {
|
||||||
|
return (
|
||||||
|
<div className="disabled">
|
||||||
|
<Icon name="warningCircle" />
|
||||||
|
<p style={{ paddingBottom: 25, paddingTop: 10 }}>The extension is missing permissions it needs to function</p>
|
||||||
|
<button type="button" className="grant-permission-btn" onClick={props.onGrant}>
|
||||||
|
Grant Permission
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
@@ -1,5 +1,6 @@
|
|||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
|
|
||||||
|
import { usePermission } from '~hooks/usePermission';
|
||||||
import { useDomainStorage } from '~utils/storage';
|
import { useDomainStorage } from '~utils/storage';
|
||||||
|
|
||||||
export function useDomainWhitelist() {
|
export function useDomainWhitelist() {
|
||||||
@@ -25,11 +26,16 @@ export function useDomainWhitelist() {
|
|||||||
export function useToggleWhitelistDomain(domain: string) {
|
export function useToggleWhitelistDomain(domain: string) {
|
||||||
const { domainWhitelist, addDomain, removeDomain } = useDomainWhitelist();
|
const { domainWhitelist, addDomain, removeDomain } = useDomainWhitelist();
|
||||||
const isWhitelisted = domainWhitelist.includes(domain);
|
const isWhitelisted = domainWhitelist.includes(domain);
|
||||||
|
const { grantPermission } = usePermission();
|
||||||
|
|
||||||
const toggle = useCallback(() => {
|
const toggle = useCallback(() => {
|
||||||
if (isWhitelisted) removeDomain(domain);
|
if (!isWhitelisted) {
|
||||||
else addDomain(domain);
|
addDomain(domain);
|
||||||
}, [isWhitelisted, domain, addDomain, removeDomain]);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
removeDomain(domain);
|
||||||
|
}, [isWhitelisted, domain, addDomain, removeDomain, grantPermission]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
toggle,
|
toggle,
|
||||||
|
@@ -12,7 +12,7 @@ export function usePermission() {
|
|||||||
const { addDomain } = useDomainWhitelist();
|
const { addDomain } = useDomainWhitelist();
|
||||||
const [permission, setPermission] = useState(false);
|
const [permission, setPermission] = useState(false);
|
||||||
|
|
||||||
const grantPermission = useCallback(async (domain: string) => {
|
const grantPermission = useCallback(async (domain?: string) => {
|
||||||
const granted = await chrome.permissions.request({
|
const granted = await chrome.permissions.request({
|
||||||
origins: ['<all_urls>'],
|
origins: ['<all_urls>'],
|
||||||
});
|
});
|
||||||
|
@@ -1,19 +1,28 @@
|
|||||||
import { BottomLabel } from '~components/BottomLabel';
|
import { BottomLabel } from '~components/BottomLabel';
|
||||||
import { DisabledScreen } from '~components/DisabledScreen';
|
import { DisabledScreen } from '~components/DisabledScreen';
|
||||||
import { Frame } from '~components/Frame';
|
import { Frame } from '~components/Frame';
|
||||||
|
import { PermissionMissingScreen } from '~components/PermissionMissingScreen';
|
||||||
import { ToggleButton } from '~components/ToggleButton';
|
import { ToggleButton } from '~components/ToggleButton';
|
||||||
import { useDomain } from '~hooks/useDomain';
|
import { useDomain } from '~hooks/useDomain';
|
||||||
import { useToggleWhitelistDomain } from '~hooks/useDomainWhitelist';
|
import { useToggleWhitelistDomain } from '~hooks/useDomainWhitelist';
|
||||||
import './Popup.css';
|
import './Popup.css';
|
||||||
|
import { usePermission } from '~hooks/usePermission';
|
||||||
|
|
||||||
function IndexPopup() {
|
function IndexPopup() {
|
||||||
const domain = useDomain();
|
const domain = useDomain();
|
||||||
const { isWhitelisted, toggle } = useToggleWhitelistDomain(domain);
|
const { isWhitelisted, toggle } = useToggleWhitelistDomain(domain);
|
||||||
|
const { grantPermission, hasPermission } = usePermission();
|
||||||
|
|
||||||
|
let page = 'toggle';
|
||||||
|
if (!hasPermission) page = 'perm';
|
||||||
|
else if (!domain) page = 'disabled';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Frame>
|
<Frame>
|
||||||
<div className="popup">
|
<div className="popup">
|
||||||
{!domain ? <DisabledScreen /> : <ToggleButton active={isWhitelisted} onClick={toggle} domain={domain} />}
|
{page === 'toggle' ? <ToggleButton active={isWhitelisted} onClick={toggle} domain={domain} /> : null}
|
||||||
|
{page === 'disabled' ? <DisabledScreen /> : null}
|
||||||
|
{page === 'perm' ? <PermissionMissingScreen onGrant={grantPermission} /> : null}
|
||||||
<BottomLabel />
|
<BottomLabel />
|
||||||
</div>
|
</div>
|
||||||
</Frame>
|
</Frame>
|
||||||
|
Reference in New Issue
Block a user