Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 10 additions & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
module.exports = {
parser: '@typescript-eslint/parser',
extends: ['eslint:recommended', 'plugin:prettier/recommended'],
plugins: ['prettier'],
extends: [
'prettier',
'react-app',
'eslint:recommended',
'plugin:prettier/recommended',
'plugin:jsx-a11y/recommended',
],
plugins: ['prettier', '@typescript-eslint', 'jsx-a11y'],
env: {
browser: true,
node: true,
Expand All @@ -13,7 +19,6 @@ module.exports = {
module: true,
},
},
rules: {
'no-unused-vars': ['off'],
},

rules: { 'no-unused-vars': 'off' },
};
52 changes: 26 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,37 @@
},
"dependencies": {
"qrcode": "^1.4.4",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-qr-hooks": "^1.0.7"
},
"devDependencies": {
"@types/qrcode": "^1.3.4",
"@types/react": "^16.9.42",
"@types/react-dom": "^16.9.8",
"@typescript-eslint/parser": "^3.6.0",
"copy-webpack-plugin": "6.0.3",
"css-loader": "^3.6.0",
"cz-conventional-changelog": "3.2.0",
"eslint": "^7.4.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-prettier": "^3.1.4",
"@types/qrcode": "^1.3.5",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"@typescript-eslint/parser": "^4.10.0",
"copy-webpack-plugin": "7.0.0",
"css-loader": "^5.0.1",
"cz-conventional-changelog": "3.3.0",
"eslint": "^7.15.0",
"eslint-config-prettier": "^7.0.0",
"eslint-plugin-prettier": "^3.3.0",
"extensionizer": "^1.0.1",
"husky": "^4.2.5",
"lint-staged": "^10.2.11",
"husky": "^4.3.6",
"lint-staged": "^10.5.3",
"node-sass": "^4.14.1",
"prettier": "^2.0.5",
"sass-loader": "^9.0.2",
"style-loader": "^1.2.1",
"ts-loader": "^8.0.0",
"typescript": "^3.9.6",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.12"
"prettier": "^2.2.1",
"sass-loader": "^10.1.0",
"style-loader": "^2.0.0",
"ts-loader": "^8.0.12",
"typescript": "^4.1.3",
"webpack": "^5.10.3",
"webpack-cli": "^4.2.0"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"husky": {
"hooks": {
Expand All @@ -51,10 +56,5 @@
"npm run prettier",
"npm run lint"
]
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
}
1 change: 1 addition & 0 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ extension.contextMenus.onClicked.addListener((info: Info) => {

const openPopup = extension.browserAction.openPopup;

// this check is needed because Firefox and Chromium based browsers implement openPopup differently
if (openPopup.length === 0) {
openPopup(() => null);
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/popup/components/CodePreview/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import React from 'react';
import React, { memo } from 'react';
import { useQrEncode } from 'react-qr-hooks';

interface Props {
interface CodePreviewProps {
readonly decoded: string;
}

const CodePreview: React.FC<Props> = ({ decoded }) => {
const CodePreview = memo<CodePreviewProps>(({ decoded }) => {
const encoded = useQrEncode(decoded, {
width: 360,
});

return <img src={encoded} alt={decoded} />;
};
});

export default CodePreview;
9 changes: 5 additions & 4 deletions src/popup/components/Details/index.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import React from 'react';
import React, { memo } from 'react';

import './Details.scss';

interface Props {
interface DetailsProps {
readonly summary: string;
readonly children: React.ReactNode;
}

const Details: React.FC<Props> = ({ summary, children }) => (
const Details = memo<DetailsProps>(({ summary, children }) => (
<details>
<summary>{summary}</summary>

<p>{children}</p>
</details>
);
));

export default Details;
2 changes: 2 additions & 0 deletions src/popup/components/ErrorMessage/ErrorMessage.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.error-message {
text-align: center;
word-break: break-word;
padding: 0 10px;
}
8 changes: 4 additions & 4 deletions src/popup/components/ErrorMessage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React from 'react';
import React, { memo } from 'react';

import './ErrorMessage.scss';

interface Props {
interface ErrorMessageProps {
readonly message: string;
}

const ErrorMessage: React.FC<Props> = ({ message }) => (
const ErrorMessage = memo<ErrorMessageProps>(({ message }) => (
<p className="error-message">{message}</p>
);
));

export default ErrorMessage;
12 changes: 12 additions & 0 deletions src/popup/components/OutOfLimit/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React, { memo } from 'react';

interface OutOfLimitProps {
readonly decoded: string;
readonly limit: number;
}

const OutOfLimit = memo<OutOfLimitProps>(({ decoded, limit }) => (
<span className="out-of-limit">{decoded.slice(limit)}</span>
));

export default OutOfLimit;
12 changes: 6 additions & 6 deletions src/popup/components/Tabs/index.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import React from 'react';
import React, { memo } from 'react';

import { Tab } from '../../../shared/enums/Tab';

import './Tabs.scss';

interface Props {
interface TabsProps {
readonly items: Record<Tab, string>;
readonly active: Tab;
onChange(value: Tab): void;
onChange: (value: Tab) => void;
}

const Tabs: React.FC<Props> = ({ items, active, onChange }) => (
const Tabs = memo<TabsProps>(({ items, active, onChange }) => (
<nav className="tab-navigation">
{Object.entries(items).map(([key, value]) => (
<div className="tab-navigation__item" key={key}>
<input
name={name}
name={key}
value={key}
type="radio"
id={key}
Expand All @@ -27,6 +27,6 @@ const Tabs: React.FC<Props> = ({ items, active, onChange }) => (
</div>
))}
</nav>
);
));

export default Tabs;
2 changes: 1 addition & 1 deletion src/popup/constants/supportedProtocols.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const supportedProtocols = ['http', 'https'];
export const SUPPORTED_PROTOCOLS = ['http', 'https'];
16 changes: 9 additions & 7 deletions src/popup/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,23 @@ export const StateContext = React.createContext<
[PopupState, React.Dispatch<ActionTypes>]
>([initialState, () => null]);

export const StateProvider: React.FC = ({ children }) => {
interface StateProviderProps {
readonly children: React.ReactNode;
}

export const StateProvider = ({ children }: StateProviderProps) => {
const [state, dispatch] = useReducer(stateReducer, initialState);

useEffect(() => {
extension.storage.local.get(
[StoreKey.SelectedText, StoreKey.CurrentTab],
(res: PopupState) => {
const data = res;

if (!data[StoreKey.CurrentTab]) {
data[StoreKey.SelectedText] = '';
data[StoreKey.CurrentTab] = Tab.Url;
if (!res[StoreKey.CurrentTab]) {
res[StoreKey.SelectedText] = '';
res[StoreKey.CurrentTab] = Tab.Url;
}

dispatch({ type: INIT, payload: data });
dispatch({ type: INIT, payload: res });
}
);
}, []);
Expand Down
21 changes: 14 additions & 7 deletions src/popup/hooks/useTabs.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
import { useContext } from 'react';
import { useContext, useCallback } from 'react';

import { StateContext } from '../context';

import { SET_TAB } from '../store/actions';
import { SET_ACTIVE_TAB } from '../store/actions';

import { StoreKey } from '../../shared/enums/StoreKey';
import { Tab } from '../../shared/enums/Tab';

type SetActiveTabCallbackType = (id: Tab) => void;

export const useTabs = () => {
const [{ [StoreKey.CurrentTab]: tab }, dispatch] = useContext(StateContext);
const [{ [StoreKey.CurrentTab]: activeTab }, dispatch] = useContext(
StateContext
);

const setTab = (id: Tab) => {
dispatch({ type: SET_TAB, payload: id });
};
const setActiveTab = useCallback<SetActiveTabCallbackType>(
(id) => {
dispatch({ type: SET_ACTIVE_TAB, payload: id });
},
[dispatch]
);

return { tab, setTab };
return { activeTab, setActiveTab };
};
19 changes: 13 additions & 6 deletions src/popup/hooks/useText.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
import { useContext } from 'react';
import { useContext, useCallback } from 'react';

import { StateContext } from '../context';

import { CLEAR_TEXT, SET_TEXT } from '../store/actions';
import { SET_TEXT, CLEAR_TEXT } from '../store/actions';

import { StoreKey } from '../../shared/enums/StoreKey';

type SetTextCallbackType = (value: string) => void;

export const useText = () => {
const [{ [StoreKey.SelectedText]: text }, dispatch] = useContext(
StateContext
);

const setText = (value: string) => {
dispatch({ type: SET_TEXT, payload: value });
};
const setText = useCallback<SetTextCallbackType>(
(value) => {
dispatch({ type: SET_TEXT, payload: value });
},
[dispatch]
);

const clearText = () => dispatch({ type: CLEAR_TEXT });
const clearText = useCallback(() => dispatch({ type: CLEAR_TEXT }), [
dispatch,
]);

return { text, setText, clearText };
};
6 changes: 3 additions & 3 deletions src/popup/hooks/useUrl.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useState } from 'react';
import extension from 'extensionizer';

import { supportedProtocols } from '../constants/supportedProtocols';
import { SUPPORTED_PROTOCOLS } from '../constants/supportedProtocols';

interface TabQueryResult {
readonly url: string;
Expand All @@ -16,9 +16,9 @@ export const useUrl = () => {
extension.tabs.query(
{ currentWindow: true, active: true },
(res: TabQueryResult[]) => {
const currentPageProtocol = res[0].url.split(':')[0];
const currentPageProtocol = res[0].url.split('://')[0];

if (supportedProtocols.includes(currentPageProtocol)) {
if (SUPPORTED_PROTOCOLS.includes(currentPageProtocol)) {
setUrl(res[0].url);

setUnsupportedProtocol('');
Expand Down
14 changes: 7 additions & 7 deletions src/popup/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { INIT, SET_TAB, CLEAR_TEXT, SET_TEXT } from '../store/actions';
import { INIT, SET_ACTIVE_TAB, CLEAR_TEXT, SET_TEXT } from '../store/actions';

import { StoreKey } from '../../shared/enums/StoreKey';
import { Tab } from '../../shared/enums/Tab';
Expand All @@ -13,16 +13,16 @@ export interface InitAction {
readonly payload: PopupState;
}

export interface SetTabAction {
readonly type: typeof SET_TAB;
export interface SetActiveTabAction {
readonly type: typeof SET_ACTIVE_TAB;
readonly payload: Tab;
}

export interface ClearTextAction {
readonly type: typeof CLEAR_TEXT;
}

export interface SetTextAction {
readonly type: typeof SET_TEXT;
readonly payload: string;
}

export interface ClearTextAction {
readonly type: typeof CLEAR_TEXT;
}
Loading