feat: parse githubUsername from oauth data

This commit is contained in:
Lin Onetwo 2020-07-04 01:29:11 +08:00
parent e98b542066
commit 0fcabf83d4
2 changed files with 15 additions and 3 deletions

View file

@ -121,6 +121,8 @@ function AddWorkspace({ wikiCreationMessage, onUpdateForm, onSave, onSetWikiCrea
homeUrl: `http://localhost:${wikiPort}/`,
picturePath: getIconPath(),
};
const githubUsername = getGithubUsername();
return (
<ClientContext.Provider value={graphqlClient}>
<Container>
@ -152,13 +154,19 @@ function AddWorkspace({ wikiCreationMessage, onUpdateForm, onSave, onSetWikiCrea
scope="repo"
onSuccess={response => {
const accessToken = response?.userInfo?.thirdPartyIdentity?.accessToken;
const authData = response?.userInfo?.oauth;
if (accessToken) {
setGraphqlClientHeader(accessToken);
}
if (authData) {
setGithubUsername(JSON.parse(authData).login);
}
}}
onFailure={response => console.log(response)}
/>
{Object.keys(graphqlClient.headers).length > 0 && <SearchRepo />}
{Object.keys(graphqlClient.headers).length > 0 && githubUsername && (
<SearchRepo githubUsername={githubUsername} />
)}
</SyncContainer>
<CreateContainer elevation={2} square>

View file

@ -28,13 +28,17 @@ const SEARCH_REPO_QUERY = `
}
}
`;
export default function SearchRepo() {
interface Props {
githubUsername: string;
}
export default function SearchRepo({ githubUsername }: Props) {
const [githubRepoSearchString, githubRepoSearchStringSetter] = useState('wiki');
const loadCount = 10;
const { loading, error, data } = useQuery(SEARCH_REPO_QUERY, {
variables: {
first: loadCount,
queryString: `user:linonetwo ${githubRepoSearchString}`,
queryString: `user:${githubUsername} ${githubRepoSearchString}`,
},
});
const repositoryCount = data?.search?.repositoryCount;