Skip to content

Commit

Permalink
Highlight suggest feature
Browse files Browse the repository at this point in the history
  • Loading branch information
DukeManh committed Mar 23, 2023
1 parent ae8a77b commit bcaa92f
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/lib/pages/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
Link,
InputGroup,
InputRightElement,
useColorMode,
} from '@chakra-ui/react';
import type { ParsedEvent, ReconnectInterval } from 'eventsource-parser';
import { createParser } from 'eventsource-parser';
Expand All @@ -36,6 +37,7 @@ import {

const Home = () => {
const [openAIKey, saveOpenAIKey] = useLocalStorage('openAIKey');
const { colorMode } = useColorMode();
const { register, handleSubmit, watch, setValue } = useForm<Inputs>({
defaultValues: {
openAIKey: openAIKey || '',
Expand All @@ -51,12 +53,15 @@ const Home = () => {
topic: '',
subTopics: [] as string[],
});
const [loadingSubTopics, setLoadingSubTopics] = useState(false);

const getSubTopics = async (topic: string) => {
setLoadingSubTopics(true);
setSubTopics('');
setSubTopicsSuggestion({ topic: '', subTopics: [] });
const stream = await getTopicSuggestion(topic);
if (!stream) {
setLoadingSubTopics(false);
return;
}

Expand All @@ -69,6 +74,7 @@ const Home = () => {
topic,
subTopics: prev.topic.split(', '),
}));
setLoadingSubTopics(false);
return;
}
try {
Expand Down Expand Up @@ -165,10 +171,17 @@ const Home = () => {
/>
<InputRightElement width="5.4rem">
<Button
isDisabled={!watch('topic')}
isDisabled={!watch('topic') || loadingSubTopics}
h="1.75rem"
size="sm"
onClick={() => getSubTopics(watch('topic'))}
transition="background-color 0.25s ease-in-out"
sx={{
...(watch('topic') && {
bg: colorMode === 'dark' ? 'green.200' : 'green.400',
color: colorMode === 'dark' ? 'black' : 'white',
}),
}}
>
Suggest
</Button>
Expand All @@ -182,6 +195,7 @@ const Home = () => {
>
{subTopicsSuggestion.subTopics.length ? (
<Text fontSize="sm" color="gray.500">
Select: &nbsp;
{subTopicsSuggestion.subTopics.map((subTopic, index) => (
<Text
as="span"
Expand All @@ -208,6 +222,7 @@ const Home = () => {
</Text>
) : (
<Text fontSize="sm" color="gray.500">
Select: &nbsp;
{subTopics}
</Text>
)}
Expand Down

1 comment on commit bcaa92f

@vercel
Copy link

@vercel vercel bot commented on bcaa92f Mar 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

quizard – ./

quizard-git-main-dukemanh.vercel.app
quizard-kappa.vercel.app
quizard-dukemanh.vercel.app

Please sign in to comment.