diff --git a/packages/extension/chrome-option/components/Header-Bar.tsx b/packages/extension/chrome-option/components/Header-Bar.tsx new file mode 100644 index 0000000..07a0099 --- /dev/null +++ b/packages/extension/chrome-option/components/Header-Bar.tsx @@ -0,0 +1,63 @@ +import { GithubOutlined, UserOutlined } from '@ant-design/icons' +import { Avatar } from 'antd' +import { useState } from 'react' +import { useMount } from 'ahooks' +import { CarbonSun } from './icon-sun' +import { CarbonMoon } from './icon-moon' +import type { IRepoWithPRs } from './Repo-List' +interface HeaderBarProps { + userInfo: { + avatar_url: string + html_url: string + } + repoInfo: IRepoWithPRs +} +export const HeaderBar = (props: HeaderBarProps = { + userInfo: { + avatar_url: '', + html_url: '', + }, + repoInfo: { + url: '', + name: '', + uname: '', + pullRequests: [], + }, +}) => { + const [dark, setDark] = useState(false) + const toggleTheme = (value: boolean) => { + setDark(value) + localStorage.setItem('dark', value.toString()) + } + useMount(() => { + const dark = localStorage.getItem('dark') + if (!dark || dark === 'false') + setDark(false) + else + setDark(true) + }) + return ( +
+
+ + } /> + +

{props.repoInfo.uname}

+
+
+ + + + { + dark ? toggleTheme(false)} /> + : toggleTheme(true)} /> + } +
+
+ ) +} diff --git a/packages/extension/chrome-option/components/Repo-List.tsx b/packages/extension/chrome-option/components/Repo-List.tsx index c366579..c4b1a4b 100644 --- a/packages/extension/chrome-option/components/Repo-List.tsx +++ b/packages/extension/chrome-option/components/Repo-List.tsx @@ -7,14 +7,16 @@ interface IRepoListProps { opType: string token: string userName: string + onSelect: (data: IRepoWithPRs) => void } interface IRepo { name: string + uname: string url: string } -interface IRepoWithPRs extends IRepo { +export interface IRepoWithPRs extends IRepo { pullRequests: Record[] } @@ -22,10 +24,11 @@ export const RepoList = (props: IRepoListProps) => { const [repoList, setRepoList] = useState([]) const repoListCache = useRef([]) const [loading, setLoading] = useState(false) + const { token, opType, userName, onSelect } = props useEffect(() => { setLoading(true) - if (props.opType === 'rebase') { - getIssuesPR(props.token, props.userName) + if (opType === 'rebase') { + getIssuesPR(token, userName) .then((res) => { // 使用 map 避免重复遍历 const repos = new Map() @@ -46,14 +49,15 @@ export const RepoList = (props: IRepoListProps) => { const resRepo = [...repos.values()] setRepoList(resRepo) repoListCache.current = resRepo + onSelect(resRepo[0]) }) .finally(() => { setLoading(false) }) } // merge 模式 我们只获取仓库信息 - if (props.opType === 'merge') { - getAllRepo(props.token).then((res) => { + if (opType === 'merge') { + getAllRepo(token).then((res) => { const hasIssuesRepo = res.filter(val => val.open_issues_count > 0 && !val.fork) const repos = new Map() hasIssuesRepo.forEach((val) => { @@ -66,19 +70,18 @@ export const RepoList = (props: IRepoListProps) => { const resRepo = [...repos.values()] setRepoList(resRepo) repoListCache.current = resRepo + onSelect(resRepo[0]) }).finally(() => { setLoading(false) }) } - }, [props.opType, props.token, props.userName]) + }, [token, opType, userName, onSelect]) - const [activeIndex, setActiveIndex] = useState(-1) + const [activeIndex, setActiveIndex] = useState(0) const handleClick = useCallback((index: number) => { setActiveIndex(index) - const repo = repoList[index] - console.log(repo.url) - console.log(repo.name) - }, [repoList]) + onSelect(repoList[index]) + }, [repoList, onSelect]) const repoListEl = useMemo(() => { return repoList.map((repo, index) => ( @@ -112,9 +115,10 @@ export const RepoList = (props: IRepoListProps) => { }, { wait: 300 }, ) + const { Search } = Input return (
- + diff --git a/packages/extension/chrome-option/components/icon-moon.tsx b/packages/extension/chrome-option/components/icon-moon.tsx new file mode 100644 index 0000000..753c8aa --- /dev/null +++ b/packages/extension/chrome-option/components/icon-moon.tsx @@ -0,0 +1,6 @@ +import type { SVGProps } from 'react' +export const CarbonMoon = (props: SVGProps) => { + return ( + + ) +} diff --git a/packages/extension/chrome-option/components/icon-sun.tsx b/packages/extension/chrome-option/components/icon-sun.tsx new file mode 100644 index 0000000..eb906dc --- /dev/null +++ b/packages/extension/chrome-option/components/icon-sun.tsx @@ -0,0 +1,6 @@ +import type { SVGProps } from 'react' +export const CarbonSun = (props: SVGProps) => { + return ( + + ) +} diff --git a/packages/extension/chrome-popup/view/PopupPage.tsx b/packages/extension/chrome-popup/view/PopupPage.tsx index b285da2..f6703e9 100644 --- a/packages/extension/chrome-popup/view/PopupPage.tsx +++ b/packages/extension/chrome-popup/view/PopupPage.tsx @@ -75,7 +75,13 @@ export const PopupPage = () => {
- pr-checker + + pr-checker +

pr-checker

diff --git a/packages/fetch-git/api/index.ts b/packages/fetch-git/api/index.ts index ab3398c..4a5fd91 100644 --- a/packages/fetch-git/api/index.ts +++ b/packages/fetch-git/api/index.ts @@ -33,4 +33,3 @@ export async function getAllRepo(token: string) { }) return res } -