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: github token for popup page #100

Merged
merged 1 commit into from
Apr 19, 2021
Merged
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
3 changes: 3 additions & 0 deletions src/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
"global_btn_goBack": {
"message": "Go back"
},
"global_btn_setToken": {
"message": "set token"
},
"global_developer": {
"message": "Develpoer"
},
Expand Down
3 changes: 3 additions & 0 deletions src/_locales/zh_CN/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
"global_btn_goBack": {
"message": "返回"
},
"global_btn_setToken": {
"message": "设置token"
},
"global_developer": {
"message": "开发者"
},
Expand Down
10 changes: 9 additions & 1 deletion src/api/github.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { Octokit } from "@octokit/core";
import { loadMetaData } from '../utils/metadata';

export const getConfigFromGithub = async (owner: string, repo: string) => {
const octokit = new Octokit();
const metaData=await loadMetaData();
let octokit;
if(metaData.token!==""){
octokit = new Octokit({ auth:metaData.token });
}
else{
octokit = new Octokit();
}
try {
const response = await octokit.request('GET /repos/{owner}/{repo}/contents/.github/hypertrons.json', { owner, repo });
const res = response.data as any;
Expand Down
3 changes: 1 addition & 2 deletions src/components/OptionsPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ const OptionsPage: React.FC = () => {
if(temp.token!==""){
setToken(temp.token);
}
console.log("init meta")
}
initMetaData();
}, []);
Expand Down Expand Up @@ -301,7 +300,7 @@ const OptionsPage: React.FC = () => {
width:120
}}
>
设置token
{getMessageI18n("global_btn_setToken")}
</DefaultButton>
</Stack>
</PivotItem>
Expand Down
64 changes: 62 additions & 2 deletions src/components/PopupPage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
import React, { useEffect, useState } from 'react';
import {
Stack
DefaultButton,
Image, ImageFit, PivotItem,
Stack, Text,
} from 'office-ui-fabric-react';
import { initializeIcons } from '@uifabric/icons';
import './index.css';
import Settings,{ loadSettings } from '../../utils/settings';
import MetaData, { loadMetaData } from '../../utils/metadata';
import { getMessageI18n } from '../../utils/utils';

initializeIcons();

const PopupPage: React.FC = () => {

const [settings,setSettings]= useState(new Settings());
const [metaData, setMetaData] = useState(new MetaData());
const [inited, setInited] = useState(false);

useEffect(() => {
const initSettings=async ()=> {
const temp=await loadSettings();
setSettings(temp);
setInited(true);
}
initSettings();
},[settings]);

useEffect(() => {
const initMetaData = async () => {
const temp=await loadMetaData();
setMetaData(temp);
setInited(true);
}
initMetaData();
}, []);

if(!inited){
return (<div/>);
Expand All @@ -30,6 +42,54 @@ const PopupPage: React.FC = () => {
return(
<Stack horizontalAlign="center">
<h1>Hypertrons</h1>
<Stack
horizontalAlign="space-around"
verticalAlign='center'
style={{ margin: "5px", padding: "3px" }}
tokens={{
childrenGap: 10
}}
>
{
metaData.token!==""&&
<Stack
horizontal
verticalAlign="center"
style={{
margin: "5px", padding: "3px", width: "300px"
}}
tokens={{
childrenGap: 5
}}
>
<Image
width={75}
height={75}
src={metaData.avatar}
imageFit={ImageFit.centerCover}
/>
<Text
variant="large"
style={{marginLeft:25,maxWidth:200,wordWrap:"break-word"}}
>
{metaData.name}
</Text>
</Stack>
}
{
metaData.token === "" &&
<DefaultButton
onClick={()=>{
chrome.runtime.openOptionsPage();
}}
style={{
width:120
}}
>
{getMessageI18n("global_btn_setToken")}
</DefaultButton>
}
</Stack>
</Stack>
)
}
Expand Down