Skip to content

Commit

Permalink
Merge pull request #445 from refly-ai/fix/extension-lint-errors
Browse files Browse the repository at this point in the history
fix: lint errors in extension app
  • Loading branch information
mrcfps authored Feb 3, 2025
2 parents 22b5abc + 2fa0323 commit 2c6ea7c
Show file tree
Hide file tree
Showing 61 changed files with 115 additions and 1,075 deletions.
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lint-staged
2 changes: 1 addition & 1 deletion apps/api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ RUN apk add --no-cache curl

WORKDIR /app

RUN corepack enable
RUN npm install -g [email protected]

COPY . .
RUN pnpm install
Expand Down
5 changes: 4 additions & 1 deletion apps/extension/src/@types/i18next.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import resources from './resources';

declare module 'i18next' {
interface CustomTypeOptions {
resources: typeof resources;
defaultNS: keyof typeof resources;
resources: {
translation: typeof resources.translation;
};
// if you see an error like: "Argument of type 'DefaultTFuncReturn' is not assignable to parameter of type xyz"
// set returnNull to false (and also in the i18next init options)
// returnNull: false;
Expand Down
101 changes: 0 additions & 101 deletions apps/extension/src/components/chat-header/index.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion apps/extension/src/components/content-clipper/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useCallback, useState, useEffect } from 'react';
import { Button, Divider, Input, message, Tooltip } from 'antd';
import { IconDelete, IconSave, IconPaste } from '@arco-design/web-react/icon';
import { IconDelete, IconPaste } from '@arco-design/web-react/icon';
import { HiOutlineDocumentDownload } from 'react-icons/hi';
import { useTranslation } from 'react-i18next';
import { useSaveSelectedContent } from '@/hooks/use-save-selected-content';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import classNames from 'classnames';
import { useEffect, useRef } from 'react';
import ReactDOM from 'react-dom';
import { Message } from '@arco-design/web-react';
import type {
Mark,
Expand Down
1 change: 0 additions & 1 deletion apps/extension/src/components/output-locale-list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const OutputLocaleList = (props: { children: any }) => {
const uiLocale = i18n?.languages?.[0] as LOCALE;

const userStore = useUserStore();
const { outputLocale } = userStore?.localSettings || {};

const changeLang = async (lng: OutputLocale) => {
const { localSettings } = useUserStore.getState();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { Tabs } from 'wxt/browser';

export const onActivated = (activeInfo: Tabs.OnActivatedActiveInfoType) => {
// 在此处处理标签切换
console.log(
'Tab with ID ' + activeInfo.tabId + ' was activated in window ' + activeInfo.windowId,
);
console.log(`Tab with ID ${activeInfo.tabId} was activated in window ${activeInfo.windowId}`);

sendHeartBeatMessage(activeInfo);
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { Tabs } from 'wxt/browser';

export const onDetached = (tabId: number, detachInfo: Tabs.OnDetachedDetachInfoType) => {
// 在此处处理标签切换
console.log('Tab with ID ' + tabId + ' was detached in window ' + detachInfo.oldWindowId);
console.log(`Tab with ID ${tabId} was detached in window ${detachInfo.oldWindowId}`);
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { setToken } from '../index';

export const onExternalMessage = async (
msg: any,
sender: Runtime.MessageSender,
sendResponse: (response?: any) => void,
_sender: Runtime.MessageSender,
_sendResponse: (response?: any) => void,
) => {
console.log('onMessageExternal msg', msg);
if (msg?.name === 'external-refly-login-notify') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,7 @@ import * as requestModule from '@refly/openapi-schema';
import { BackgroundMessage } from '@refly/common-types';
import { createClient } from '@hey-api/client-fetch';
import { getExtensionServerOrigin } from '@refly/utils/url';
import { getCookie } from '@/utils/cookie';
import { getToken } from '../../index';
import { AuthenticationExpiredError, OperationTooFrequent, UnknownError } from '@refly/errors';
import { responseInterceptorWithTokenRefresh } from '@refly-packages/ai-workspace-common/utils/auth';
import {
cacheClonedRequest,
getAndClearCachedRequest,
} from '@refly-packages/ai-workspace-common/requests/proxiedRequest';

const client = createClient({
baseUrl: `${getExtensionServerOrigin()}/v1`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { sendMessage } from '@refly-packages/ai-workspace-common/utils/extension
import { BackgroundMessage } from '@refly/common-types';
import { browser } from 'wxt/browser';

export const handleGetOpenedTabs = async (msg: BackgroundMessage) => {
export const handleGetOpenedTabs = async (_msg: BackgroundMessage) => {
try {
// 获取当前浏览器标签页
const tabs = await browser.tabs.query({ currentWindow: true });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { handleInjectContentSelectorCss } from '@/entrypoints/background/events/

export const onMessage = async (
msg: BackgroundMessage,
sender: Runtime.MessageSender,
sendResponse: (response?: any) => void,
_sender: Runtime.MessageSender,
_sendResponse: (response?: any) => void,
) => {
// 前置做保存,后续使用
await saveLastActiveTab();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BackgroundMessage } from '@refly/common-types';
import { browser } from 'wxt/browser';

export const handleInjectContentSelectorCss = async (msg: BackgroundMessage) => {
export const handleInjectContentSelectorCss = async (_msg: BackgroundMessage) => {
try {
const tabs = await browser.tabs.query({ active: true, currentWindow: true });
const { id } = tabs[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,26 @@ export const handleRegisterSidePanel = async (msg: BackgroundMessage) => {
} else {
if (typeof isSetSidePanel === 'boolean' && isSetSidePanel) {
return;
} else {
isSetSidePanel = true;
}
isSetSidePanel = true;
// @ts-ignore
browser?.sidePanel
.setPanelBehavior({ openPanelOnActionClick: true })
.then(() => {
console.log('register sidePanel success');
})
.catch((error: any) => console.error(`sidePanel open error: `, error));
.catch((error: any) => console.error('sidePanel open error: ', error));
}
};

export const handleUnregisterSidePanel = async (msg: BackgroundMessage) => {
export const handleUnregisterSidePanel = async (_msg: BackgroundMessage) => {
// @ts-ignore
browser?.sidePanel
.setPanelBehavior({ openPanelOnActionClick: false })
.then(() => {
console.log('unregister sidePanel success');
})
.catch((error: any) => console.error(`sidePanel unregister error: `, error));
.catch((error: any) => console.error('sidePanel unregister error: ', error));
};

export const handleRegisterEvent = async (msg: BackgroundMessage) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ export const handleToggleCopilotSidePanel = (
});
}
} catch (error) {
console.error(`handleToggleCopilot error: `, error);
console.error('handleToggleCopilot error: ', error);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import './App.scss';
import classNames from 'classnames';
import { IconHighlight, IconSave, IconClose } from '@arco-design/web-react/icon';
import { useSaveCurrentWeblinkAsResource } from '@/hooks/use-save-resource';
import { useToggleCopilot } from '@/modules/toggle-copilot/hooks/use-toggle-copilot';
import { useSaveResourceNotify } from '@refly-packages/ai-workspace-common/hooks/use-save-resouce-notify';
import { useListenToCopilotType } from '@/modules/toggle-copilot/hooks/use-listen-to-copilot-type';
import { useTranslation } from 'react-i18next';
Expand All @@ -33,7 +32,7 @@ const getPopupContainer = () => {
};

export const App = () => {
const [selectedText, setSelectedText] = useState<string>('');
const [selectedText, _setSelectedText] = useState<string>('');
const { saveResource } = useSaveCurrentWeblinkAsResource();
const { handleSaveResourceAndNotify } = useSaveResourceNotify();
// const { handleToggleCopilot } = useToggleCopilot();
Expand All @@ -58,7 +57,7 @@ export const App = () => {
console.log('i18n', i18n?.languages);

// 加载快捷键
const [shortcut] = useState<string>(reflyEnv.getOsType() === 'OSX' ? '⌘ J' : 'Ctrl J');
const [_shortcut] = useState<string>(reflyEnv.getOsType() === 'OSX' ? '⌘ J' : 'Ctrl J');
const [isDragging, setIsDragging] = useState(false);
const isDraggingRef = useRef(false);
const [position, setPosition] = useState({ y: 0 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { setRuntime } from '@refly/utils/env';
import { ConfigProvider } from 'antd';
import { MemoryRouter, Route } from '@refly-packages/ai-workspace-common/utils/router';
import { AppRouter } from '@/routes';
import { Login } from '@/pages/login/index.tsx';

export default defineContentScript({
matches: ['<all_urls>'],
Expand All @@ -24,7 +23,7 @@ export default defineContentScript({
setRuntime('extension-csui');

console.log('ctx', ctx);
let removeInjectCSS: () => void;
let _removeInjectCSS: () => void;
// 3. Define your UI`
const ui = await createShadowRootUi(ctx, {
name: 'refly-float-sphere',
Expand Down
6 changes: 1 addition & 5 deletions apps/extension/src/entrypoints/main-csui.content/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import { defineContentScript } from 'wxt/sandbox';
import ReactDOM from 'react-dom/client';
import { createShadowRootUi } from 'wxt/client';
import App from './App';
import { setRuntime } from '@refly/utils/env';
import { MemoryRouter } from '@refly-packages/ai-workspace-common/utils/router';

export default defineContentScript({
matches: ['<all_urls>'],
// 2. Set cssInjectionMode
cssInjectionMode: 'ui',

async main(ctx) {
async main() {
setRuntime('extension-csui');
// console.log('ctx', ctx);
// 3. Define your UI`
Expand Down
1 change: 0 additions & 1 deletion apps/extension/src/entrypoints/popup/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { ContentClipper } from '@/components/content-clipper';
import { setRuntime } from '@refly/utils/env';
import { Unsupported } from '@/entrypoints/popup/unsupported';
import { LoginHeader } from '@/entrypoints/popup/login-header';
import { LoadLoading } from '@/entrypoints/popup/load-loading';

import { SuspenseLoading } from '@refly-packages/ai-workspace-common/components/common/loading/index';
/**
Expand Down
2 changes: 1 addition & 1 deletion apps/extension/src/entrypoints/popup/not-logged.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Button, ConfigProvider, Spin, Tooltip } from 'antd';
import { Button } from 'antd';
import { useTranslation } from 'react-i18next';

import { getClientOrigin } from '@refly/utils/url';
Expand Down
1 change: 0 additions & 1 deletion apps/extension/src/entrypoints/utils-csui.content/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useEffect, useRef } from 'react';
import { checkBrowserArc } from '@/utils/browser';

import './App.scss';

Expand Down
Loading

0 comments on commit 2c6ea7c

Please sign in to comment.