diff --git a/samples/apps/github-qna-webapp-react/package.json b/samples/apps/github-qna-webapp-react/package.json index 8425c6ff389a..f531b8506be3 100644 --- a/samples/apps/github-qna-webapp-react/package.json +++ b/samples/apps/github-qna-webapp-react/package.json @@ -11,7 +11,6 @@ "@types/node": "^16.7.13", "@types/react": "^18.0.0", "@types/react-dom": "^18.0.0", - "openai": "^3.2.1", "react": "^18.2.0", "react-dom": "^18.2.0", "react-scripts": "5.0.1", diff --git a/samples/apps/github-qna-webapp-react/src/assets/icons8-github-512.png b/samples/apps/github-qna-webapp-react/src/assets/icons8-github-512.png new file mode 100644 index 000000000000..49d0d273eb6a Binary files /dev/null and b/samples/apps/github-qna-webapp-react/src/assets/icons8-github-512.png differ diff --git a/samples/apps/github-qna-webapp-react/src/components/GitHubRepoSelection.tsx b/samples/apps/github-qna-webapp-react/src/components/GitHubRepoSelection.tsx index c6d066c6616c..b1558087bf81 100644 --- a/samples/apps/github-qna-webapp-react/src/components/GitHubRepoSelection.tsx +++ b/samples/apps/github-qna-webapp-react/src/components/GitHubRepoSelection.tsx @@ -1,8 +1,8 @@ // Copyright (c) Microsoft. All rights reserved. import { Body1, Button, Input, Label, Spinner, Title3 } from '@fluentui/react-components'; -import { ArrowDownload16Regular, CheckmarkCircle20Filled } from '@fluentui/react-icons'; -import React, { FC, useState } from 'react'; +import { ArrowDownload16Regular, CheckmarkCircle20Filled, ErrorCircle20Regular } from '@fluentui/react-icons'; +import { FC, useEffect, useState } from 'react'; import { useSemanticKernel } from '../hooks/useSemanticKernel'; import { IKeyConfig } from '../model/KeyConfig'; @@ -15,23 +15,26 @@ interface IData { onLoadProject: (project: string, branch: string) => void; } +const enum DownloadState { + Setup = 0, + Loading = 1, + Loaded = 2, + Error = 3, +} + const GitHubProjectSelection: FC = ({ uri, keyConfig, prevProject, prevBranch, onLoadProject, onBack }) => { const [project, setProject] = useState(prevProject); const [branch, setBranch] = useState(prevBranch); - const [isLoading, setIsLoading] = useState(false); - const [isLoaded, setIsLoaded] = useState(project !== '' && branch !== ''); - const [isLoadError, setIsLoadError] = useState(false); + const [downloadState, setDownloadState] = useState(DownloadState.Setup); const sk = useSemanticKernel(uri); const isSameProjectAndBranch = () => { return project === prevProject && branch === prevBranch && project !== '' && branch !== ''; - } + }; const download = async () => { try { - setIsLoading(true); - setIsLoaded(false); - setIsLoadError(false); + setDownloadState(DownloadState.Loading); var result = await sk.invokeAsync( keyConfig, { @@ -44,22 +47,24 @@ const GitHubProjectSelection: FC = ({ uri, keyConfig, prevProject, prevBr 'GitHubSkill', 'SummarizeRepository', ); - setIsLoaded(true); + setDownloadState(DownloadState.Loaded); console.log(result); } catch (e) { - setIsLoadError(true); + setDownloadState(DownloadState.Error); alert('Something went wrong.\n\nDetails:\n' + e); - } finally { - setIsLoading(false); } }; - React.useEffect(() => { - setIsLoaded(isSameProjectAndBranch()) + useEffect(() => { + if (isSameProjectAndBranch()) { + setDownloadState(DownloadState.Loaded); + } }, [project]); - React.useEffect(() => { - setIsLoaded(isSameProjectAndBranch()) + useEffect(() => { + if (isSameProjectAndBranch()) { + setDownloadState(DownloadState.Loaded); + } }, [branch]); return ( @@ -98,46 +103,44 @@ const GitHubProjectSelection: FC = ({ uri, keyConfig, prevProject, prevBr placeholder="main" />