From 0fcabf83d49586dcd2a78a3626ed6ea7012093ee Mon Sep 17 00:00:00 2001 From: Lin Onetwo Date: Sat, 4 Jul 2020 01:29:11 +0800 Subject: [PATCH] feat: parse githubUsername from oauth data --- src/components/dialog-add-workspace/index.js | 10 +++++++++- src/components/dialog-add-workspace/search-repo.js | 8 ++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/components/dialog-add-workspace/index.js b/src/components/dialog-add-workspace/index.js index 2c82ce29..1a9832c3 100644 --- a/src/components/dialog-add-workspace/index.js +++ b/src/components/dialog-add-workspace/index.js @@ -121,6 +121,8 @@ function AddWorkspace({ wikiCreationMessage, onUpdateForm, onSave, onSetWikiCrea homeUrl: `http://localhost:${wikiPort}/`, picturePath: getIconPath(), }; + + const githubUsername = getGithubUsername(); return ( @@ -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 && } + {Object.keys(graphqlClient.headers).length > 0 && githubUsername && ( + + )} diff --git a/src/components/dialog-add-workspace/search-repo.js b/src/components/dialog-add-workspace/search-repo.js index 730c3a3f..cbe62772 100644 --- a/src/components/dialog-add-workspace/search-repo.js +++ b/src/components/dialog-add-workspace/search-repo.js @@ -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;